@@ -15,7 +15,7 @@ use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
15
15
use std:: rt:: task:: BlockedTask ;
16
16
use std:: rt:: task:: Task ;
17
17
use std:: sync:: deque;
18
- use std:: unstable:: mutex:: Mutex ;
18
+ use std:: unstable:: mutex:: NativeMutex ;
19
19
use std:: unstable:: raw;
20
20
21
21
use TaskState ;
@@ -669,8 +669,7 @@ impl Scheduler {
669
669
// is acquired here. This is the resumption points and the "bounce"
670
670
// that it is referring to.
671
671
unsafe {
672
- current_task. nasty_deschedule_lock . lock ( ) ;
673
- current_task. nasty_deschedule_lock . unlock ( ) ;
672
+ let _guard = current_task. nasty_deschedule_lock . lock ( ) ;
674
673
}
675
674
return current_task;
676
675
}
@@ -765,10 +764,11 @@ impl Scheduler {
765
764
// to it, but we're guaranteed that the task won't exit until we've
766
765
// unlocked the lock so there's no worry of this memory going away.
767
766
let cur = self . change_task_context ( cur, next, |sched, mut task| {
768
- let lock: * mut Mutex = & mut task. nasty_deschedule_lock ;
769
- unsafe { ( * lock) . lock ( ) }
770
- f ( sched, BlockedTask :: block ( task. swap ( ) ) ) ;
771
- unsafe { ( * lock) . unlock ( ) }
767
+ let lock: * mut NativeMutex = & mut task. nasty_deschedule_lock ;
768
+ unsafe {
769
+ let _guard = ( * lock) . lock ( ) ;
770
+ f ( sched, BlockedTask :: block ( task. swap ( ) ) ) ;
771
+ }
772
772
} ) ;
773
773
cur. put ( ) ;
774
774
}
@@ -1453,8 +1453,8 @@ mod test {
1453
1453
1454
1454
#[ test]
1455
1455
fn test_spawn_sched_blocking ( ) {
1456
- use std:: unstable:: mutex:: { Mutex , MUTEX_INIT } ;
1457
- static mut LOCK : Mutex = MUTEX_INIT ;
1456
+ use std:: unstable:: mutex:: { StaticNativeMutex , NATIVE_MUTEX_INIT } ;
1457
+ static mut LOCK : StaticNativeMutex = NATIVE_MUTEX_INIT ;
1458
1458
1459
1459
// Testing that a task in one scheduler can block in foreign code
1460
1460
// without affecting other schedulers
@@ -1466,12 +1466,11 @@ mod test {
1466
1466
let mut handle = pool. spawn_sched ( ) ;
1467
1467
handle. send ( PinnedTask ( pool. task ( TaskOpts :: new ( ) , proc ( ) {
1468
1468
unsafe {
1469
- LOCK . lock ( ) ;
1469
+ let mut guard = LOCK . lock ( ) ;
1470
1470
1471
1471
start_ch. send ( ( ) ) ;
1472
- LOCK . wait ( ) ; // block the scheduler thread
1473
- LOCK . signal ( ) ; // let them know we have the lock
1474
- LOCK . unlock ( ) ;
1472
+ guard. wait ( ) ; // block the scheduler thread
1473
+ guard. signal ( ) ; // let them know we have the lock
1475
1474
}
1476
1475
1477
1476
fin_ch. send ( ( ) ) ;
@@ -1503,10 +1502,9 @@ mod test {
1503
1502
child_ch. send ( 20 ) ;
1504
1503
pingpong ( & parent_po, & child_ch) ;
1505
1504
unsafe {
1506
- LOCK . lock ( ) ;
1507
- LOCK . signal ( ) ; // wakeup waiting scheduler
1508
- LOCK . wait ( ) ; // wait for them to grab the lock
1509
- LOCK . unlock ( ) ;
1505
+ let mut guard = LOCK . lock ( ) ;
1506
+ guard. signal ( ) ; // wakeup waiting scheduler
1507
+ guard. wait ( ) ; // wait for them to grab the lock
1510
1508
}
1511
1509
} ) ) ) ;
1512
1510
drop ( handle) ;
0 commit comments