Skip to content

Commit d0074c3

Browse files
committed
pass almost all preemptive CI on unix
1 parent 7871ce7 commit d0074c3

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
PROJECT_DIR: ${{ github.workspace }}
5656
run: sh .github/workflows/ci.sh
5757
- name: Run preemptive tests
58-
if: ${{ contains(fromJSON('["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-apple-darwin"]'), matrix.target) }}
58+
if: ${{ contains(matrix.os, 'ubuntu') && !contains(matrix.target, 'loongarch64') || contains(matrix.os, 'macos') }}
5959
env:
6060
CHANNEL: ${{ matrix.channel }}
6161
CROSS: ${{ !startsWith(matrix.target, 'x86_64') && contains(matrix.target, 'linux') && '1' || '0' }}

core/docs/en/monitor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ The `preemptive` feature currently supports the following targets:
1414
|---------------|-----------------------------------|--------------------------|---------|
1515
| `x86_64` ||||
1616
| `x86` ||||
17-
| `AArch64` | ⚠️ |||
18-
| `ARM` | ⚠️ |||
19-
| `RISC-V` | ⚠️ |||
17+
| `AArch64` | |||
18+
| `ARM` | |||
19+
| `RISC-V` | |||
2020
| `LoongArch64` | ⚠️ |||
2121

2222
✅ Tested and stable; ⚠️ Tested but unstable; ❌ Not supported.

core/src/common/macros.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ macro_rules! impl_current_for {
8888
$struct_name:ident$(<$($generic:tt $( : $trait_tt1: tt $( + $trait_tt2: tt)*)?),+>)?
8989
) => {
9090
thread_local! {
91-
static $name: std::cell::RefCell<std::collections::VecDeque<*const std::ffi::c_void>> =
92-
const { std::cell::RefCell::new(std::collections::VecDeque::new()) };
91+
static $name: crossbeam_utils::atomic::AtomicCell<std::collections::VecDeque<*const std::ffi::c_void>> =
92+
const { crossbeam_utils::atomic::AtomicCell::new(std::collections::VecDeque::new()) };
9393
}
9494

9595
impl$(<$($generic $( : $trait_tt1 $( + $trait_tt2)*)?),+>)? $struct_name$(<$($generic),+>)? {
9696
/// Init the current.
9797
pub(crate) fn init_current(current: &Self) {
98-
$name.with(|s| {
99-
s.try_borrow_mut()
100-
.unwrap_or_else(|e| {
98+
$name.with(|s| unsafe {
99+
s.as_ptr()
100+
.as_mut()
101+
.unwrap_or_else(|| {
101102
panic!(
102-
"thread:{} init {} current failed with {}",
103+
"thread:{} init {} current failed",
103104
std::thread::current().name().unwrap_or("unknown"),
104-
stringify!($name),
105-
e
105+
stringify!($name)
106106
)
107107
})
108108
.push_front(core::ptr::from_ref(current).cast::<std::ffi::c_void>());
@@ -113,31 +113,31 @@ macro_rules! impl_current_for {
113113
#[must_use]
114114
#[allow(unreachable_pub)]
115115
pub fn current<'current>() -> Option<&'current Self> {
116-
$name.with(|s| {
117-
s.try_borrow()
118-
.unwrap_or_else(|e| {
116+
$name.with(|s| unsafe {
117+
s.as_ptr()
118+
.as_ref()
119+
.unwrap_or_else(|| {
119120
panic!(
120-
"thread:{} get {} current failed with {}",
121+
"thread:{} get {} current failed",
121122
std::thread::current().name().unwrap_or("unknown"),
122-
stringify!($name),
123-
e
123+
stringify!($name)
124124
)
125125
})
126126
.front()
127-
.map(|ptr| unsafe { &*(*ptr).cast::<Self>() })
127+
.map(|ptr| &*(*ptr).cast::<Self>())
128128
})
129129
}
130130

131131
/// Clean the current.
132132
pub(crate) fn clean_current() {
133-
$name.with(|s| {
134-
_ = s.try_borrow_mut()
135-
.unwrap_or_else(|e| {
133+
$name.with(|s| unsafe {
134+
_ = s.as_ptr()
135+
.as_mut()
136+
.unwrap_or_else(|| {
136137
panic!(
137-
"thread:{} clean {} current failed with {}",
138+
"thread:{} clean {} current failed",
138139
std::thread::current().name().unwrap_or("unknown"),
139-
stringify!($name),
140-
e
140+
stringify!($name)
141141
)
142142
})
143143
.pop_front();

core/src/coroutine/suspender.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::common::get_timeout_time;
22
use crate::impl_current_for;
3-
use std::cell::RefCell;
4-
use std::collections::VecDeque;
53
use std::time::Duration;
64

75
thread_local! {
86
#[allow(clippy::missing_const_for_thread_local)]
9-
static TIMESTAMP: RefCell<VecDeque<u64>> = const { RefCell::new(VecDeque::new()) };
7+
static TIMESTAMP: crossbeam_utils::atomic::AtomicCell<std::collections::VecDeque<u64>> =
8+
const { crossbeam_utils::atomic::AtomicCell::new(std::collections::VecDeque::new()) };
109
}
1110

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

1817
/// Delay the execution of the coroutine with an arg until `timestamp`.
1918
pub fn until_with(&self, arg: Yield, timestamp: u64) -> Param {
20-
TIMESTAMP.with(|s| {
21-
s.try_borrow_mut()
22-
.unwrap_or_else(|e| {
19+
TIMESTAMP.with(|s| unsafe {
20+
s.as_ptr()
21+
.as_mut()
22+
.unwrap_or_else(|| {
2323
panic!(
24-
"thread:{} init TIMESTAMP current failed with {}",
25-
std::thread::current().name().unwrap_or("unknown"),
26-
e
24+
"thread:{} init TIMESTAMP current failed",
25+
std::thread::current().name().unwrap_or("unknown")
2726
)
2827
})
2928
.push_front(timestamp);
@@ -33,13 +32,13 @@ impl<Param, Yield> Suspender<'_, Param, Yield> {
3332

3433
pub(crate) fn timestamp() -> u64 {
3534
TIMESTAMP
36-
.with(|s| {
37-
s.try_borrow_mut()
38-
.unwrap_or_else(|e| {
35+
.with(|s| unsafe {
36+
s.as_ptr()
37+
.as_mut()
38+
.unwrap_or_else(|| {
3939
panic!(
40-
"thread:{} get TIMESTAMP current failed with {}",
41-
std::thread::current().name().unwrap_or("unknown"),
42-
e
40+
"thread:{} get TIMESTAMP current failed",
41+
std::thread::current().name().unwrap_or("unknown")
4342
)
4443
})
4544
.pop_front()

0 commit comments

Comments
 (0)