Skip to content

Commit 77f6e1e

Browse files
committed
fix linux x86 CI
1 parent b228729 commit 77f6e1e

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

core/src/co_pool/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ impl Drop for CoroutinePool<'_> {
7070
self.get_running_size(),
7171
"There are still tasks in progress !"
7272
);
73-
assert_eq!(
74-
0,
75-
self.task_queue.len(),
73+
assert!(
74+
self.task_queue.is_empty(),
7675
"There are still tasks to be carried out !"
7776
);
7877
}

core/src/coroutine/korosensei.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::coroutine::StackInfo;
88
use corosensei::stack::Stack;
99
use corosensei::trap::TrapHandlerRegs;
1010
use corosensei::CoroutineResult;
11-
use std::cell::{Cell, RefCell};
11+
use std::cell::{Cell, RefCell, UnsafeCell};
1212
use std::collections::VecDeque;
1313
use std::ffi::c_longlong;
1414
use std::fmt::Debug;
@@ -29,7 +29,7 @@ pub struct Coroutine<'c, Param, Yield, Return> {
2929
pub(crate) name: String,
3030
inner: corosensei::Coroutine<Param, Yield, Result<Return, &'static str>, PooledStack>,
3131
pub(crate) state: Cell<CoroutineState<Yield, Return>>,
32-
pub(crate) stack_infos: RefCell<VecDeque<StackInfo>>,
32+
stack_infos: UnsafeCell<VecDeque<StackInfo>>,
3333
pub(crate) listeners: VecDeque<&'c dyn Listener<Yield, Return>>,
3434
pub(crate) local: CoroutineLocal<'c>,
3535
pub(crate) priority: Option<c_longlong>,
@@ -291,6 +291,25 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
291291
self.listeners.push_back(listener);
292292
}
293293

294+
pub(crate) fn stack_infos_ref(&self) -> &VecDeque<StackInfo> {
295+
unsafe {
296+
self.stack_infos
297+
.get()
298+
.as_ref()
299+
.expect("StackInfo not init !")
300+
}
301+
}
302+
303+
#[allow(clippy::mut_from_ref)]
304+
pub(crate) fn stack_infos_mut(&self) -> &mut VecDeque<StackInfo> {
305+
unsafe {
306+
self.stack_infos
307+
.get()
308+
.as_mut()
309+
.expect("StackInfo not init !")
310+
}
311+
}
312+
294313
/// Grows the call stack if necessary.
295314
///
296315
/// This function is intended to be called at manually instrumented points in a program where
@@ -314,12 +333,12 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
314333
return Ok(callback());
315334
}
316335
return stack_pool.allocate(stack_size).map(|stack| {
317-
co.stack_infos.borrow_mut().push_back(StackInfo {
336+
co.stack_infos_mut().push_back(StackInfo {
318337
stack_top: stack.base().get(),
319338
stack_bottom: stack.limit().get(),
320339
});
321340
let r = corosensei::on_stack(stack, callback);
322-
_ = co.stack_infos.borrow_mut().pop_back();
341+
_ = co.stack_infos_mut().pop_back();
323342
r
324343
});
325344
}
@@ -380,7 +399,7 @@ where
380399
{
381400
let stack_size = stack_size.max(crate::common::page_size());
382401
let stack = MemoryPool::get_instance().allocate(stack_size)?;
383-
let stack_infos = RefCell::new(VecDeque::from([StackInfo {
402+
let stack_infos = UnsafeCell::new(VecDeque::from([StackInfo {
384403
stack_top: stack.base().get(),
385404
stack_bottom: stack.limit().get(),
386405
}]));

core/src/coroutine/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
107107
///
108108
/// This can only be done safely in coroutine.
109109
pub unsafe fn remaining_stack(&self) -> usize {
110-
let current_ptr = psm::stack_pointer() as usize;
111-
current_ptr - self.stack_infos.borrow().back().unwrap().stack_bottom
110+
let current_sp = psm::stack_pointer() as usize;
111+
current_sp - self.stack_infos_ref().back().unwrap().stack_bottom
112112
}
113113

114114
/// Queries the current stack info of this coroutine.
115115
///
116116
/// The first used stack index is 0 and increases with usage.
117117
pub fn stack_infos(&self) -> VecDeque<StackInfo> {
118-
self.stack_infos.borrow().clone()
118+
self.stack_infos_ref().clone()
119119
}
120120

121121
/// Checks whether the stack pointer at the point where a trap occurred is
@@ -126,7 +126,7 @@ impl<'c, Param, Yield, Return> Coroutine<'c, Param, Yield, Return> {
126126
/// The result of this function is only meaningful if the coroutine has not
127127
/// been dropped yet.
128128
pub fn stack_ptr_in_bounds(&self, stack_ptr: u64) -> bool {
129-
for info in self.stack_infos.borrow().iter() {
129+
for info in self.stack_infos_ref() {
130130
if info.stack_bottom as u64 <= stack_ptr && stack_ptr < info.stack_top as u64 {
131131
return true;
132132
}
@@ -202,7 +202,7 @@ where
202202
f.debug_struct("Coroutine")
203203
.field("name", &self.name())
204204
.field("state", &self.state())
205-
.field("stack_infos", &self.stack_infos)
205+
.field("stack_infos", &self.stack_infos())
206206
.field("local", &self.local)
207207
.field("priority", &self.priority)
208208
.finish()

core/src/coroutine/stack_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl MemoryPool {
186186
}
187187

188188
pub(crate) fn allocate(&self, stack_size: usize) -> std::io::Result<PooledStack> {
189-
let heap = unsafe { self.pool.get().as_mut().expect("StackPool is not unique") };
189+
let heap = unsafe { self.pool.get().as_mut().expect("MemoryPool is not unique") };
190190
// find min stack
191191
let mut not_use = Vec::new();
192192
while let Some(stack) = heap.peek() {
@@ -265,7 +265,7 @@ impl MemoryPool {
265265
/// Clean the expired stack.
266266
#[allow(dead_code)]
267267
pub(crate) fn clean(&self) {
268-
let heap = unsafe { self.pool.get().as_mut().expect("StackPool is not unique") };
268+
let heap = unsafe { self.pool.get().as_mut().expect("MemoryPool is not unique") };
269269
let mut maybe_free = Vec::new();
270270
while let Some(stack) = heap.peek() {
271271
if Rc::strong_count(&stack.stack) > 1 {

0 commit comments

Comments
 (0)