@@ -55,26 +55,26 @@ impl Ord for SuspendItem<'_> {
5555
5656#[ repr( C ) ]
5757#[ derive( Debug ) ]
58- struct SyscallSuspendItem < ' s > {
58+ struct SyscallSuspendItem {
5959 timestamp : u64 ,
60- co_name : & ' s str ,
60+ co_id : usize ,
6161}
6262
63- impl PartialEq < Self > for SyscallSuspendItem < ' _ > {
63+ impl PartialEq < Self > for SyscallSuspendItem {
6464 fn eq ( & self , other : & Self ) -> bool {
6565 self . timestamp . eq ( & other. timestamp )
6666 }
6767}
6868
69- impl Eq for SyscallSuspendItem < ' _ > { }
69+ impl Eq for SyscallSuspendItem { }
7070
71- impl PartialOrd < Self > for SyscallSuspendItem < ' _ > {
71+ impl PartialOrd < Self > for SyscallSuspendItem {
7272 fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
7373 Some ( self . cmp ( other) )
7474 }
7575}
7676
77- impl Ord for SyscallSuspendItem < ' _ > {
77+ impl Ord for SyscallSuspendItem {
7878 fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
7979 // BinaryHeap defaults to a large top heap, but we need a small top heap
8080 other. timestamp . cmp ( & self . timestamp )
@@ -98,8 +98,8 @@ pub struct Scheduler<'s> {
9898 #[ doc = include_str ! ( "../docs/en/ordered-work-steal.md" ) ]
9999 ready : OrderedLocalQueue < ' s , SchedulableCoroutine < ' s > > ,
100100 suspend : BinaryHeap < SuspendItem < ' s > > ,
101- syscall : DashMap < & ' s str , SchedulableCoroutine < ' s > > ,
102- syscall_suspend : BinaryHeap < SyscallSuspendItem < ' s > > ,
101+ syscall : DashMap < usize , SchedulableCoroutine < ' s > > ,
102+ syscall_suspend : BinaryHeap < SyscallSuspendItem > ,
103103}
104104
105105impl Default for Scheduler < ' _ > {
@@ -220,8 +220,8 @@ impl<'s> Scheduler<'s> {
220220 ///
221221 /// # Errors
222222 /// if change to ready fails.
223- pub fn try_resume ( & self , co_name : & ' s str ) {
224- if let Some ( ( _, co) ) = self . syscall . remove ( & co_name ) {
223+ pub fn try_resume ( & self , co_id : usize ) {
224+ if let Some ( ( _, co) ) = self . syscall . remove ( & co_id ) {
225225 match co. state ( ) {
226226 CoroutineState :: Syscall ( val, syscall, SyscallState :: Suspend ( _) ) => {
227227 co. syscall ( val, syscall, SyscallState :: Callback )
@@ -313,10 +313,11 @@ impl<'s> Scheduler<'s> {
313313 CoroutineState :: Syscall ( ( ) , _, state) => {
314314 //挂起协程到系统调用表
315315 //如果已包含,说明当前系统调用还有上层父系统调用,因此直接忽略插入结果
316- _ = self . syscall . insert ( co_name, coroutine) ;
316+ let co_id = coroutine. id ( ) ;
317+ _ = self . syscall . insert ( co_id, coroutine) ;
317318 if let SyscallState :: Suspend ( timestamp) = state {
318319 self . syscall_suspend
319- . push ( SyscallSuspendItem { timestamp, co_name } ) ;
320+ . push ( SyscallSuspendItem { timestamp, co_id } ) ;
320321 }
321322 }
322323 CoroutineState :: Suspend ( ( ) , timestamp) => {
@@ -373,7 +374,7 @@ impl<'s> Scheduler<'s> {
373374 break ;
374375 }
375376 if let Some ( item) = self . syscall_suspend . pop ( ) {
376- if let Some ( ( _, co) ) = self . syscall . remove ( item. co_name ) {
377+ if let Some ( ( _, co) ) = self . syscall . remove ( & item. co_id ) {
377378 match co. state ( ) {
378379 CoroutineState :: Syscall ( val, syscall, SyscallState :: Suspend ( _) ) => {
379380 co. syscall ( val, syscall, SyscallState :: Timeout ) ?;
@@ -420,7 +421,7 @@ mod tests {
420421 for timestamp in ( 0 ..10 ) . rev ( ) {
421422 heap. push ( SyscallSuspendItem {
422423 timestamp,
423- co_name : "test" ,
424+ co_id : 1 ,
424425 } ) ;
425426 }
426427 for timestamp in 0 ..10 {
0 commit comments