Removing do keyword from libextra

This commit is contained in:
Scott Lawrence
2014-01-26 23:13:24 -05:00
parent d904179066
commit badc580416
8 changed files with 122 additions and 123 deletions

View File

@@ -28,12 +28,12 @@
* let (port, chan) = Chan::new(); * let (port, chan) = Chan::new();
* chan.send(shared_numbers.clone()); * chan.send(shared_numbers.clone());
* *
* do spawn { * spawn(proc() {
* let shared_numbers = port.recv(); * let shared_numbers = port.recv();
* let local_numbers = shared_numbers.get(); * let local_numbers = shared_numbers.get();
* *
* // Work with the local numbers * // Work with the local numbers
* } * });
* } * }
* ``` * ```
*/ */
@@ -567,12 +567,12 @@ mod tests {
let (p, c) = Chan::new(); let (p, c) = Chan::new();
do task::spawn { task::spawn(proc() {
let arc_v: Arc<~[int]> = p.recv(); let arc_v: Arc<~[int]> = p.recv();
let v = arc_v.get().clone(); let v = arc_v.get().clone();
assert_eq!(v[3], 4); assert_eq!(v[3], 4);
}; });
c.send(arc_v.clone()); c.send(arc_v.clone());
@@ -587,14 +587,14 @@ mod tests {
let arc = ~MutexArc::new(false); let arc = ~MutexArc::new(false);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (p,c) = Chan::new(); let (p,c) = Chan::new();
do task::spawn { task::spawn(proc() {
// wait until parent gets in // wait until parent gets in
p.recv(); p.recv();
arc2.access_cond(|state, cond| { arc2.access_cond(|state, cond| {
*state = true; *state = true;
cond.signal(); cond.signal();
}) })
} });
arc.access_cond(|state, cond| { arc.access_cond(|state, cond| {
c.send(()); c.send(());
@@ -611,14 +611,14 @@ mod tests {
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (p, c) = Chan::new(); let (p, c) = Chan::new();
do spawn { spawn(proc() {
let _ = p.recv(); let _ = p.recv();
arc2.access_cond(|one, cond| { arc2.access_cond(|one, cond| {
cond.signal(); cond.signal();
// Parent should fail when it wakes up. // Parent should fail when it wakes up.
assert_eq!(*one, 0); assert_eq!(*one, 0);
}) })
} });
arc.access_cond(|one, cond| { arc.access_cond(|one, cond| {
c.send(()); c.send(());
@@ -632,11 +632,11 @@ mod tests {
fn test_mutex_arc_poison() { fn test_mutex_arc_poison() {
let arc = ~MutexArc::new(1); let arc = ~MutexArc::new(1);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
do task::try || { task::try(proc() {
arc2.access(|one| { arc2.access(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}; });
arc.access(|one| { arc.access(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -649,13 +649,13 @@ mod tests {
// to underlaying data. // to underlaying data.
let arc = ~MutexArc::new(1); let arc = ~MutexArc::new(1);
let arc2 = ~MutexArc::new(*arc); let arc2 = ~MutexArc::new(*arc);
do task::spawn || { task::spawn(proc() {
(*arc2).unsafe_access(|mutex| { (*arc2).unsafe_access(|mutex| {
(*mutex).access(|one| { (*mutex).access(|one| {
assert!(*one == 1); assert!(*one == 1);
}) })
}) })
}; });
} }
} }
@@ -682,11 +682,11 @@ mod tests {
fn test_rw_arc_poison_wr() { fn test_rw_arc_poison_wr() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.write(|one| { arc2.write(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}; });
arc.read(|one| { arc.read(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -696,11 +696,11 @@ mod tests {
fn test_rw_arc_poison_ww() { fn test_rw_arc_poison_ww() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.write(|one| { arc2.write(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}; });
arc.write(|one| { arc.write(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -709,13 +709,13 @@ mod tests {
fn test_rw_arc_poison_dw() { fn test_rw_arc_poison_dw() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.write_downgrade(|mut write_mode| { arc2.write_downgrade(|mut write_mode| {
write_mode.write(|one| { write_mode.write(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}) })
}; });
arc.write(|one| { arc.write(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -724,11 +724,11 @@ mod tests {
fn test_rw_arc_no_poison_rr() { fn test_rw_arc_no_poison_rr() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.read(|one| { arc2.read(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}; });
arc.read(|one| { arc.read(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -737,11 +737,11 @@ mod tests {
fn test_rw_arc_no_poison_rw() { fn test_rw_arc_no_poison_rw() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.read(|one| { arc2.read(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}; });
arc.write(|one| { arc.write(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -750,14 +750,14 @@ mod tests {
fn test_rw_arc_no_poison_dr() { fn test_rw_arc_no_poison_dr() {
let arc = RWArc::new(1); let arc = RWArc::new(1);
let arc2 = arc.clone(); let arc2 = arc.clone();
do task::try { task::try(proc() {
arc2.write_downgrade(|write_mode| { arc2.write_downgrade(|write_mode| {
let read_mode = arc2.downgrade(write_mode); let read_mode = arc2.downgrade(write_mode);
read_mode.read(|one| { read_mode.read(|one| {
assert_eq!(*one, 2); assert_eq!(*one, 2);
}) })
}) })
}; });
arc.write(|one| { arc.write(|one| {
assert_eq!(*one, 1); assert_eq!(*one, 1);
}) })
@@ -768,7 +768,7 @@ mod tests {
let arc2 = arc.clone(); let arc2 = arc.clone();
let (p, c) = Chan::new(); let (p, c) = Chan::new();
do task::spawn { task::spawn(proc() {
arc2.write(|num| { arc2.write(|num| {
10.times(|| { 10.times(|| {
let tmp = *num; let tmp = *num;
@@ -778,7 +778,7 @@ mod tests {
}); });
c.send(()); c.send(());
}) })
} });
// Readers try to catch the writer in the act // Readers try to catch the writer in the act
let mut children = ~[]; let mut children = ~[];
@@ -786,11 +786,11 @@ mod tests {
let arc3 = arc.clone(); let arc3 = arc.clone();
let mut builder = task::task(); let mut builder = task::task();
children.push(builder.future_result()); children.push(builder.future_result());
do builder.spawn { builder.spawn(proc() {
arc3.read(|num| { arc3.read(|num| {
assert!(*num >= 0); assert!(*num >= 0);
}) })
} });
}); });
// Wait for children to pass their asserts // Wait for children to pass their asserts
@@ -840,19 +840,19 @@ mod tests {
let ((rp1, rc1), (rp2, rc2)) = (Chan::new(), Chan::new()); let ((rp1, rc1), (rp2, rc2)) = (Chan::new(), Chan::new());
reader_convos.push((rc1, rp2)); reader_convos.push((rc1, rp2));
let arcn = arc.clone(); let arcn = arc.clone();
do task::spawn { task::spawn(proc() {
rp1.recv(); // wait for downgrader to give go-ahead rp1.recv(); // wait for downgrader to give go-ahead
arcn.read(|state| { arcn.read(|state| {
assert_eq!(*state, 31337); assert_eq!(*state, 31337);
rc2.send(()); rc2.send(());
}) })
} });
}); });
// Writer task // Writer task
let arc2 = arc.clone(); let arc2 = arc.clone();
let ((wp1, wc1), (wp2, wc2)) = (Chan::new(), Chan::new()); let ((wp1, wc1), (wp2, wc2)) = (Chan::new(), Chan::new());
do task::spawn || { task::spawn(proc() {
wp1.recv(); wp1.recv();
arc2.write_cond(|state, cond| { arc2.write_cond(|state, cond| {
assert_eq!(*state, 0); assert_eq!(*state, 0);
@@ -867,7 +867,7 @@ mod tests {
*state = 42; *state = 42;
}); });
wc2.send(()); wc2.send(());
} });
// Downgrader (us) // Downgrader (us)
arc.write_downgrade(|mut write_mode| { arc.write_downgrade(|mut write_mode| {
@@ -912,7 +912,7 @@ mod tests {
// writer task // writer task
let xw = x.clone(); let xw = x.clone();
do task::spawn { task::spawn(proc() {
xw.write_cond(|state, c| { xw.write_cond(|state, c| {
wc.send(()); // tell downgrader it's ok to go wc.send(()); // tell downgrader it's ok to go
c.wait(); c.wait();
@@ -921,7 +921,7 @@ mod tests {
// trying to receive the "reader cloud lock hand-off". // trying to receive the "reader cloud lock hand-off".
*state = false; *state = false;
}) })
} });
wp.recv(); // wait for writer to get in wp.recv(); // wait for writer to get in
@@ -934,10 +934,10 @@ mod tests {
// make a reader task to trigger the "reader cloud lock" handoff // make a reader task to trigger the "reader cloud lock" handoff
let xr = x.clone(); let xr = x.clone();
let (rp, rc) = Chan::new(); let (rp, rc) = Chan::new();
do task::spawn { task::spawn(proc() {
rc.send(()); rc.send(());
xr.read(|_state| { }) xr.read(|_state| { })
} });
rp.recv(); // wait for reader task to exist rp.recv(); // wait for reader task to exist
let read_mode = x.downgrade(write_mode); let read_mode = x.downgrade(write_mode);

View File

@@ -115,9 +115,9 @@ mod test {
pub fn basic_rendezvous_test() { pub fn basic_rendezvous_test() {
let (port, chan) = rendezvous(); let (port, chan) = rendezvous();
do spawn { spawn(proc() {
chan.send("abc"); chan.send("abc");
} });
assert!(port.recv() == "abc"); assert!(port.recv() == "abc");
} }
@@ -126,29 +126,29 @@ mod test {
fn recv_a_lot() { fn recv_a_lot() {
// Rendezvous streams should be able to handle any number of messages being sent // Rendezvous streams should be able to handle any number of messages being sent
let (port, chan) = rendezvous(); let (port, chan) = rendezvous();
do spawn { spawn(proc() {
10000.times(|| { chan.send(()) }) 10000.times(|| { chan.send(()) })
} });
10000.times(|| { port.recv() }) 10000.times(|| { port.recv() })
} }
#[test] #[test]
fn send_and_fail_and_try_recv() { fn send_and_fail_and_try_recv() {
let (port, chan) = rendezvous(); let (port, chan) = rendezvous();
do spawn { spawn(proc() {
chan.duplex_stream.send(()); // Can't access this field outside this module chan.duplex_stream.send(()); // Can't access this field outside this module
fail!() fail!()
} });
port.recv() port.recv()
} }
#[test] #[test]
fn try_send_and_recv_then_fail_before_ack() { fn try_send_and_recv_then_fail_before_ack() {
let (port, chan) = rendezvous(); let (port, chan) = rendezvous();
do spawn { spawn(proc() {
port.duplex_stream.recv(); port.duplex_stream.recv();
fail!() fail!()
} });
chan.try_send(()); chan.try_send(());
} }
@@ -156,10 +156,10 @@ mod test {
#[should_fail] #[should_fail]
fn send_and_recv_then_fail_before_ack() { fn send_and_recv_then_fail_before_ack() {
let (port, chan) = rendezvous(); let (port, chan) = rendezvous();
do spawn { spawn(proc() {
port.duplex_stream.recv(); port.duplex_stream.recv();
fail!() fail!()
} });
chan.send(()); chan.send(());
} }
} }

View File

@@ -971,10 +971,10 @@ mod tests {
#[test] #[test]
fn test_send() { fn test_send() {
let n = list_from([1,2,3]); let n = list_from([1,2,3]);
do spawn { spawn(proc() {
check_links(&n); check_links(&n);
assert_eq!(~[&1,&2,&3], n.iter().collect::<~[&int]>()); assert_eq!(~[&1,&2,&3], n.iter().collect::<~[&int]>());
} });
} }
#[test] #[test]

View File

@@ -18,7 +18,7 @@
* use extra::future::Future; * use extra::future::Future;
* # fn fib(n: uint) -> uint {42}; * # fn fib(n: uint) -> uint {42};
* # fn make_a_sandwich() {}; * # fn make_a_sandwich() {};
* let mut delayed_fib = do Future::spawn { fib(5000) }; * let mut delayed_fib = Future::spawn(proc() { fib(5000) });
* make_a_sandwich(); * make_a_sandwich();
* println!("fib(5000) = {}", delayed_fib.get()) * println!("fib(5000) = {}", delayed_fib.get())
* ``` * ```
@@ -112,9 +112,9 @@ impl<A:Send> Future<A> {
* waiting for the result to be received on the port. * waiting for the result to be received on the port.
*/ */
do Future::from_fn { Future::from_fn(proc() {
port.recv() port.recv()
} })
} }
pub fn spawn(blk: proc() -> A) -> Future<A> { pub fn spawn(blk: proc() -> A) -> Future<A> {
@@ -127,9 +127,9 @@ impl<A:Send> Future<A> {
let (port, chan) = Chan::new(); let (port, chan) = Chan::new();
do spawn { spawn(proc() {
chan.send(blk()); chan.send(blk());
} });
Future::from_port(port) Future::from_port(port)
} }
@@ -195,11 +195,11 @@ mod test {
#[test] #[test]
fn test_sendable_future() { fn test_sendable_future() {
let expected = "schlorf"; let expected = "schlorf";
let f = do Future::spawn { expected }; let f = Future::spawn(proc() { expected });
do task::spawn { task::spawn(proc() {
let mut f = f; let mut f = f;
let actual = f.get(); let actual = f.get();
assert_eq!(actual, expected); assert_eq!(actual, expected);
} });
} }
} }

View File

@@ -2201,7 +2201,7 @@ mod tests {
} }
fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected_error: &str) { fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected_error: &str) {
use std::task; use std::task;
let res = do task::try { let res = task::try(proc() {
// either fails in `decode` (which is what we want), or // either fails in `decode` (which is what we want), or
// returns Some(error_message)/None if the string was // returns Some(error_message)/None if the string was
// invalid or valid JSON. // invalid or valid JSON.
@@ -2212,7 +2212,7 @@ mod tests {
None None
} }
} }
}; });
match res { match res {
Ok(Some(parse_error)) => fail!("`{}` is not valid json: {}", Ok(Some(parse_error)) => fail!("`{}` is not valid json: {}",
to_parse, parse_error), to_parse, parse_error),

View File

@@ -695,11 +695,11 @@ impl<'a> RWLockReadMode<'a> {
/// let c = barrier.clone(); /// let c = barrier.clone();
/// // The same messages will be printed together. /// // The same messages will be printed together.
/// // You will NOT see any interleaving. /// // You will NOT see any interleaving.
/// do spawn { /// spawn(proc() {
/// println!("before wait"); /// println!("before wait");
/// c.wait(); /// c.wait();
/// println!("after wait"); /// println!("after wait");
/// } /// });
/// }); /// });
/// ``` /// ```
#[deriving(Clone)] #[deriving(Clone)]
@@ -778,11 +778,11 @@ mod tests {
fn test_sem_as_mutex() { fn test_sem_as_mutex() {
let s = Semaphore::new(1); let s = Semaphore::new(1);
let s2 = s.clone(); let s2 = s.clone();
do task::spawn { task::spawn(proc() {
s2.access(|| { s2.access(|| {
5.times(|| { task::deschedule(); }) 5.times(|| { task::deschedule(); })
}) })
} });
s.access(|| { s.access(|| {
5.times(|| { task::deschedule(); }) 5.times(|| { task::deschedule(); })
}) })
@@ -793,10 +793,10 @@ mod tests {
let (p, c) = Chan::new(); let (p, c) = Chan::new();
let s = Semaphore::new(0); let s = Semaphore::new(0);
let s2 = s.clone(); let s2 = s.clone();
do task::spawn { task::spawn(proc() {
s2.acquire(); s2.acquire();
c.send(()); c.send(());
} });
5.times(|| { task::deschedule(); }); 5.times(|| { task::deschedule(); });
s.release(); s.release();
let _ = p.recv(); let _ = p.recv();
@@ -805,11 +805,11 @@ mod tests {
let (p, c) = Chan::new(); let (p, c) = Chan::new();
let s = Semaphore::new(0); let s = Semaphore::new(0);
let s2 = s.clone(); let s2 = s.clone();
do task::spawn { task::spawn(proc() {
5.times(|| { task::deschedule(); }); 5.times(|| { task::deschedule(); });
s2.release(); s2.release();
let _ = p.recv(); let _ = p.recv();
} });
s.acquire(); s.acquire();
c.send(()); c.send(());
} }
@@ -821,12 +821,12 @@ mod tests {
let s2 = s.clone(); let s2 = s.clone();
let (p1,c1) = Chan::new(); let (p1,c1) = Chan::new();
let (p2,c2) = Chan::new(); let (p2,c2) = Chan::new();
do task::spawn { task::spawn(proc() {
s2.access(|| { s2.access(|| {
let _ = p2.recv(); let _ = p2.recv();
c1.send(()); c1.send(());
}) })
} });
s.access(|| { s.access(|| {
c2.send(()); c2.send(());
let _ = p1.recv(); let _ = p1.recv();
@@ -842,11 +842,11 @@ mod tests {
let mut child_data = Some((s2, c)); let mut child_data = Some((s2, c));
s.access(|| { s.access(|| {
let (s2, c) = child_data.take_unwrap(); let (s2, c) = child_data.take_unwrap();
do task::spawn { task::spawn(proc() {
c.send(()); c.send(());
s2.access(|| { }); s2.access(|| { });
c.send(()); c.send(());
} });
let _ = p.recv(); // wait for child to come alive let _ = p.recv(); // wait for child to come alive
5.times(|| { task::deschedule(); }); // let the child contend 5.times(|| { task::deschedule(); }); // let the child contend
}); });
@@ -865,13 +865,12 @@ mod tests {
let mut sharedstate = ~0; let mut sharedstate = ~0;
{ {
let ptr: *int = &*sharedstate; let ptr: *int = &*sharedstate;
do task::spawn { task::spawn(proc() {
let sharedstate: &mut int = let sharedstate: &mut int =
unsafe { cast::transmute(ptr) }; unsafe { cast::transmute(ptr) };
access_shared(sharedstate, &m2, 10); access_shared(sharedstate, &m2, 10);
c.send(()); c.send(());
});
}
} }
{ {
access_shared(sharedstate, &m, 10); access_shared(sharedstate, &m, 10);
@@ -897,24 +896,24 @@ mod tests {
// Child wakes up parent // Child wakes up parent
m.lock_cond(|cond| { m.lock_cond(|cond| {
let m2 = m.clone(); let m2 = m.clone();
do task::spawn { task::spawn(proc() {
m2.lock_cond(|cond| { m2.lock_cond(|cond| {
let woken = cond.signal(); let woken = cond.signal();
assert!(woken); assert!(woken);
}) })
} });
cond.wait(); cond.wait();
}); });
// Parent wakes up child // Parent wakes up child
let (port,chan) = Chan::new(); let (port,chan) = Chan::new();
let m3 = m.clone(); let m3 = m.clone();
do task::spawn { task::spawn(proc() {
m3.lock_cond(|cond| { m3.lock_cond(|cond| {
chan.send(()); chan.send(());
cond.wait(); cond.wait();
chan.send(()); chan.send(());
}) })
} });
let _ = port.recv(); // Wait until child gets in the mutex let _ = port.recv(); // Wait until child gets in the mutex
m.lock_cond(|cond| { m.lock_cond(|cond| {
let woken = cond.signal(); let woken = cond.signal();
@@ -931,13 +930,13 @@ mod tests {
let mi = m.clone(); let mi = m.clone();
let (port, chan) = Chan::new(); let (port, chan) = Chan::new();
ports.push(port); ports.push(port);
do task::spawn { task::spawn(proc() {
mi.lock_cond(|cond| { mi.lock_cond(|cond| {
chan.send(()); chan.send(());
cond.wait(); cond.wait();
chan.send(()); chan.send(());
}) })
} });
}); });
// wait until all children get in the mutex // wait until all children get in the mutex
@@ -961,9 +960,9 @@ mod tests {
fn test_mutex_cond_no_waiter() { fn test_mutex_cond_no_waiter() {
let m = Mutex::new(); let m = Mutex::new();
let m2 = m.clone(); let m2 = m.clone();
do task::try { task::try(proc() {
m.lock_cond(|_x| { }) m.lock_cond(|_x| { })
}; });
m2.lock_cond(|cond| { m2.lock_cond(|cond| {
assert!(!cond.signal()); assert!(!cond.signal());
}) })
@@ -974,11 +973,11 @@ mod tests {
let m = Mutex::new(); let m = Mutex::new();
let m2 = m.clone(); let m2 = m.clone();
let result: result::Result<(), ~Any> = do task::try { let result: result::Result<(), ~Any> = task::try(proc() {
m2.lock(|| { m2.lock(|| {
fail!(); fail!();
}) })
}; });
assert!(result.is_err()); assert!(result.is_err());
// child task must have finished by the time try returns // child task must have finished by the time try returns
m.lock(|| { }) m.lock(|| { })
@@ -991,18 +990,18 @@ mod tests {
let m = Mutex::new(); let m = Mutex::new();
let m2 = m.clone(); let m2 = m.clone();
let result: result::Result<(), ~Any> = do task::try { let result: result::Result<(), ~Any> = task::try(proc() {
let (p, c) = Chan::new(); let (p, c) = Chan::new();
do task::spawn { // linked task::spawn(proc() { // linked
let _ = p.recv(); // wait for sibling to get in the mutex let _ = p.recv(); // wait for sibling to get in the mutex
task::deschedule(); task::deschedule();
fail!(); fail!();
} });
m2.lock_cond(|cond| { m2.lock_cond(|cond| {
c.send(()); // tell sibling go ahead c.send(()); // tell sibling go ahead
cond.wait(); // block forever cond.wait(); // block forever
}) })
}; });
assert!(result.is_err()); assert!(result.is_err());
// child task must have finished by the time try returns // child task must have finished by the time try returns
m.lock_cond(|cond| { m.lock_cond(|cond| {
@@ -1019,14 +1018,14 @@ mod tests {
let m2 = m.clone(); let m2 = m.clone();
let (p, c) = Chan::new(); let (p, c) = Chan::new();
let result: result::Result<(), ~Any> = do task::try { let result: result::Result<(), ~Any> = task::try(proc() {
let mut sibling_convos = ~[]; let mut sibling_convos = ~[];
2.times(|| { 2.times(|| {
let (p, c) = Chan::new(); let (p, c) = Chan::new();
sibling_convos.push(p); sibling_convos.push(p);
let mi = m2.clone(); let mi = m2.clone();
// spawn sibling task // spawn sibling task
do task::spawn { // linked task::spawn(proc() { // linked
mi.lock_cond(|cond| { mi.lock_cond(|cond| {
c.send(()); // tell sibling to go ahead c.send(()); // tell sibling to go ahead
(|| { (|| {
@@ -1037,7 +1036,7 @@ mod tests {
error!("task unwinding and done sending"); error!("task unwinding and done sending");
}) })
}) })
} });
}); });
for p in sibling_convos.mut_iter() { for p in sibling_convos.mut_iter() {
let _ = p.recv(); // wait for sibling to get in the mutex let _ = p.recv(); // wait for sibling to get in the mutex
@@ -1045,7 +1044,7 @@ mod tests {
m2.lock(|| { }); m2.lock(|| { });
c.send(sibling_convos); // let parent wait on all children c.send(sibling_convos); // let parent wait on all children
fail!(); fail!();
}; });
assert!(result.is_err()); assert!(result.is_err());
// child task must have finished by the time try returns // child task must have finished by the time try returns
let mut r = p.recv(); let mut r = p.recv();
@@ -1061,52 +1060,52 @@ mod tests {
let m = Mutex::new(); let m = Mutex::new();
m.lock_cond(|cond| { m.lock_cond(|cond| {
let m2 = m.clone(); let m2 = m.clone();
do task::spawn { task::spawn(proc() {
m2.lock_cond(|cond| { m2.lock_cond(|cond| {
cond.signal_on(0); cond.signal_on(0);
}) })
} });
cond.wait(); cond.wait();
}) })
} }
#[test] #[test]
#[ignore(reason = "linked failure?")] #[ignore(reason = "linked failure?")]
fn test_mutex_different_conds() { fn test_mutex_different_conds() {
let result = do task::try { let result = task::try(proc() {
let m = Mutex::new_with_condvars(2); let m = Mutex::new_with_condvars(2);
let m2 = m.clone(); let m2 = m.clone();
let (p, c) = Chan::new(); let (p, c) = Chan::new();
do task::spawn { task::spawn(proc() {
m2.lock_cond(|cond| { m2.lock_cond(|cond| {
c.send(()); c.send(());
cond.wait_on(1); cond.wait_on(1);
}) })
} });
let _ = p.recv(); let _ = p.recv();
m.lock_cond(|cond| { m.lock_cond(|cond| {
if !cond.signal_on(0) { if !cond.signal_on(0) {
fail!(); // success; punt sibling awake. fail!(); // success; punt sibling awake.
} }
}) })
}; });
assert!(result.is_err()); assert!(result.is_err());
} }
#[test] #[test]
fn test_mutex_no_condvars() { fn test_mutex_no_condvars() {
let result = do task::try { let result = task::try(proc() {
let m = Mutex::new_with_condvars(0); let m = Mutex::new_with_condvars(0);
m.lock_cond(|cond| { cond.wait(); }) m.lock_cond(|cond| { cond.wait(); })
}; });
assert!(result.is_err()); assert!(result.is_err());
let result = do task::try { let result = task::try(proc() {
let m = Mutex::new_with_condvars(0); let m = Mutex::new_with_condvars(0);
m.lock_cond(|cond| { cond.signal(); }) m.lock_cond(|cond| { cond.signal(); })
}; });
assert!(result.is_err()); assert!(result.is_err());
let result = do task::try { let result = task::try(proc() {
let m = Mutex::new_with_condvars(0); let m = Mutex::new_with_condvars(0);
m.lock_cond(|cond| { cond.broadcast(); }) m.lock_cond(|cond| { cond.broadcast(); })
}; });
assert!(result.is_err()); assert!(result.is_err());
} }
/************************************************************************ /************************************************************************
@@ -1141,12 +1140,12 @@ mod tests {
let mut sharedstate = ~0; let mut sharedstate = ~0;
{ {
let ptr: *int = &*sharedstate; let ptr: *int = &*sharedstate;
do task::spawn { task::spawn(proc() {
let sharedstate: &mut int = let sharedstate: &mut int =
unsafe { cast::transmute(ptr) }; unsafe { cast::transmute(ptr) };
access_shared(sharedstate, &x2, mode1, 10); access_shared(sharedstate, &x2, mode1, 10);
c.send(()); c.send(());
} });
} }
{ {
access_shared(sharedstate, x, mode2, 10); access_shared(sharedstate, x, mode2, 10);
@@ -1189,7 +1188,7 @@ mod tests {
let x2 = x.clone(); let x2 = x.clone();
let (p1, c1) = Chan::new(); let (p1, c1) = Chan::new();
let (p2, c2) = Chan::new(); let (p2, c2) = Chan::new();
do task::spawn { task::spawn(proc() {
if !make_mode2_go_first { if !make_mode2_go_first {
let _ = p2.recv(); // parent sends to us once it locks, or ... let _ = p2.recv(); // parent sends to us once it locks, or ...
} }
@@ -1200,7 +1199,7 @@ mod tests {
let _ = p2.recv(); let _ = p2.recv();
c1.send(()); c1.send(());
}) })
} });
if make_mode2_go_first { if make_mode2_go_first {
let _ = p1.recv(); // child sends to us once it locks, or ... let _ = p1.recv(); // child sends to us once it locks, or ...
} }
@@ -1244,24 +1243,24 @@ mod tests {
// Child wakes up parent // Child wakes up parent
x.write_cond(|cond| { x.write_cond(|cond| {
let x2 = x.clone(); let x2 = x.clone();
do task::spawn { task::spawn(proc() {
x2.write_cond(|cond| { x2.write_cond(|cond| {
let woken = cond.signal(); let woken = cond.signal();
assert!(woken); assert!(woken);
}) })
} });
cond.wait(); cond.wait();
}); });
// Parent wakes up child // Parent wakes up child
let (port, chan) = Chan::new(); let (port, chan) = Chan::new();
let x3 = x.clone(); let x3 = x.clone();
do task::spawn { task::spawn(proc() {
x3.write_cond(|cond| { x3.write_cond(|cond| {
chan.send(()); chan.send(());
cond.wait(); cond.wait();
chan.send(()); chan.send(());
}) })
} });
let _ = port.recv(); // Wait until child gets in the rwlock let _ = port.recv(); // Wait until child gets in the rwlock
x.read(|| { }); // Must be able to get in as a reader in the meantime x.read(|| { }); // Must be able to get in as a reader in the meantime
x.write_cond(|cond| { // Or as another writer x.write_cond(|cond| { // Or as another writer
@@ -1292,13 +1291,13 @@ mod tests {
let xi = x.clone(); let xi = x.clone();
let (port, chan) = Chan::new(); let (port, chan) = Chan::new();
ports.push(port); ports.push(port);
do task::spawn { task::spawn(proc() {
lock_cond(&xi, dg1, |cond| { lock_cond(&xi, dg1, |cond| {
chan.send(()); chan.send(());
cond.wait(); cond.wait();
chan.send(()); chan.send(());
}) })
} });
}); });
// wait until all children get in the mutex // wait until all children get in the mutex
@@ -1327,11 +1326,11 @@ mod tests {
let x = RWLock::new(); let x = RWLock::new();
let x2 = x.clone(); let x2 = x.clone();
let result: result::Result<(), ~Any> = do task::try || { let result: result::Result<(), ~Any> = task::try(proc() {
lock_rwlock_in_mode(&x2, mode1, || { lock_rwlock_in_mode(&x2, mode1, || {
fail!(); fail!();
}) })
}; });
assert!(result.is_err()); assert!(result.is_err());
// child task must have finished by the time try returns // child task must have finished by the time try returns
lock_rwlock_in_mode(&x, mode2, || { }) lock_rwlock_in_mode(&x, mode2, || { })
@@ -1392,10 +1391,10 @@ mod tests {
9.times(|| { 9.times(|| {
let c = barrier.clone(); let c = barrier.clone();
let chan = chan.clone(); let chan = chan.clone();
do spawn { spawn(proc() {
c.wait(); c.wait();
chan.send(true); chan.send(true);
} });
}); });
// At this point, all spawned tasks should be blocked, // At this point, all spawned tasks should be blocked,

View File

@@ -873,7 +873,7 @@ pub fn run_test(force_ignore: bool,
fn run_test_inner(desc: TestDesc, fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>, monitor_ch: SharedChan<MonitorMsg>,
testfn: proc()) { testfn: proc()) {
do spawn { spawn(proc() {
let mut task = task::task(); let mut task = task::task();
task.name(match desc.name { task.name(match desc.name {
DynTestName(ref name) => SendStrOwned(name.clone()), DynTestName(ref name) => SendStrOwned(name.clone()),
@@ -885,7 +885,7 @@ pub fn run_test(force_ignore: bool,
let task_result = result_future.recv(); let task_result = result_future.recv();
let test_result = calc_result(&desc, task_result.is_ok()); let test_result = calc_result(&desc, task_result.is_ok());
monitor_ch.send((desc.clone(), test_result)); monitor_ch.send((desc.clone(), test_result));
} });
} }
match testfn { match testfn {

View File

@@ -414,14 +414,14 @@ impl<'a> Prep<'a> {
let blk = bo.take_unwrap(); let blk = bo.take_unwrap();
// FIXME: What happens if the task fails? // FIXME: What happens if the task fails?
do spawn { spawn(proc() {
let mut exe = Exec { let mut exe = Exec {
discovered_inputs: WorkMap::new(), discovered_inputs: WorkMap::new(),
discovered_outputs: WorkMap::new(), discovered_outputs: WorkMap::new(),
}; };
let v = blk(&mut exe); let v = blk(&mut exe);
chan.send((exe, v)); chan.send((exe, v));
} });
Work::from_task(self, port) Work::from_task(self, port)
} }
} }
@@ -495,7 +495,7 @@ fn test() {
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
prep.declare_input("file", pth.as_str().unwrap(), file_content); prep.declare_input("file", pth.as_str().unwrap(), file_content);
do prep.exec |_exe| { prep.exec(proc(_exe) {
let out = make_path(~"foo.o"); let out = make_path(~"foo.o");
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
run::process_status("gcc", [pth.as_str().unwrap().to_owned(), run::process_status("gcc", [pth.as_str().unwrap().to_owned(),
@@ -507,7 +507,7 @@ fn test() {
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
out.as_str().unwrap().to_owned() out.as_str().unwrap().to_owned()
} })
}); });
println!("{}", s); println!("{}", s);