@@ -15,7 +15,7 @@ use cell::Cell;
15
15
use option:: { Option , Some , None } ;
16
16
use prelude:: * ;
17
17
use rt:: task:: Task ;
18
- use unstable:: atomics:: { AtomicUint , SeqCst } ;
18
+ use unstable:: atomics:: { AtomicUint , Acquire , SeqCst } ;
19
19
use unstable:: sync:: { UnsafeAtomicRcBox , LittleLock } ;
20
20
use util;
21
21
@@ -137,6 +137,16 @@ impl KillHandle {
137
137
}
138
138
}
139
139
140
+ #[ inline]
141
+ pub fn killed ( & self ) -> bool {
142
+ // Called every context switch, so shouldn't report true if the task
143
+ // is unkillable with a kill signal pending.
144
+ let inner = unsafe { & * self . get ( ) } ;
145
+ let flag = unsafe { & * inner. killed . get ( ) } ;
146
+ // FIXME(#6598): can use relaxed ordering (i think)
147
+ flag. load ( Acquire ) == KILL_KILLED
148
+ }
149
+
140
150
pub fn notify_immediate_failure ( & mut self ) {
141
151
// A benign data race may happen here if there are failing sibling
142
152
// tasks that were also spawned-watched. The refcount's write barriers
@@ -287,6 +297,22 @@ impl Death {
287
297
self . unkillable = 0 ;
288
298
}
289
299
300
+ /// Fails if a kill signal was received.
301
+ #[ inline]
302
+ pub fn check_killed ( & self ) {
303
+ match self . kill_handle {
304
+ Some ( ref kill_handle) =>
305
+ // The task may be both unkillable and killed if it does some
306
+ // synchronization during unwinding or cleanup (for example,
307
+ // sending on a notify port). In that case failing won't help.
308
+ if self . unkillable == 0 && kill_handle. killed ( ) {
309
+ fail ! ( KILLED_MSG ) ;
310
+ } ,
311
+ // This may happen during task death (see comments in collect_failure).
312
+ None => rtassert ! ( self . unkillable > 0 ) ,
313
+ }
314
+ }
315
+
290
316
/// Enter a possibly-nested unkillable section of code.
291
317
/// All calls must be paired with a subsequent call to allow_kill.
292
318
#[ inline]
0 commit comments