Skip to content

Commit fdeb2c4

Browse files
authored
refactor io_uring impls (#360)
2 parents 5a39680 + 0db9ae9 commit fdeb2c4

File tree

25 files changed

+214
-368
lines changed

25 files changed

+214
-368
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ jobs:
8282
aarch64-apple-darwin,
8383

8484
x86_64-pc-windows-gnu,
85-
# i686-pc-windows-gnu,
85+
i686-pc-windows-gnu,
8686
x86_64-pc-windows-msvc,
87-
# i686-pc-windows-msvc,
87+
i686-pc-windows-msvc,
8888
]
8989
channel: [ 1.81.0, nightly-2024-08-02 ]
9090
include:
@@ -114,9 +114,9 @@ jobs:
114114

115115
- target: x86_64-pc-windows-gnu
116116
os: windows-latest
117-
# - target: i686-pc-windows-gnu
118-
# os: windows-latest
117+
- target: i686-pc-windows-gnu
118+
os: windows-latest
119119
- target: x86_64-pc-windows-msvc
120120
os: windows-latest
121-
# - target: i686-pc-windows-msvc
122-
# os: windows-latest
121+
- target: i686-pc-windows-msvc
122+
os: windows-latest

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
- name: Install cargo-llvm-cov
3232
uses: taiki-e/install-action@cargo-llvm-cov
3333
- name: Generate code coverage
34-
run: sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && sudo -u runner /home/runner/.cargo/bin/cargo llvm-cov --release --all --lcov --output-path lcov.info"
34+
run: bash -c "ulimit -Sl 512 && ulimit -Hl 512 && /home/runner/.cargo/bin/cargo llvm-cov --release --all --lcov --output-path lcov.info"
3535
- name: Generate code coverage with all features
36-
run: sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && sudo -u runner /home/runner/.cargo/bin/cargo llvm-cov --all-features --release --all --lcov --output-path lcov-all-features.info"
36+
run: bash -c "ulimit -Sl 512 && ulimit -Hl 512 && /home/runner/.cargo/bin/cargo llvm-cov --all-features --release --all --lcov --output-path lcov-all-features.info"
3737
- name: Upload coverage to Codecov
3838
run: |
3939
bash <(curl -s https://codecov.io/bash) -f lcov.info -t ${{ env.CODECOV_TOKEN }}

core/src/coroutine/korosensei.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use crate::catch;
22
use crate::common::constants::CoroutineState;
33
use crate::coroutine::listener::Listener;
44
use crate::coroutine::local::CoroutineLocal;
5-
use crate::coroutine::stack_pool::{MemoryPool, PooledStack};
65
use crate::coroutine::suspender::Suspender;
76
use crate::coroutine::StackInfo;
8-
use corosensei::stack::Stack;
7+
use corosensei::stack::{DefaultStack, Stack};
98
use corosensei::trap::TrapHandlerRegs;
109
use corosensei::CoroutineResult;
1110
use std::cell::{Cell, RefCell, UnsafeCell};
@@ -27,7 +26,7 @@ cfg_if::cfg_if! {
2726
#[repr(C)]
2827
pub struct Coroutine<'c, Param, Yield, Return> {
2928
pub(crate) name: String,
30-
inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, PooledStack>,
29+
inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, DefaultStack>,
3130
pub(crate) state: Cell<CoroutineState<Yield, Return>>,
3231
stack_infos: UnsafeCell<VecDeque<StackInfo>>,
3332
pub(crate) listeners: VecDeque<&'c dyn Listener<Yield, Return>>,
@@ -326,17 +325,13 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
326325
stack_size: usize,
327326
callback: F,
328327
) -> std::io::Result<R> {
329-
let stack_pool = MemoryPool::get_instance();
330328
if let Some(co) = Self::current() {
331329
let remaining_stack = unsafe { co.remaining_stack() };
332330
if remaining_stack >= red_zone {
333331
return Ok(callback());
334332
}
335-
return stack_pool.allocate(stack_size).map(|stack| {
336-
co.stack_infos_mut().push_back(StackInfo {
337-
stack_top: stack.base().get(),
338-
stack_bottom: stack.limit().get(),
339-
});
333+
return DefaultStack::new(stack_size).map(|stack| {
334+
co.stack_infos_mut().push_back(StackInfo::from(&stack));
340335
let r = corosensei::on_stack(stack, callback);
341336
_ = co.stack_infos_mut().pop_back();
342337
r
@@ -355,12 +350,9 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
355350
return Ok(callback());
356351
}
357352
}
358-
stack_pool.allocate(stack_size).map(|stack| {
353+
DefaultStack::new(stack_size).map(|stack| {
359354
STACK_INFOS.with(|s| {
360-
s.borrow_mut().push_back(StackInfo {
361-
stack_top: stack.base().get(),
362-
stack_bottom: stack.limit().get(),
363-
});
355+
s.borrow_mut().push_back(StackInfo::from(&stack));
364356
});
365357
let r = corosensei::on_stack(stack, callback);
366358
_ = STACK_INFOS.with(|s| s.borrow_mut().pop_back());
@@ -398,7 +390,7 @@ where
398390
F: FnOnce(&Suspender<Param, Yield>, Param) -> Return + 'static,
399391
{
400392
let stack_size = stack_size.max(crate::common::page_size());
401-
let stack = MemoryPool::get_instance().allocate(stack_size)?;
393+
let stack = DefaultStack::new(stack_size)?;
402394
let stack_infos = UnsafeCell::new(VecDeque::from([StackInfo {
403395
stack_top: stack.base().get(),
404396
stack_bottom: stack.limit().get(),
@@ -469,3 +461,12 @@ where
469461
}
470462
}
471463
}
464+
465+
impl<S: Stack> From<&S> for StackInfo {
466+
fn from(stack: &S) -> Self {
467+
Self {
468+
stack_top: stack.base().get(),
469+
stack_bottom: stack.limit().get(),
470+
}
471+
}
472+
}

core/src/coroutine/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ pub mod local;
1717
/// Coroutine listener abstraction and impl.
1818
pub mod listener;
1919

20-
/// Reuse stacks.
21-
pub mod stack_pool;
22-
2320
#[cfg(feature = "korosensei")]
2421
pub use korosensei::Coroutine;
2522
#[cfg(feature = "korosensei")]

0 commit comments

Comments
 (0)