@@ -31,7 +31,7 @@ pub struct Guard<'a> {
31
31
}
32
32
33
33
struct Inner {
34
- queue : Vec < BlockedTask > ,
34
+ queue : Vec < ( BlockedTask , uint ) > ,
35
35
held : bool ,
36
36
closed : bool ,
37
37
}
@@ -47,16 +47,17 @@ impl Access {
47
47
}
48
48
}
49
49
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 > {
51
52
// This unsafety is actually OK because the homing missile argument
52
53
// guarantees that we're on the same event loop as all the other objects
53
54
// 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 ( ) } ;
55
56
56
57
if inner. held {
57
58
let t: Box < Task > = Local :: take ( ) ;
58
59
t. deschedule ( 1 , |task| {
59
- inner. queue . push ( task) ;
60
+ inner. queue . push ( ( task, token ) ) ;
60
61
Ok ( ( ) )
61
62
} ) ;
62
63
assert ! ( inner. held) ;
@@ -75,6 +76,17 @@ impl Access {
75
76
// necessary synchronization to be running on this thread.
76
77
unsafe { ( * self . inner . get ( ) ) . closed = true ; }
77
78
}
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
+ }
78
90
}
79
91
80
92
impl Clone for Access {
@@ -111,9 +123,9 @@ impl<'a> Drop for Guard<'a> {
111
123
// scheduled on this scheduler. Because we might be woken up on some
112
124
// other scheduler, we drop our homing missile before we reawaken
113
125
// the task.
114
- Some ( task) => {
126
+ Some ( ( task, _ ) ) => {
115
127
drop ( self . missile . take ( ) ) ;
116
- let _ = task. wake ( ) . map ( |t| t . reawaken ( ) ) ;
128
+ task. reawaken ( ) ;
117
129
}
118
130
None => { inner. held = false ; }
119
131
}
0 commit comments