diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-12-06 18:34:37 -0800 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-12-18 23:31:51 -0800 |
| commit | 43ae4b3301cc0605839778ecf59effb32b752e33 (patch) | |
| tree | aa111f5adc1eaa1e996847e1437d1b1b40821ce0 /src/libstd/sync | |
| parent | 14c1a103bc3f78721df1dc860a75a477c8275e3a (diff) | |
| download | rust-43ae4b3301cc0605839778ecf59effb32b752e33.tar.gz rust-43ae4b3301cc0605839778ecf59effb32b752e33.zip | |
Fallout from new thread API
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/future.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/mutex.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/poison.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 34 | ||||
| -rw-r--r-- | src/libstd/sync/task_pool.rs | 7 |
6 files changed, 35 insertions, 42 deletions
diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index e5a1e09967c..16f2cff5998 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -29,8 +29,8 @@ use core::mem::replace; use self::FutureState::*; use comm::{Receiver, channel}; -use task::spawn; use thunk::{Thunk}; +use thread::Thread; /// A type encapsulating the result of a computation which may not be complete pub struct Future<A> { @@ -139,7 +139,7 @@ impl<A:Send> Future<A> { let (tx, rx) = channel(); - spawn(move |:| { + Thread::spawn(move |:| { // Don't panic if the other end has hung up let _ = tx.send_opt(blk()); }); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 33f8d254c71..fc73e2957a5 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -274,7 +274,7 @@ impl Drop for StaticMutexGuard { mod test { use prelude::*; - use task; + use thread::Thread; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; #[test] @@ -386,10 +386,10 @@ mod test { fn test_mutex_arc_poison() { let arc = Arc::new(Mutex::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| { + let _ = Thread::with_join(move|| { let lock = arc2.lock(); assert_eq!(*lock, 2); - }); + }).join(); let lock = arc.lock(); assert_eq!(*lock, 1); } @@ -414,7 +414,7 @@ mod test { fn test_mutex_arc_access_in_unwind() { let arc = Arc::new(Mutex::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| -> () { + let _ = Thread::with_join::<()>(move|| -> () { struct Unwinder { i: Arc<Mutex<int>>, } @@ -425,7 +425,7 @@ mod test { } let _u = Unwinder { i: arc2 }; panic!(); - }); + }).join(); let lock = arc.lock(); assert_eq!(*lock, 2); } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 263937c5cbe..a43f822e351 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -121,7 +121,7 @@ impl Once { mod test { use prelude::*; - use task; + use thread::Thread; use super::{ONCE_INIT, Once}; #[test] @@ -143,7 +143,7 @@ mod test { for _ in range(0u, 10) { let tx = tx.clone(); spawn(move|| { - for _ in range(0u, 4) { task::deschedule() } + for _ in range(0u, 4) { Thread::yield_now() } unsafe { O.doit(|| { assert!(!run); diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index ee151556620..ad08e9873fa 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -8,21 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use option::Option::None; -use rustrt::task::Task; -use rustrt::local::Local; +use thread::Thread; pub struct Flag { pub failed: bool } impl Flag { pub fn borrow(&mut self) -> Guard { - Guard { flag: &mut self.failed, failing: failing() } + Guard { flag: &mut self.failed, panicking: Thread::panicking() } } } pub struct Guard<'a> { flag: &'a mut bool, - failing: bool, + panicking: bool, } impl<'a> Guard<'a> { @@ -33,16 +31,8 @@ impl<'a> Guard<'a> { } pub fn done(&mut self) { - if !self.failing && failing() { + if !self.panicking && Thread::panicking() { *self.flag = true; } } } - -fn failing() -> bool { - if Local::exists(None::<Task>) { - Local::borrow(None::<Task>).unwinder.unwinding() - } else { - false - } -} diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index b6d6aa989c5..1f1e9eea1d6 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -356,7 +356,7 @@ mod tests { use prelude::*; use rand::{mod, Rng}; - use task; + use thread::Thread; use sync::{Arc, RWLock, StaticRWLock, RWLOCK_INIT}; #[test] @@ -409,10 +409,10 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = Arc::new(RWLock::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| { + let _ = Thread::with_join(move|| { let lock = arc2.write(); assert_eq!(*lock, 2); - }); + }).join(); let lock = arc.read(); assert_eq!(*lock, 1); } @@ -422,10 +422,10 @@ mod tests { fn test_rw_arc_poison_ww() { let arc = Arc::new(RWLock::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| { + let _ = Thread::with_join(move|| { let lock = arc2.write(); assert_eq!(*lock, 2); - }); + }).join(); let lock = arc.write(); assert_eq!(*lock, 1); } @@ -434,10 +434,10 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RWLock::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| { + let _ = Thread::with_join(move|| { let lock = arc2.read(); assert_eq!(*lock, 2); - }); + }).join(); let lock = arc.read(); assert_eq!(*lock, 1); } @@ -445,10 +445,10 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RWLock::new(1i)); let arc2 = arc.clone(); - let _ = task::try(move|| { + let _ = Thread::with_join(move|| { let lock = arc2.read(); assert_eq!(*lock, 2); - }); + }).join(); let lock = arc.write(); assert_eq!(*lock, 1); } @@ -459,12 +459,12 @@ mod tests { let arc2 = arc.clone(); let (tx, rx) = channel(); - task::spawn(move|| { + Thread::spawn(move|| { let mut lock = arc2.write(); for _ in range(0u, 10) { let tmp = *lock; *lock = -1; - task::deschedule(); + Thread::yield_now(); *lock = tmp + 1; } tx.send(()); @@ -474,15 +474,15 @@ mod tests { let mut children = Vec::new(); for _ in range(0u, 5) { let arc3 = arc.clone(); - children.push(task::try_future(move|| { + children.push(Thread::with_join(move|| { let lock = arc3.read(); assert!(*lock >= 0); })); } // Wait for children to pass their asserts - for r in children.iter_mut() { - assert!(r.get_ref().is_ok()); + for r in children.into_iter() { + assert!(r.join().is_ok()); } // Wait for writer to finish @@ -495,7 +495,11 @@ mod tests { fn test_rw_arc_access_in_unwind() { let arc = Arc::new(RWLock::new(1i)); let arc2 = arc.clone(); +<<<<<<< HEAD let _ = task::try(move|| -> () { +======= + let _ = Thread::with_join::<()>(proc() { +>>>>>>> Fallout from new thread API struct Unwinder { i: Arc<RWLock<int>>, } @@ -507,7 +511,7 @@ mod tests { } let _u = Unwinder { i: arc2 }; panic!(); - }); + }).join(); let lock = arc.read(); assert_eq!(*lock, 2); } diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index fa5b62a202b..5e7944d5fe5 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -12,7 +12,7 @@ use core::prelude::*; -use task::{spawn}; +use thread::Thread; use comm::{channel, Sender, Receiver}; use sync::{Arc, Mutex}; use thunk::Thunk; @@ -105,7 +105,7 @@ impl TaskPool { } fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) { - spawn(move |:| { + Thread::spawn(move |:| { // Will spawn a new task on panic unless it is cancelled. let sentinel = Sentinel::new(&jobs); @@ -126,7 +126,7 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) { } sentinel.cancel(); - }) + }); } #[cfg(test)] @@ -206,4 +206,3 @@ mod test { waiter.wait(); } } - |
