Fallout from new thread API

This commit is contained in:
Aaron Turon 2014-12-06 18:34:37 -08:00
parent 14c1a103bc
commit 43ae4b3301
51 changed files with 323 additions and 439 deletions

View file

@ -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!(),
};

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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),