Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ jobs:
aarch64-apple-darwin,

x86_64-pc-windows-gnu,
# i686-pc-windows-gnu,
i686-pc-windows-gnu,
x86_64-pc-windows-msvc,
# i686-pc-windows-msvc,
i686-pc-windows-msvc,
]
channel: [ 1.81.0, nightly-2024-08-02 ]
include:
Expand Down Expand Up @@ -114,9 +114,9 @@ jobs:

- target: x86_64-pc-windows-gnu
os: windows-latest
# - target: i686-pc-windows-gnu
# os: windows-latest
- target: i686-pc-windows-gnu
os: windows-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
# - target: i686-pc-windows-msvc
# os: windows-latest
- target: i686-pc-windows-msvc
os: windows-latest
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
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"
run: bash -c "ulimit -Sl 512 && ulimit -Hl 512 && /home/runner/.cargo/bin/cargo llvm-cov --release --all --lcov --output-path lcov.info"
- name: Generate code coverage with all features
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"
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"
- name: Upload coverage to Codecov
run: |
bash <(curl -s https://codecov.io/bash) -f lcov.info -t ${{ env.CODECOV_TOKEN }}
Expand Down
31 changes: 16 additions & 15 deletions core/src/coroutine/korosensei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use crate::catch;
use crate::common::constants::CoroutineState;
use crate::coroutine::listener::Listener;
use crate::coroutine::local::CoroutineLocal;
use crate::coroutine::stack_pool::{MemoryPool, PooledStack};
use crate::coroutine::suspender::Suspender;
use crate::coroutine::StackInfo;
use corosensei::stack::Stack;
use corosensei::stack::{DefaultStack, Stack};
use corosensei::trap::TrapHandlerRegs;
use corosensei::CoroutineResult;
use std::cell::{Cell, RefCell, UnsafeCell};
Expand All @@ -27,7 +26,7 @@ cfg_if::cfg_if! {
#[repr(C)]
pub struct Coroutine<'c, Param, Yield, Return> {
pub(crate) name: String,
inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, PooledStack>,
inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, DefaultStack>,
pub(crate) state: Cell<CoroutineState<Yield, Return>>,
stack_infos: UnsafeCell<VecDeque<StackInfo>>,
pub(crate) listeners: VecDeque<&'c dyn Listener<Yield, Return>>,
Expand Down Expand Up @@ -326,17 +325,13 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
stack_size: usize,
callback: F,
) -> std::io::Result<R> {
let stack_pool = MemoryPool::get_instance();
if let Some(co) = Self::current() {
let remaining_stack = unsafe { co.remaining_stack() };
if remaining_stack >= red_zone {
return Ok(callback());
}
return stack_pool.allocate(stack_size).map(|stack| {
co.stack_infos_mut().push_back(StackInfo {
stack_top: stack.base().get(),
stack_bottom: stack.limit().get(),
});
return DefaultStack::new(stack_size).map(|stack| {
co.stack_infos_mut().push_back(StackInfo::from(&stack));
let r = corosensei::on_stack(stack, callback);
_ = co.stack_infos_mut().pop_back();
r
Expand All @@ -355,12 +350,9 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
return Ok(callback());
}
}
stack_pool.allocate(stack_size).map(|stack| {
DefaultStack::new(stack_size).map(|stack| {
STACK_INFOS.with(|s| {
s.borrow_mut().push_back(StackInfo {
stack_top: stack.base().get(),
stack_bottom: stack.limit().get(),
});
s.borrow_mut().push_back(StackInfo::from(&stack));
});
let r = corosensei::on_stack(stack, callback);
_ = STACK_INFOS.with(|s| s.borrow_mut().pop_back());
Expand Down Expand Up @@ -398,7 +390,7 @@ where
F: FnOnce(&Suspender<Param, Yield>, Param) -> Return + 'static,
{
let stack_size = stack_size.max(crate::common::page_size());
let stack = MemoryPool::get_instance().allocate(stack_size)?;
let stack = DefaultStack::new(stack_size)?;
let stack_infos = UnsafeCell::new(VecDeque::from([StackInfo {
stack_top: stack.base().get(),
stack_bottom: stack.limit().get(),
Expand Down Expand Up @@ -469,3 +461,12 @@ where
}
}
}

impl<S: Stack> From<&S> for StackInfo {
fn from(stack: &S) -> Self {
Self {
stack_top: stack.base().get(),
stack_bottom: stack.limit().get(),
}
}
}
3 changes: 0 additions & 3 deletions core/src/coroutine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pub mod local;
/// Coroutine listener abstraction and impl.
pub mod listener;

/// Reuse stacks.
pub mod stack_pool;

#[cfg(feature = "korosensei")]
pub use korosensei::Coroutine;
#[cfg(feature = "korosensei")]
Expand Down
Loading
Loading