Skip to content

Commit a088fb9

Browse files
committed
---
yaml --- r: 125423 b: refs/heads/master c: 355c798 h: refs/heads/master i: 125421: c4ad202 125419: 5d7792e 125415: fb2e629 125407: 53505e3 v: v3
1 parent 12aee68 commit a088fb9

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,5 +1,5 @@
11
---
2-
refs/heads/master: e156d001c6577593295f6eee417ea8758fbc4a84
2+
refs/heads/master: 355c798ac3eba15bb2d53a6c553c6149391f9615
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 9fc8394d3bce22ab483f98842434c84c396212ae
55
refs/heads/try: e5e0db5bc45aa2de6887fbf51dec013ca5c025c6

trunk/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

trunk/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)