Skip to content

Commit bbaddba

Browse files
committed
---
yaml --- r: 126970 b: refs/heads/snap-stage3 c: 355c798 h: refs/heads/master v: v3
1 parent fe2089d commit bbaddba

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
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: 7be8f0af0393dcdb077c2f6b1653836fd3fba235
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e156d001c6577593295f6eee417ea8758fbc4a84
4+
refs/heads/snap-stage3: 355c798ac3eba15bb2d53a6c553c6149391f9615
55
refs/heads/try: 502e4c045236682e9728539dc0d2b3d0b237f55c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libnative/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
7171
// Note that this increment must happen *before* the spawn in order to
7272
// guarantee that if this task exits it will always end up waiting for the
7373
// spawned task to exit.
74-
bookkeeping::increment();
74+
let token = bookkeeping::increment();
7575

7676
// Spawning a new OS thread guarantees that __morestack will never get
7777
// triggered, but we must manually set up the actual stack bounds once this
@@ -93,7 +93,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
9393
let mut task = task;
9494
task.put_runtime(ops);
9595
drop(task.run(|| { f.take_unwrap()() }).destroy());
96-
bookkeeping::decrement();
96+
drop(token);
9797
})
9898
}
9999

branches/snap-stage3/src/librustrt/bookkeeping.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@
1919
//! decrement() manually.
2020
2121
use core::atomics;
22+
use core::ops::Drop;
2223

2324
use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
2425

2526
static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
2627
static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
2728

28-
pub fn increment() {
29+
pub struct Token(());
30+
31+
impl Drop for Token {
32+
fn drop(&mut self) { decrement() }
33+
}
34+
35+
/// Increment the number of live tasks, returning a token which will decrement
36+
/// the count when dropped.
37+
pub fn increment() -> Token {
2938
let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
39+
Token(())
3040
}
3141

3242
pub fn decrement() {

0 commit comments

Comments
 (0)