Skip to content

Commit f288685

Browse files
committed
---
yaml --- r: 64507 b: refs/heads/snap-stage3 c: e80efe3 h: refs/heads/master i: 64505: 53d58e4 64503: 45ea442 v: v3
1 parent cfca3a4 commit f288685

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 629f6e8d68be06bf07f803db64be6a917a66b2cf
4+
refs/heads/snap-stage3: e80efe3fda506877b3fb7ff0df5d97dffb6a906f
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/rt/kill.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cell::Cell;
1515
use option::{Option, Some, None};
1616
use prelude::*;
1717
use rt::task::Task;
18-
use unstable::atomics::{AtomicUint, SeqCst};
18+
use unstable::atomics::{AtomicUint, Acquire, SeqCst};
1919
use unstable::sync::{UnsafeAtomicRcBox, LittleLock};
2020
use util;
2121

@@ -137,6 +137,16 @@ impl KillHandle {
137137
}
138138
}
139139

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+
140150
pub fn notify_immediate_failure(&mut self) {
141151
// A benign data race may happen here if there are failing sibling
142152
// tasks that were also spawned-watched. The refcount's write barriers
@@ -287,6 +297,22 @@ impl Death {
287297
self.unkillable = 0;
288298
}
289299

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+
290316
/// Enter a possibly-nested unkillable section of code.
291317
/// All calls must be paired with a subsequent call to allow_kill.
292318
#[inline]

branches/snap-stage3/src/libstd/rt/sched.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ impl Scheduler {
483483

484484
// Running tasks may have asked us to do some cleanup
485485
(*sched).run_cleanup_job();
486+
487+
// Must happen after running the cleanup job (of course).
488+
// Might not be running in task context; if not, a later call to
489+
// resume_task_immediately will take care of this.
490+
(*sched).current_task.map(|t| t.death.check_killed());
486491
}
487492
}
488493

@@ -524,6 +529,9 @@ impl Scheduler {
524529
// We could be executing in a different thread now
525530
let sched = Local::unsafe_borrow::<Scheduler>();
526531
(*sched).run_cleanup_job();
532+
533+
// As above, must happen after running the cleanup job.
534+
(*sched).current_task.map(|t| t.death.check_killed());
527535
}
528536
}
529537

@@ -559,6 +567,9 @@ impl Scheduler {
559567
// We could be executing in a different thread now
560568
let sched = Local::unsafe_borrow::<Scheduler>();
561569
(*sched).run_cleanup_job();
570+
571+
// As above, must happen after running the cleanup job.
572+
(*sched).current_task.map(|t| t.death.check_killed());
562573
}
563574
}
564575

0 commit comments

Comments
 (0)