File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 7be8f0af0393dcdb077c2f6b1653836fd3fba235
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: e156d001c6577593295f6eee417ea8758fbc4a84
4
+ refs/heads/snap-stage3: 355c798ac3eba15bb2d53a6c553c6149391f9615
5
5
refs/heads/try: 502e4c045236682e9728539dc0d2b3d0b237f55c
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
71
71
// Note that this increment must happen *before* the spawn in order to
72
72
// guarantee that if this task exits it will always end up waiting for the
73
73
// spawned task to exit.
74
- bookkeeping:: increment ( ) ;
74
+ let token = bookkeeping:: increment ( ) ;
75
75
76
76
// Spawning a new OS thread guarantees that __morestack will never get
77
77
// 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) {
93
93
let mut task = task;
94
94
task. put_runtime ( ops) ;
95
95
drop ( task. run ( || { f. take_unwrap ( ) ( ) } ) . destroy ( ) ) ;
96
- bookkeeping :: decrement ( ) ;
96
+ drop ( token ) ;
97
97
} )
98
98
}
99
99
Original file line number Diff line number Diff line change 19
19
//! decrement() manually.
20
20
21
21
use core:: atomics;
22
+ use core:: ops:: Drop ;
22
23
23
24
use mutex:: { StaticNativeMutex , NATIVE_MUTEX_INIT } ;
24
25
25
26
static mut TASK_COUNT : atomics:: AtomicUint = atomics:: INIT_ATOMIC_UINT ;
26
27
static mut TASK_LOCK : StaticNativeMutex = NATIVE_MUTEX_INIT ;
27
28
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 {
29
38
let _ = unsafe { TASK_COUNT . fetch_add ( 1 , atomics:: SeqCst ) } ;
39
+ Token ( ( ) )
30
40
}
31
41
32
42
pub fn decrement ( ) {
You can’t perform that action at this time.
0 commit comments