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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
PROJECT_DIR: ${{ github.workspace }}
run: sh .github/workflows/ci.sh
- name: Run preemptive tests
if: ${{ contains(fromJSON('["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-apple-darwin"]'), matrix.target) }}
if: ${{ contains(matrix.os, 'ubuntu') && !contains(matrix.target, 'loongarch64') || contains(matrix.os, 'macos') }}
env:
CHANNEL: ${{ matrix.channel }}
CROSS: ${{ !startsWith(matrix.target, 'x86_64') && contains(matrix.target, 'linux') && '1' || '0' }}
Expand Down
6 changes: 3 additions & 3 deletions core/docs/en/monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ The `preemptive` feature currently supports the following targets:
|---------------|-----------------------------------|--------------------------|---------|
| `x86_64` | ✅ | ✅ | ❌ |
| `x86` | ✅ | ❌ | ❌ |
| `AArch64` | ⚠️ | ✅ | ❌ |
| `ARM` | ⚠️ | ❌ | ❌ |
| `RISC-V` | ⚠️ | ❌ | ❌ |
| `AArch64` | | ✅ | ❌ |
| `ARM` | | ❌ | ❌ |
| `RISC-V` | | ❌ | ❌ |
| `LoongArch64` | ⚠️ | ❌ | ❌ |

✅ Tested and stable; ⚠️ Tested but unstable; ❌ Not supported.
Expand Down
42 changes: 21 additions & 21 deletions core/src/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ macro_rules! impl_current_for {
$struct_name:ident$(<$($generic:tt $( : $trait_tt1: tt $( + $trait_tt2: tt)*)?),+>)?
) => {
thread_local! {
static $name: std::cell::RefCell<std::collections::VecDeque<*const std::ffi::c_void>> =
const { std::cell::RefCell::new(std::collections::VecDeque::new()) };
static $name: crossbeam_utils::atomic::AtomicCell<std::collections::VecDeque<*const std::ffi::c_void>> =
const { crossbeam_utils::atomic::AtomicCell::new(std::collections::VecDeque::new()) };
}

impl$(<$($generic $( : $trait_tt1 $( + $trait_tt2)*)?),+>)? $struct_name$(<$($generic),+>)? {
/// Init the current.
pub(crate) fn init_current(current: &Self) {
$name.with(|s| {
s.try_borrow_mut()
.unwrap_or_else(|e| {
$name.with(|s| unsafe {
s.as_ptr()
.as_mut()
.unwrap_or_else(|| {
panic!(
"thread:{} init {} current failed with {}",
"thread:{} init {} current failed",
std::thread::current().name().unwrap_or("unknown"),
stringify!($name),
e
stringify!($name)
)
})
.push_front(core::ptr::from_ref(current).cast::<std::ffi::c_void>());
Expand All @@ -113,31 +113,31 @@ macro_rules! impl_current_for {
#[must_use]
#[allow(unreachable_pub)]
pub fn current<'current>() -> Option<&'current Self> {
$name.with(|s| {
s.try_borrow()
.unwrap_or_else(|e| {
$name.with(|s| unsafe {
s.as_ptr()
.as_ref()
.unwrap_or_else(|| {
panic!(
"thread:{} get {} current failed with {}",
"thread:{} get {} current failed",
std::thread::current().name().unwrap_or("unknown"),
stringify!($name),
e
stringify!($name)
)
})
.front()
.map(|ptr| unsafe { &*(*ptr).cast::<Self>() })
.map(|ptr| &*(*ptr).cast::<Self>())
})
}

/// Clean the current.
pub(crate) fn clean_current() {
$name.with(|s| {
_ = s.try_borrow_mut()
.unwrap_or_else(|e| {
$name.with(|s| unsafe {
_ = s.as_ptr()
.as_mut()
.unwrap_or_else(|| {
panic!(
"thread:{} clean {} current failed with {}",
"thread:{} clean {} current failed",
std::thread::current().name().unwrap_or("unknown"),
stringify!($name),
e
stringify!($name)
)
})
.pop_front();
Expand Down
29 changes: 14 additions & 15 deletions core/src/coroutine/suspender.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::common::get_timeout_time;
use crate::impl_current_for;
use std::cell::RefCell;
use std::collections::VecDeque;
use std::time::Duration;

thread_local! {
#[allow(clippy::missing_const_for_thread_local)]
static TIMESTAMP: RefCell<VecDeque<u64>> = const { RefCell::new(VecDeque::new()) };
static TIMESTAMP: crossbeam_utils::atomic::AtomicCell<std::collections::VecDeque<u64>> =
const { crossbeam_utils::atomic::AtomicCell::new(std::collections::VecDeque::new()) };
}

impl<Param, Yield> Suspender<'_, Param, Yield> {
Expand All @@ -17,13 +16,13 @@ impl<Param, Yield> Suspender<'_, Param, Yield> {

/// Delay the execution of the coroutine with an arg until `timestamp`.
pub fn until_with(&self, arg: Yield, timestamp: u64) -> Param {
TIMESTAMP.with(|s| {
s.try_borrow_mut()
.unwrap_or_else(|e| {
TIMESTAMP.with(|s| unsafe {
s.as_ptr()
.as_mut()
.unwrap_or_else(|| {
panic!(
"thread:{} init TIMESTAMP current failed with {}",
std::thread::current().name().unwrap_or("unknown"),
e
"thread:{} init TIMESTAMP current failed",
std::thread::current().name().unwrap_or("unknown")
)
})
.push_front(timestamp);
Expand All @@ -33,13 +32,13 @@ impl<Param, Yield> Suspender<'_, Param, Yield> {

pub(crate) fn timestamp() -> u64 {
TIMESTAMP
.with(|s| {
s.try_borrow_mut()
.unwrap_or_else(|e| {
.with(|s| unsafe {
s.as_ptr()
.as_mut()
.unwrap_or_else(|| {
panic!(
"thread:{} get TIMESTAMP current failed with {}",
std::thread::current().name().unwrap_or("unknown"),
e
"thread:{} get TIMESTAMP current failed",
std::thread::current().name().unwrap_or("unknown")
)
})
.pop_front()
Expand Down
Loading