File tree 7 files changed +24
-30
lines changed
7 files changed +24
-30
lines changed Original file line number Diff line number Diff line change @@ -89,13 +89,6 @@ pub static NATIVE_BLOCKED: uint = 1 << 2;
89
89
/// let guard = m.lock();
90
90
/// // do some work
91
91
/// drop(guard); // unlock the lock
92
- ///
93
- /// {
94
- /// let _g = m.lock();
95
- /// // do some work in a scope
96
- /// }
97
- ///
98
- /// // now the mutex is unlocked
99
92
/// ```
100
93
pub struct Mutex {
101
94
priv lock : StaticMutex ,
@@ -541,9 +534,9 @@ mod test {
541
534
let ( p, c) = SharedChan :: new ( ) ;
542
535
for _ in range ( 0 , N ) {
543
536
let c2 = c. clone ( ) ;
544
- do native:: task:: spawn { inc( ) ; c2. send ( ( ) ) ; }
537
+ native:: task:: spawn ( proc ( ) { inc ( ) ; c2. send ( ( ) ) ; } ) ;
545
538
let c2 = c. clone ( ) ;
546
- do spawn { inc( ) ; c2. send ( ( ) ) ; }
539
+ spawn ( proc ( ) { inc ( ) ; c2. send ( ( ) ) ; } ) ;
547
540
}
548
541
549
542
drop ( c) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ use sync::mutex::{StaticMutex, MUTEX_INIT};
30
30
/// # Example
31
31
///
32
32
/// ```rust
33
- /// use std::unstable::mutex ::{Once, ONCE_INIT};
33
+ /// use extra::sync::one ::{Once, ONCE_INIT};
34
34
///
35
35
/// static mut START: Once = ONCE_INIT;
36
36
/// unsafe {
@@ -140,7 +140,7 @@ mod test {
140
140
let ( p, c) = SharedChan :: new ( ) ;
141
141
for _ in range ( 0 , 10 ) {
142
142
let c = c. clone ( ) ;
143
- do spawn {
143
+ spawn ( proc ( ) {
144
144
for _ in range ( 0 , 4 ) { task:: deschedule ( ) }
145
145
unsafe {
146
146
o. doit ( || {
@@ -150,7 +150,7 @@ mod test {
150
150
assert ! ( run) ;
151
151
}
152
152
c. send ( ( ) ) ;
153
- }
153
+ } ) ;
154
154
}
155
155
156
156
unsafe {
Original file line number Diff line number Diff line change @@ -1470,14 +1470,13 @@ mod test {
1470
1470
LOCK . signal ( ) ; // wakeup waiting scheduler
1471
1471
LOCK . wait ( ) ; // wait for them to grab the lock
1472
1472
LOCK . unlock ( ) ;
1473
- LOCK . destroy ( ) ; // now we're guaranteed they have no locks
1474
1473
}
1475
1474
} ) ) ) ;
1476
1475
drop ( handle) ;
1477
1476
1478
1477
fin_po. recv ( ) ;
1479
1478
pool. shutdown ( ) ;
1480
1479
}
1481
-
1480
+ unsafe { LOCK . destroy ( ) ; }
1482
1481
}
1483
1482
}
Original file line number Diff line number Diff line change @@ -204,17 +204,16 @@ pub fn init() {
204
204
use std:: unstable:: mutex:: { Mutex , MUTEX_INIT } ;
205
205
static mut INITIALIZED : bool = false ;
206
206
static mut LOCK : Mutex = MUTEX_INIT ;
207
- unsafe {
208
- LOCK . lock ( ) ;
209
- if !INITIALIZED {
210
- let mut data: WSADATA = intrinsics:: init ( ) ;
211
- let ret = WSAStartup ( 0x202 , // version 2.2
212
- & mut data) ;
213
- assert_eq ! ( ret, 0 ) ;
214
- INITIALIZED = true ;
215
- }
216
- LOCK . unlock ( ) ;
207
+
208
+ LOCK . lock ( ) ;
209
+ if !INITIALIZED {
210
+ let mut data: WSADATA = intrinsics:: init ( ) ;
211
+ let ret = WSAStartup ( 0x202 , // version 2.2
212
+ & mut data) ;
213
+ assert_eq ! ( ret, 0 ) ;
214
+ INITIALIZED = true ;
217
215
}
216
+ LOCK . unlock ( ) ;
218
217
}
219
218
}
220
219
Original file line number Diff line number Diff line change 22
22
23
23
use std:: cast;
24
24
use std:: rt;
25
- use std:: unstable:: mutex:: { Once , ONCE_INIT } ;
25
+ use std:: unstable:: mutex:: { Mutex , MUTEX_INIT } ;
26
26
27
27
use bookkeeping;
28
28
use io:: timer:: { Req , Shutdown } ;
@@ -37,10 +37,12 @@ static mut HELPER_CHAN: *mut SharedChan<Req> = 0 as *mut SharedChan<Req>;
37
37
static mut HELPER_SIGNAL : imp:: signal = 0 as imp:: signal ;
38
38
39
39
pub fn boot ( helper : fn ( imp:: signal , Port < Req > ) ) {
40
- static mut INIT : Once = ONCE_INIT ;
40
+ static mut LOCK : Mutex = MUTEX_INIT ;
41
+ static mut INITIALIZED : bool = false ;
41
42
42
43
unsafe {
43
- INIT . doit ( || {
44
+ LOCK . lock ( ) ;
45
+ if !INITIALIZED {
44
46
let ( msgp, msgc) = SharedChan :: new ( ) ;
45
47
HELPER_CHAN = cast:: transmute ( ~msgc) ;
46
48
let ( receive, send) = imp:: new ( ) ;
@@ -52,7 +54,9 @@ pub fn boot(helper: fn(imp::signal, Port<Req>)) {
52
54
} ) ;
53
55
54
56
rt:: at_exit ( proc ( ) { shutdown ( ) } ) ;
55
- } )
57
+ INITIALIZED = true ;
58
+ }
59
+ LOCK . unlock ( ) ;
56
60
}
57
61
}
58
62
Original file line number Diff line number Diff line change @@ -96,7 +96,6 @@ pub mod write {
96
96
use lib:: llvm:: llvm;
97
97
use lib:: llvm:: { ModuleRef , TargetMachineRef , PassManagerRef } ;
98
98
use lib;
99
- use syntax:: abi;
100
99
use util:: common:: time;
101
100
use syntax:: abi;
102
101
Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ impl<T> AtomicOption<T> {
384
384
}
385
385
386
386
#[ cfg( stage0) ]
387
- pub fn empty ( ) -> AtomicOption < T > { AtomicOption { p : 0 as * mut c_void } }
387
+ pub fn empty ( ) -> AtomicOption < T > { AtomicOption { p : 0 as * mut u8 } }
388
388
#[ cfg( not( stage0) ) ]
389
389
pub fn empty ( ) -> AtomicOption < T > { AtomicOption { p : 0 } }
390
390
You can’t perform that action at this time.
0 commit comments