File tree Expand file tree Collapse file tree 7 files changed +24
-30
lines changed Expand file tree Collapse file tree 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;
8989/// let guard = m.lock();
9090/// // do some work
9191/// 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
9992/// ```
10093pub struct Mutex {
10194 priv lock : StaticMutex ,
@@ -541,9 +534,9 @@ mod test {
541534 let ( p, c) = SharedChan :: new ( ) ;
542535 for _ in range ( 0 , N ) {
543536 let c2 = c. clone ( ) ;
544- do native:: task:: spawn { inc( ) ; c2. send ( ( ) ) ; }
537+ native:: task:: spawn ( proc ( ) { inc ( ) ; c2. send ( ( ) ) ; } ) ;
545538 let c2 = c. clone ( ) ;
546- do spawn { inc( ) ; c2. send ( ( ) ) ; }
539+ spawn ( proc ( ) { inc ( ) ; c2. send ( ( ) ) ; } ) ;
547540 }
548541
549542 drop ( c) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ use sync::mutex::{StaticMutex, MUTEX_INIT};
3030/// # Example
3131///
3232/// ```rust
33- /// use std::unstable::mutex ::{Once, ONCE_INIT};
33+ /// use extra::sync::one ::{Once, ONCE_INIT};
3434///
3535/// static mut START: Once = ONCE_INIT;
3636/// unsafe {
@@ -140,7 +140,7 @@ mod test {
140140 let ( p, c) = SharedChan :: new ( ) ;
141141 for _ in range ( 0 , 10 ) {
142142 let c = c. clone ( ) ;
143- do spawn {
143+ spawn ( proc ( ) {
144144 for _ in range ( 0 , 4 ) { task:: deschedule ( ) }
145145 unsafe {
146146 o. doit ( || {
@@ -150,7 +150,7 @@ mod test {
150150 assert ! ( run) ;
151151 }
152152 c. send ( ( ) ) ;
153- }
153+ } ) ;
154154 }
155155
156156 unsafe {
Original file line number Diff line number Diff line change @@ -1470,14 +1470,13 @@ mod test {
14701470 LOCK . signal ( ) ; // wakeup waiting scheduler
14711471 LOCK . wait ( ) ; // wait for them to grab the lock
14721472 LOCK . unlock ( ) ;
1473- LOCK . destroy ( ) ; // now we're guaranteed they have no locks
14741473 }
14751474 } ) ) ) ;
14761475 drop ( handle) ;
14771476
14781477 fin_po. recv ( ) ;
14791478 pool. shutdown ( ) ;
14801479 }
1481-
1480+ unsafe { LOCK . destroy ( ) ; }
14821481 }
14831482}
Original file line number Diff line number Diff line change @@ -204,17 +204,16 @@ pub fn init() {
204204 use std:: unstable:: mutex:: { Mutex , MUTEX_INIT } ;
205205 static mut INITIALIZED : bool = false ;
206206 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 ;
217215 }
216+ LOCK . unlock ( ) ;
218217 }
219218}
220219
Original file line number Diff line number Diff line change 2222
2323use std:: cast;
2424use std:: rt;
25- use std:: unstable:: mutex:: { Once , ONCE_INIT } ;
25+ use std:: unstable:: mutex:: { Mutex , MUTEX_INIT } ;
2626
2727use bookkeeping;
2828use io:: timer:: { Req , Shutdown } ;
@@ -37,10 +37,12 @@ static mut HELPER_CHAN: *mut SharedChan<Req> = 0 as *mut SharedChan<Req>;
3737static mut HELPER_SIGNAL : imp:: signal = 0 as imp:: signal ;
3838
3939pub 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 ;
4142
4243 unsafe {
43- INIT . doit ( || {
44+ LOCK . lock ( ) ;
45+ if !INITIALIZED {
4446 let ( msgp, msgc) = SharedChan :: new ( ) ;
4547 HELPER_CHAN = cast:: transmute ( ~msgc) ;
4648 let ( receive, send) = imp:: new ( ) ;
@@ -52,7 +54,9 @@ pub fn boot(helper: fn(imp::signal, Port<Req>)) {
5254 } ) ;
5355
5456 rt:: at_exit ( proc ( ) { shutdown ( ) } ) ;
55- } )
57+ INITIALIZED = true ;
58+ }
59+ LOCK . unlock ( ) ;
5660 }
5761}
5862
Original file line number Diff line number Diff line change @@ -96,7 +96,6 @@ pub mod write {
9696 use lib:: llvm:: llvm;
9797 use lib:: llvm:: { ModuleRef , TargetMachineRef , PassManagerRef } ;
9898 use lib;
99- use syntax:: abi;
10099 use util:: common:: time;
101100 use syntax:: abi;
102101
Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ impl<T> AtomicOption<T> {
384384 }
385385
386386 #[ 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 } }
388388 #[ cfg( not( stage0) ) ]
389389 pub fn empty ( ) -> AtomicOption < T > { AtomicOption { p : 0 } }
390390
You can’t perform that action at this time.
0 commit comments