@@ -31,7 +31,7 @@ pub struct Guard<'a> {
3131}
3232
3333struct Inner {
34- queue : Vec < BlockedTask > ,
34+ queue : Vec < ( BlockedTask , uint ) > ,
3535 held : bool ,
3636 closed : bool ,
3737}
@@ -47,16 +47,17 @@ impl Access {
4747 }
4848 }
4949
50- pub fn grant < ' a > ( & ' a mut self , missile : HomingMissile ) -> Guard < ' a > {
50+ pub fn grant < ' a > ( & ' a mut self , token : uint ,
51+ missile : HomingMissile ) -> Guard < ' a > {
5152 // This unsafety is actually OK because the homing missile argument
5253 // guarantees that we're on the same event loop as all the other objects
5354 // attempting to get access granted.
54- let inner: & mut Inner = unsafe { cast :: transmute ( self . inner . get ( ) ) } ;
55+ let inner: & mut Inner = unsafe { & mut * self . inner . get ( ) } ;
5556
5657 if inner. held {
5758 let t: Box < Task > = Local :: take ( ) ;
5859 t. deschedule ( 1 , |task| {
59- inner. queue . push ( task) ;
60+ inner. queue . push ( ( task, token ) ) ;
6061 Ok ( ( ) )
6162 } ) ;
6263 assert ! ( inner. held) ;
@@ -75,6 +76,17 @@ impl Access {
7576 // necessary synchronization to be running on this thread.
7677 unsafe { ( * self . inner . get ( ) ) . closed = true ; }
7778 }
79+
80+ // Dequeue a blocked task with a specified token. This is unsafe because it
81+ // is only safe to invoke while on the home event loop, and there is no
82+ // guarantee that this i being invoked on the home event loop.
83+ pub unsafe fn dequeue ( & mut self , token : uint ) -> Option < BlockedTask > {
84+ let inner: & mut Inner = & mut * self . inner . get ( ) ;
85+ match inner. queue . iter ( ) . position ( |& ( _, t) | t == token) {
86+ Some ( i) => Some ( inner. queue . remove ( i) . unwrap ( ) . val0 ( ) ) ,
87+ None => None ,
88+ }
89+ }
7890}
7991
8092impl Clone for Access {
@@ -111,9 +123,9 @@ impl<'a> Drop for Guard<'a> {
111123 // scheduled on this scheduler. Because we might be woken up on some
112124 // other scheduler, we drop our homing missile before we reawaken
113125 // the task.
114- Some ( task) => {
126+ Some ( ( task, _ ) ) => {
115127 drop ( self . missile . take ( ) ) ;
116- let _ = task. wake ( ) . map ( |t| t . reawaken ( ) ) ;
128+ task. reawaken ( ) ;
117129 }
118130 None => { inner. held = false ; }
119131 }
0 commit comments