@@ -15,7 +15,7 @@ use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
1515use std:: rt:: task:: BlockedTask ;
1616use std:: rt:: task:: Task ;
1717use std:: sync:: deque;
18- use std:: unstable:: mutex:: Mutex ;
18+ use std:: unstable:: mutex:: NativeMutex ;
1919use std:: unstable:: raw;
2020
2121use TaskState ;
@@ -669,8 +669,7 @@ impl Scheduler {
669669 // is acquired here. This is the resumption points and the "bounce"
670670 // that it is referring to.
671671 unsafe {
672- current_task. nasty_deschedule_lock . lock ( ) ;
673- current_task. nasty_deschedule_lock . unlock ( ) ;
672+ let _guard = current_task. nasty_deschedule_lock . lock ( ) ;
674673 }
675674 return current_task;
676675 }
@@ -765,10 +764,11 @@ impl Scheduler {
765764 // to it, but we're guaranteed that the task won't exit until we've
766765 // unlocked the lock so there's no worry of this memory going away.
767766 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+ }
772772 } ) ;
773773 cur. put ( ) ;
774774 }
@@ -1453,8 +1453,8 @@ mod test {
14531453
14541454 #[ test]
14551455 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 ;
14581458
14591459 // Testing that a task in one scheduler can block in foreign code
14601460 // without affecting other schedulers
@@ -1466,12 +1466,11 @@ mod test {
14661466 let mut handle = pool. spawn_sched ( ) ;
14671467 handle. send ( PinnedTask ( pool. task ( TaskOpts :: new ( ) , proc ( ) {
14681468 unsafe {
1469- LOCK . lock ( ) ;
1469+ let mut guard = LOCK . lock ( ) ;
14701470
14711471 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
14751474 }
14761475
14771476 fin_ch. send ( ( ) ) ;
@@ -1503,10 +1502,9 @@ mod test {
15031502 child_ch. send ( 20 ) ;
15041503 pingpong ( & parent_po, & child_ch) ;
15051504 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
15101508 }
15111509 } ) ) ) ;
15121510 drop ( handle) ;
0 commit comments