@@ -8,7 +8,7 @@ use crate::coroutine::StackInfo;
88use corosensei:: stack:: Stack ;
99use corosensei:: trap:: TrapHandlerRegs ;
1010use corosensei:: CoroutineResult ;
11- use std:: cell:: { Cell , RefCell } ;
11+ use std:: cell:: { Cell , RefCell , UnsafeCell } ;
1212use std:: collections:: VecDeque ;
1313use std:: ffi:: c_longlong;
1414use 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 } ] ) ) ;
0 commit comments