Skip to content

Commit 7277bc4

Browse files
committed
---
yaml --- r: 143006 b: refs/heads/try2 c: e80efe3 h: refs/heads/master v: v3
1 parent fd504bf commit 7277bc4

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 629f6e8d68be06bf07f803db64be6a917a66b2cf
8+
refs/heads/try2: e80efe3fda506877b3fb7ff0df5d97dffb6a906f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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)