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/io | |
| parent | 14c1a103bc3f78721df1dc860a75a477c8275e3a (diff) | |
| download | rust-43ae4b3301cc0605839778ecf59effb32b752e33.tar.gz rust-43ae4b3301cc0605839778ecf59effb32b752e33.zip | |
Fallout from new thread API
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/comm_adapters.rs | 10 | ||||
| -rw-r--r-- | src/libstd/io/net/pipe.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/net/tcp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 11 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 33 |
5 files changed, 28 insertions, 32 deletions
diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 2aa7435d871..d2a9861737d 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -156,12 +156,12 @@ mod test { use prelude::*; use super::*; use io; - use task; + use thread::Thread; #[test] fn test_rx_reader() { let (tx, rx) = channel(); - task::spawn(move|| { + Thread::spawn(move|| { tx.send(vec![1u8, 2u8]); tx.send(vec![]); tx.send(vec![3u8, 4u8]); @@ -203,7 +203,7 @@ mod test { #[test] fn test_rx_buffer() { let (tx, rx) = channel(); - task::spawn(move|| { + Thread::spawn(move|| { tx.send(b"he".to_vec()); tx.send(b"llo wo".to_vec()); tx.send(b"".to_vec()); @@ -229,7 +229,11 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; +<<<<<<< HEAD let got = match task::try(move|| { rx.recv() }) { +======= + let got = match Thread::with_join(proc() { rx.recv() }).join() { +>>>>>>> Fallout from new thread API Ok(got) => got, Err(_) => panic!(), }; diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index 9f2f41c0021..01eb33b44f9 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -549,7 +549,7 @@ mod tests { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::task::deschedule(); + ::thread::Thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } drop(l); diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 3c38e23183f..0e9a93e4275 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -1155,7 +1155,7 @@ mod test { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::task::deschedule(); + ::thread::Thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } } @@ -1378,7 +1378,7 @@ mod test { // Try to ensure that the reading clone is indeed reading for _ in range(0i, 50) { - ::task::deschedule(); + ::thread::Thread::yield_now(); } // clone the handle again while it's reading, then let it finish the diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 9ba6381c8c3..d9acb94714b 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -30,6 +30,7 @@ use hash::Hash; use std::hash::sip::SipState; use io::pipe::{PipeStream, PipePair}; use path::BytesContainer; +use thread::Thread; use sys; use sys::fs::FileDesc; @@ -693,10 +694,12 @@ impl Process { fn read(stream: Option<io::PipeStream>) -> Receiver<IoResult<Vec<u8>>> { let (tx, rx) = channel(); match stream { - Some(stream) => spawn(move |:| { - let mut stream = stream; - tx.send(stream.read_to_end()) - }), + Some(stream) => { + Thread::spawn(move |:| { + let mut stream = stream; + tx.send(stream.read_to_end()) + }); + } None => tx.send(Ok(Vec::new())) } rx diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 7b5cbf7d58f..32ba6278a89 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -41,9 +41,6 @@ use option::Option; use option::Option::{Some, None}; use ops::{Deref, DerefMut, FnOnce}; use result::Result::{Ok, Err}; -use rt; -use rt::local::Local; -use rt::task::Task; use slice::SliceExt; use str::StrPrelude; use string::String; @@ -328,25 +325,17 @@ pub fn set_stderr(stderr: Box<Writer + Send>) -> Option<Box<Writer + Send>> { // // io1 aliases io2 // }) // }) -fn with_task_stdout<F>(f: F) where - F: FnOnce(&mut Writer) -> IoResult<()>, -{ - let result = if Local::exists(None::<Task>) { - let mut my_stdout = LOCAL_STDOUT.with(|slot| { - slot.borrow_mut().take() - }).unwrap_or_else(|| { - box stdout() as Box<Writer + Send> - }); - let result = f(&mut *my_stdout); - let mut var = Some(my_stdout); - LOCAL_STDOUT.with(|slot| { - *slot.borrow_mut() = var.take(); - }); - result - } else { - let mut io = rt::util::Stdout; - f(&mut io as &mut Writer) - }; +fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) { + let mut my_stdout = LOCAL_STDOUT.with(|slot| { + slot.borrow_mut().take() + }).unwrap_or_else(|| { + box stdout() as Box<Writer + Send> + }); + let result = f(&mut *my_stdout); + let mut var = Some(my_stdout); + LOCAL_STDOUT.with(|slot| { + *slot.borrow_mut() = var.take(); + }); match result { Ok(()) => {} Err(e) => panic!("failed printing to stdout: {}", e), |
