diff --git a/doc/tutorial.md b/doc/tutorial.md index d9b55ba4d9565..cdd4da3c93cf0 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1875,7 +1875,7 @@ unless they contain managed boxes, managed closures, or borrowed pointers. * `Freeze` - Constant (immutable) types. These are types that do not contain anything intrinsically mutable. Intrinsically mutable values include `@mut` -and `Cell` in the standard library. +and `Mut` in the standard library. * `'static` - Non-borrowed types. These are types that do not contain any data whose lifetime is bound to diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 270b1097c554b..7047b061a52ca 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -15,6 +15,7 @@ extern mod extra; +use std::mutable::Mut; use std::os; use std::rt; @@ -317,15 +318,15 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { } pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { - use std::cell::Cell; - let config = Cell::new((*config).clone()); - let testfile = Cell::new(testfile.to_str()); - test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) + let config = Mut::new_some((*config).clone()); + let testfile = Mut::new_some(testfile.to_str()); + test::DynTestFn(|| { runtest::run(config.take_unwrap(), testfile.take_unwrap()) }) } pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn { - use std::cell::Cell; - let config = Cell::new((*config).clone()); - let testfile = Cell::new(testfile.to_str()); - test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) }) + let config = Mut::new_some((*config).clone()); + let testfile = Mut::new_some(testfile.to_str()); + do test::DynMetricFn |mm| { + runtest::run_metrics(config.take_unwrap(), testfile.take_unwrap(), mm) + } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 6e2f62f870695..dee70564a8937 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -20,8 +20,9 @@ use procsrv; use util; use util::logv; -use std::cell::Cell; + use std::io; +use std::mutable::Mut; use std::os; use std::str; use std::task::{spawn_sched, SingleThreaded}; @@ -31,8 +32,8 @@ use std::unstable::running_on_valgrind; use extra::test::MetricMap; pub fn run(config: config, testfile: ~str) { - let config = Cell::new(config); - let testfile = Cell::new(testfile); + let config = Mut::new_some(config); + let testfile = Mut::new_some(testfile); // FIXME #6436: Creating another thread to run the test because this // is going to call waitpid. The new scheduler has some strange // interaction between the blocking tasks and 'friend' schedulers @@ -43,14 +44,14 @@ pub fn run(config: config, testfile: ~str) { // We do _not_ create another thread if we're running on V because // it serializes all threads anyways. if running_on_valgrind() { - let config = config.take(); - let testfile = testfile.take(); + let config = config.take_unwrap(); + let testfile = testfile.take_unwrap(); let mut _mm = MetricMap::new(); run_metrics(config, testfile, &mut _mm); } else { do spawn_sched(SingleThreaded) { - let config = config.take(); - let testfile = testfile.take(); + let config = config.take_unwrap(); + let testfile = testfile.take_unwrap(); let mut _mm = MetricMap::new(); run_metrics(config, testfile, &mut _mm); } diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index ca8000c984d4a..dde2cdbbd796f 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -593,12 +593,11 @@ impl<'self, T:Freeze + Send> RWReadMode<'self, T> { #[cfg(test)] mod tests { - use arc::*; - use std::cell::Cell; use std::comm; use std::task; + use std::mutable::Mut; #[test] fn manually_share_arc() { @@ -627,10 +626,10 @@ mod tests { let arc = ~MutexArc::new(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); - let (c,p) = (Cell::new(c), Cell::new(p)); + let (c,p) = (Mut::new_some(c), Mut::new_some(p)); do task::spawn || { // wait until parent gets in - p.take().recv(); + p.take_unwrap().recv(); do arc2.access_cond |state, cond| { *state = true; cond.signal(); @@ -638,7 +637,7 @@ mod tests { } do arc.access_cond |state, cond| { - c.take().send(()); + c.take_unwrap().send(()); assert!(!*state); while !*state { cond.wait(); diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index d102f6068f561..2736fcc542977 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -641,6 +641,7 @@ mod test { use io_util::BufReader; use std::io::BytesWriter; + use std::mutable::Mut; use std::task; #[test] @@ -768,7 +769,6 @@ mod test { writer_chan: WriterChanFactory, port: uint) { - use std::cell::Cell; use std::comm; use std::result; use net::ip; @@ -785,15 +785,15 @@ mod test { let addr0 = ip::v4::parse_addr("127.0.0.1"); - let begin_connect_chan = Cell::new(begin_connect_chan); - let accept_chan = Cell::new(accept_chan); + let begin_connect_chan = Mut::new_some(begin_connect_chan); + let accept_chan = Mut::new_some(accept_chan); // The server task let addr = addr0.clone(); do task::spawn || { let iotask = &uv::global_loop::get(); - let begin_connect_chan = begin_connect_chan.take(); - let accept_chan = accept_chan.take(); + let begin_connect_chan = begin_connect_chan.take_unwrap(); + let accept_chan = accept_chan.take_unwrap(); let listen_res = do tcp::listen( addr.clone(), port, 128, iotask, |_kill_ch| { // Tell the sender to initiate the connection diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 74a551c6f6d56..d09d8e33ccd15 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -27,8 +27,9 @@ use std::cast; -use std::cell::Cell; + use std::comm::{PortOne, oneshot}; +use std::mutable::Mut; use std::task; use std::util::replace; @@ -121,9 +122,9 @@ pub fn from_port(port: PortOne) -> Future { * waiting for the result to be received on the port. */ - let port = Cell::new(port); + let port = Mut::new_some(port); do from_fn { - port.take().recv() + port.take_unwrap().recv() } } @@ -149,9 +150,9 @@ pub fn spawn(blk: ~fn() -> A) -> Future { let (port, chan) = oneshot(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do task::spawn { - let chan = chan.take(); + let chan = chan.take_unwrap(); chan.send(blk()); } @@ -162,8 +163,8 @@ pub fn spawn(blk: ~fn() -> A) -> Future { mod test { use future::*; - use std::cell::Cell; use std::comm::oneshot; + use std::mutable::Mut; use std::task; #[test] @@ -220,9 +221,9 @@ mod test { #[test] fn test_sendable_future() { let expected = "schlorf"; - let f = Cell::new(do spawn { expected }); + let f = Mut::new_some(do spawn { expected }); do task::spawn { - let mut f = f.take(); + let mut f = f.take_unwrap(); let actual = f.get(); assert_eq!(actual, expected); } diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index fa7cd9025eb7c..a68beb1dfff7b 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -12,17 +12,20 @@ /** Task-local reference counted smart pointers -Task-local reference counted smart pointers are an alternative to managed boxes with deterministic -destruction. They are restricted to containing types that are either `Send` or `Freeze` (or both) to -prevent cycles. +Task-local reference counted smart pointers are an alternative to managed boxes +with deterministic destruction. They are restricted to containing types that +are either `Send` or `Freeze` (or both) to prevent cycles. -Neither `Rc` or `RcMut` is ever `Send` and `RcMut` is never `Freeze`. If `T` is `Freeze`, a +Neither `Rc` is never `Send` and `Mut` is never `Freeze`. If `T` is `Freeze`, a cycle cannot be created with `Rc` because there is no way to modify it after creation. +`Rc>` requires `U` to be `Send` so that no cycles are created. + */ use std::cast; +use std::mutable::Mut; use std::ptr; use std::unstable::intrinsics; @@ -56,6 +59,10 @@ impl Rc { pub fn from_send(value: T) -> Rc { unsafe { Rc::new(value) } } + + pub fn from_send_mut(value: T) -> Rc> { + unsafe { Rc::new(Mut::new(value)) } + } } impl Rc { @@ -107,26 +114,25 @@ impl DeepClone for Rc { #[cfg(test)] mod test_rc { use super::*; - use std::cell::Cell; #[test] fn test_clone() { - let x = Rc::from_send(Cell::new(5)); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.borrow().with_mut_ref |inner| { + do x.borrow().map_mut |inner| { *inner = 20; } - assert_eq!(y.borrow().take(), 20); + assert_eq!(y.borrow().map(|t| *t), 20); } #[test] fn test_deep_clone() { - let x = Rc::from_send(Cell::new(5)); + let x = Rc::from_send_mut(5); let y = x.deep_clone(); - do x.borrow().with_mut_ref |inner| { + do x.borrow().map_mut |inner| { *inner = 20; } - assert_eq!(y.borrow().take(), 5); + assert_eq!(y.borrow().map(|t| *t), 5); } #[test] @@ -150,146 +156,44 @@ mod test_rc { } } -#[deriving(Eq)] -enum Borrow { - Mutable, - Immutable, - Nothing -} - -struct RcMutBox { - value: T, - count: uint, - borrow: Borrow -} - -/// Mutable reference counted pointer type -#[no_send] -#[no_freeze] -#[unsafe_no_drop_flag] -pub struct RcMut { - priv ptr: *mut RcMutBox, -} - -impl RcMut { - unsafe fn new(value: T) -> RcMut { - RcMut{ptr: owned_to_raw(~RcMutBox{value: value, count: 1, borrow: Nothing})} - } -} - -impl RcMut { - pub fn from_send(value: T) -> RcMut { - unsafe { RcMut::new(value) } - } -} - -impl RcMut { - pub fn from_freeze(value: T) -> RcMut { - unsafe { RcMut::new(value) } - } -} - -impl RcMut { - /// Fails if there is already a mutable borrow of the box - #[inline] - pub fn with_borrow(&self, f: &fn(&T) -> U) -> U { - unsafe { - assert!((*self.ptr).borrow != Mutable); - let previous = (*self.ptr).borrow; - (*self.ptr).borrow = Immutable; - let res = f(&(*self.ptr).value); - (*self.ptr).borrow = previous; - res - } - } - - /// Fails if there is already a mutable or immutable borrow of the box - #[inline] - pub fn with_mut_borrow(&self, f: &fn(&mut T) -> U) -> U { - unsafe { - assert_eq!((*self.ptr).borrow, Nothing); - (*self.ptr).borrow = Mutable; - let res = f(&mut (*self.ptr).value); - (*self.ptr).borrow = Nothing; - res - } - } -} - -#[unsafe_destructor] -impl Drop for RcMut { - fn drop(&mut self) { - unsafe { - if self.ptr.is_not_null() { - (*self.ptr).count -= 1; - if (*self.ptr).count == 0 { - let _: ~T = cast::transmute(self.ptr); - } - } - } - } -} - -impl Clone for RcMut { - /// Return a shallow copy of the reference counted pointer. - #[inline] - fn clone(&self) -> RcMut { - unsafe { - (*self.ptr).count += 1; - RcMut{ptr: self.ptr} - } - } -} - -impl DeepClone for RcMut { - /// Return a deep copy of the reference counted pointer. - #[inline] - fn deep_clone(&self) -> RcMut { - do self.with_borrow |x| { - // FIXME: #6497: should avoid freeze (slow) - unsafe { RcMut::new(x.deep_clone()) } - } - } -} - #[cfg(test)] mod test_rc_mut { use super::*; #[test] fn test_clone() { - let x = RcMut::from_send(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_mut_borrow |value| { + do x.borrow().map_mut |value| { *value = 20; } - do y.with_borrow |value| { + do y.borrow().map_mut |value| { assert_eq!(*value, 20); } } #[test] fn test_deep_clone() { - let x = RcMut::from_freeze(5); + let x = Rc::from_send_mut(5); let y = x.deep_clone(); - do x.with_mut_borrow |value| { + do x.borrow().map_mut |value| { *value = 20; } - do y.with_borrow |value| { + do y.borrow().map |value| { assert_eq!(*value, 5); } } #[test] fn borrow_many() { - let x = RcMut::from_send(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_borrow |a| { + do x.borrow().map |a| { assert_eq!(*a, 5); - do y.with_borrow |b| { + do y.borrow().map |b| { assert_eq!(*b, 5); - do x.with_borrow |c| { + do x.borrow().map |c| { assert_eq!(*c, 5); } } @@ -298,41 +202,41 @@ mod test_rc_mut { #[test] fn modify() { - let x = RcMut::from_freeze(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do y.with_mut_borrow |a| { + do y.borrow().map_mut |a| { assert_eq!(*a, 5); *a = 6; } - do x.with_borrow |a| { + do x.borrow().map |a| { assert_eq!(*a, 6); } } #[test] fn release_immutable() { - let x = RcMut::from_send(5); - do x.with_borrow |_| {} - do x.with_mut_borrow |_| {} + let x = Rc::from_send_mut(5); + do x.borrow().map |_| {} + do x.borrow().map_mut |_| {} } #[test] fn release_mutable() { - let x = RcMut::from_freeze(5); - do x.with_mut_borrow |_| {} - do x.with_borrow |_| {} + let x = Rc::from_send_mut(5); + do x.borrow().map_mut |_| {} + do x.borrow().map |_| {} } #[test] #[should_fail] fn frozen() { - let x = RcMut::from_send(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_borrow |_| { - do y.with_mut_borrow |_| { + do x.borrow().map |_| { + do y.borrow().map_mut |_| { } } } @@ -340,11 +244,11 @@ mod test_rc_mut { #[test] #[should_fail] fn mutable_dupe() { - let x = RcMut::from_freeze(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_mut_borrow |_| { - do y.with_mut_borrow |_| { + do x.borrow().map_mut |_| { + do y.borrow().map_mut |_| { } } } @@ -352,11 +256,11 @@ mod test_rc_mut { #[test] #[should_fail] fn mutable_freeze() { - let x = RcMut::from_send(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_mut_borrow |_| { - do y.with_borrow |_| { + do x.borrow().map_mut |_| { + do y.borrow().map |_| { } } } @@ -364,12 +268,12 @@ mod test_rc_mut { #[test] #[should_fail] fn restore_freeze() { - let x = RcMut::from_freeze(5); + let x = Rc::from_send_mut(5); let y = x.clone(); - do x.with_borrow |_| { - do x.with_borrow |_| {} - do y.with_mut_borrow |_| {} + do x.borrow().map |_| { + do x.borrow().map |_| {} + do y.borrow().map_mut |_| {} } } } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 99235e3029cc4..00b283fc85fc1 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -694,8 +694,8 @@ mod tests { use sync::*; use std::cast; - use std::cell::Cell; use std::comm; + use std::mutable::Mut; use std::result; use std::task; @@ -780,9 +780,9 @@ mod tests { let s = Semaphore::new(1); let s2 = s.clone(); let (p, c) = comm::stream(); - let child_data = Cell::new((s2, c)); + let child_data = Mut::new_some((s2, c)); do s.access { - let (s2, c) = child_data.take(); + let (s2, c) = child_data.take_unwrap(); do task::spawn { c.send(()); do s2.access { } @@ -965,13 +965,13 @@ mod tests { let mut sibling_convos = ~[]; do 2.times { let (p, c) = comm::stream(); - let c = Cell::new(c); + let c = Mut::new_some(c); sibling_convos.push(p); let mi = m2.clone(); // spawn sibling task do task::spawn { // linked do mi.lock_cond |cond| { - let c = c.take(); + let c = c.take_unwrap(); c.send(()); // tell sibling to go ahead do (|| { cond.wait(); // block forever diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 4dcb48d27516e..a8ed1df727e3a 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -32,6 +32,7 @@ use std::clone::Clone; use std::comm::{stream, SharedChan, GenericPort, GenericChan}; use std::libc; use std::io; +use std::mutable::Mut; use std::result; use std::task; use std::to_str::ToStr; @@ -826,14 +827,14 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, testfn: ~fn()) { - let testfn_cell = ::std::cell::Cell::new(testfn); + let testfn_cell = Mut::new_some(testfn); do task::spawn { let mut result_future = None; // task::future_result(builder); let mut task = task::task(); task.unlinked(); task.future_result(|r| { result_future = Some(r) }); - task.spawn(testfn_cell.take()); + task.spawn(testfn_cell.take_unwrap()); let task_result = result_future.unwrap().recv(); let test_result = calc_result(&desc, diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 24ab8360e8fab..769a5d1bd023d 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -17,9 +17,10 @@ use sha1::Sha1; use serialize::{Encoder, Encodable, Decoder, Decodable}; use arc::{Arc,RWArc}; use treemap::TreeMap; -use std::cell::Cell; + use std::comm::{PortOne, oneshot}; use std::{io, os, task}; +use std::mutable::Mut; /** * @@ -439,7 +440,7 @@ impl<'self> Prep<'self> { debug!("Cache miss!"); let (port, chan) = oneshot(); let blk = bo.take_unwrap(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); // What happens if the task fails? do task::spawn { @@ -447,7 +448,7 @@ impl<'self> Prep<'self> { discovered_inputs: WorkMap::new(), discovered_outputs: WorkMap::new(), }; - let chan = chan.take(); + let chan = chan.take_unwrap(); let v = blk(&mut exe); chan.send((exe, v)); } diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index c14e49f37e5bf..319462b75b3c9 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -23,8 +23,8 @@ use middle::graph::{Direction, NodeIndex}; use util::common::indenter; use util::ppaux::{Repr}; -use std::cell::Cell; use std::hashmap::{HashMap, HashSet}; +use std::mutable::Mut; use std::uint; use std::vec; use syntax::ast; @@ -107,14 +107,14 @@ pub struct RegionVarBindings { // This contains the results of inference. It begins as an empty // cell and only acquires a value after inference is complete. // We use a cell vs a mutable option to circumvent borrowck errors. - values: Cell<~[VarValue]>, + values: Mut>, } pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings { RegionVarBindings { tcx: tcx, var_origins: ~[], - values: Cell::new_empty(), + values: Mut::new(None), constraints: HashMap::new(), lubs: HashMap::new(), glbs: HashMap::new(), @@ -212,11 +212,16 @@ impl RegionVarBindings { re_bound(br_fresh(sc)) } + fn did_resolve(&self) -> bool { + let rvalues = self.values.borrow(); + rvalues.get().is_some() + } + pub fn add_constraint(&mut self, constraint: Constraint, origin: SubregionOrigin) { // cannot add constraints once regions are resolved - assert!(self.values.is_empty()); + assert!(!self.did_resolve()); debug!("RegionVarBindings: add_constraint(%?)", constraint); @@ -232,7 +237,7 @@ impl RegionVarBindings { sub: Region, sup: Region) { // cannot add constraints once regions are resolved - assert!(self.values.is_empty()); + assert!(!self.did_resolve()); debug!("RegionVarBindings: make_subregion(%?, %?)", sub, sup); match (sub, sup) { @@ -267,7 +272,7 @@ impl RegionVarBindings { b: Region) -> Region { // cannot add constraints once regions are resolved - assert!(self.values.is_empty()); + assert!(!self.did_resolve()); debug!("RegionVarBindings: lub_regions(%?, %?)", a, b); match (a, b) { @@ -290,7 +295,7 @@ impl RegionVarBindings { b: Region) -> Region { // cannot add constraints once regions are resolved - assert!(self.values.is_empty()); + assert!(!self.did_resolve()); debug!("RegionVarBindings: glb_regions(%?, %?)", a, b); match (a, b) { @@ -309,14 +314,17 @@ impl RegionVarBindings { } pub fn resolve_var(&mut self, rid: RegionVid) -> ty::Region { - if self.values.is_empty() { - self.tcx.sess.span_bug( - self.var_origins[rid.to_uint()].span(), - fmt!("Attempt to resolve region variable before values have \ - been computed!")); - } + let rvalues = self.values.borrow(); + let v = match *rvalues.get() { + None => { + self.tcx.sess.span_bug( + self.var_origins[rid.to_uint()].span(), + fmt!("Attempt to resolve region variable before values have \ + been computed!")); + }, + Some(ref vals) => vals[rid.to_uint()] + }; - let v = self.values.with_ref(|values| values[rid.to_uint()]); debug!("RegionVarBindings: resolve_var(%?=%u)=%?", rid, rid.to_uint(), v); match v { @@ -472,7 +480,8 @@ impl RegionVarBindings { debug!("RegionVarBindings: resolve_regions()"); let mut errors = opt_vec::Empty; let v = self.infer_variable_values(&mut errors); - self.values.put_back(v); + let mut mvalues = self.values.borrow_mut(); + *mvalues.get() = Some(v); errors } } diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index b2b7599aae3a7..5a6e8f2f10f8e 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -20,7 +20,7 @@ non-sendableness. use parse; -use std::cell::Cell; + use std::comm::{stream, SharedChan, Port}; use std::task; use rustc::driver::driver; @@ -60,13 +60,13 @@ pub fn from_file(file: ~str, owner: SrvOwner) -> T { } fn run(owner: SrvOwner, source: ~str, parse: Parser) -> T { - + use std::mutable::Mut; let (po, ch) = stream(); - let source = Cell::new(source); - let parse = Cell::new(parse); + let source = Mut::new_some(source); + let parse = Mut::new_some(parse); do task::spawn { - act(&po, source.take().to_managed(), parse.take()); + act(&po, source.take_unwrap().to_managed(), parse.take_unwrap()); } let srv_ = Srv { diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ff6401456b6b9..6c087e3f7a06b 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -9,7 +9,8 @@ // except according to those terms. -use std::cell::Cell; + +use std::mutable::Mut; use std::os; use std::result::Result; use std::result; @@ -169,11 +170,11 @@ fn config_from_opts( } } }; - let process_output = Cell::new(process_output); + let process_output = Mut::new_some(process_output); let result = do result.and_then |config| { let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd()); let pandoc_cmd = maybe_find_pandoc( - &config, pandoc_cmd, process_output.take()); + &config, pandoc_cmd, process_output.take_unwrap()); do pandoc_cmd.and_then |pandoc_cmd| { result::Ok(Config { pandoc_cmd: pandoc_cmd, diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index 7d07b4864f50e..e9f545db94329 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -21,16 +21,17 @@ use markdown_writer::WriterFactory; use pass::Pass; use sort_pass; -use std::cell::Cell; + +use std::mutable::Mut; use std::str; use std::vec; use syntax; pub fn mk_pass(writer_factory: WriterFactory) -> Pass { - let writer_factory = Cell::new(writer_factory); + let writer_factory = Mut::new_some(writer_factory); Pass { name: ~"markdown", - f: |srv, doc| run(srv, doc, writer_factory.take()) + f: |srv, doc| run(srv, doc, writer_factory.take_unwrap()) } } diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index 41c0dcfb6d252..eb5f3a2ae3ebd 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -18,14 +18,14 @@ use fold::Fold; use fold; use pass::Pass; -use std::cell::Cell; +use std::mutable::Mut; pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { - let op = Cell::new(op); + let op = Mut::new_some(op); Pass { name: name.clone(), f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc { - run(srv, doc, op.take()) + run(srv, doc, op.take_unwrap()) } } } diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index 8d61a971157fc..66173f18e74b1 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -71,7 +71,7 @@ extern mod rustc; extern mod syntax; use std::{libc, io, os, task}; -use std::cell::Cell; + use extra::rl; use rustc::driver::{driver, session}; @@ -449,6 +449,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer, pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~str, use_rl: bool) -> bool { + use std::mutable::Mut; + if line.starts_with(":") { // drop the : and the \n (one byte each) let full = line.slice(1, line.len()); @@ -476,12 +478,15 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st } } - let line = Cell::new(line); - let program = Cell::new(repl.program.clone()); - let lib_search_paths = Cell::new(repl.lib_search_paths.clone()); - let binary = Cell::new(repl.binary.clone()); + let line = Mut::new_some(line); + let program = Mut::new_some(repl.program.clone()); + let lib_search_paths = Mut::new_some(repl.lib_search_paths.clone()); + let binary = Mut::new_some(repl.binary.clone()); let result = do task::try { - run(program.take(), binary.take(), lib_search_paths.take(), line.take()) + run(program.take_unwrap(), + binary.take_unwrap(), + lib_search_paths.take_unwrap(), + line.take_unwrap()) }; match result { diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs deleted file mode 100644 index a1459b780dfb3..0000000000000 --- a/src/libstd/cell.rs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A mutable, nullable memory location - -#[missing_doc]; - -use cast::transmute_mut; -use unstable::finally::Finally; -use prelude::*; - -/* -A dynamic, mutable location. - -Similar to a mutable option type, but friendlier. -*/ - -#[no_freeze] -#[deriving(Clone, DeepClone, Eq)] -#[allow(missing_doc)] -pub struct Cell { - priv value: Option -} - -impl Cell { - /// Creates a new full cell with the given value. - pub fn new(value: T) -> Cell { - Cell { value: Some(value) } - } - - /// Creates a new empty cell with no value inside. - pub fn new_empty() -> Cell { - Cell { value: None } - } - - /// Yields the value, failing if the cell is empty. - pub fn take(&self) -> T { - let this = unsafe { transmute_mut(self) }; - if this.is_empty() { - fail!("attempt to take an empty cell"); - } - - this.value.take_unwrap() - } - - /// Yields the value if the cell is full, or `None` if it is empty. - pub fn take_opt(&self) -> Option { - let this = unsafe { transmute_mut(self) }; - this.value.take() - } - - /// Returns the value, failing if the cell is full. - pub fn put_back(&self, value: T) { - let this = unsafe { transmute_mut(self) }; - if !this.is_empty() { - fail!("attempt to put a value back into a full cell"); - } - this.value = Some(value); - } - - /// Returns true if the cell is empty and false if the cell is full. - pub fn is_empty(&self) -> bool { - self.value.is_none() - } - - /// Calls a closure with a reference to the value. - pub fn with_ref(&self, op: &fn(v: &T) -> R) -> R { - do self.with_mut_ref |ptr| { op(ptr) } - } - - /// Calls a closure with a mutable reference to the value. - pub fn with_mut_ref(&self, op: &fn(v: &mut T) -> R) -> R { - let mut v = Some(self.take()); - do (|| { - op(v.get_mut_ref()) - }).finally { - self.put_back(v.take_unwrap()); - } - } -} - -#[test] -fn test_basic() { - let value_cell = Cell::new(~10); - assert!(!value_cell.is_empty()); - let value = value_cell.take(); - assert!(value == ~10); - assert!(value_cell.is_empty()); - value_cell.put_back(value); - assert!(!value_cell.is_empty()); -} - -#[test] -#[should_fail] -fn test_take_empty() { - let value_cell: Cell<~int> = Cell::new_empty(); - value_cell.take(); -} - -#[test] -#[should_fail] -fn test_put_back_non_empty() { - let value_cell = Cell::new(~10); - value_cell.put_back(~20); -} - -#[test] -fn test_with_ref() { - let good = 6; - let c = Cell::new(~[1, 2, 3, 4, 5, 6]); - let l = do c.with_ref() |v| { v.len() }; - assert_eq!(l, good); -} - -#[test] -fn test_with_mut_ref() { - let good = ~[1, 2, 3]; - let v = ~[1, 2]; - let c = Cell::new(v); - do c.with_mut_ref() |v| { v.push(3); } - let v = c.take(); - assert_eq!(v, good); -} diff --git a/src/libstd/mutable.rs b/src/libstd/mutable.rs new file mode 100644 index 0000000000000..cfd6f39c9b31e --- /dev/null +++ b/src/libstd/mutable.rs @@ -0,0 +1,314 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! A mutable memory location with dynamically checked borrow rules. + +use cast; +use cmp::Eq; +use util; + +use ops::Drop; +use clone::{Clone, DeepClone}; +use option::{Option, Some}; + +/// A mutable slot with dynamically checked borrow rules. +#[no_freeze] +pub struct Mut { + priv value: T, + priv flag: BorrowFlag, + priv nc: util::NonCopyable, +} + +// Values [1, MAX-1] represent the number of `ReaderPtr` active +// (will not outgrow its range since `uint` is the size of the address space) +type BorrowFlag = uint; +static Unused: BorrowFlag = 0; +static Writing: BorrowFlag = -1; + +impl Mut { + /// Create a new `Mut` containing `value` + #[inline] + pub fn new(value: T) -> Mut { + Mut{value: value, flag: Unused, nc: util::NonCopyable} + } + + unsafe fn as_mut<'a>(&'a self) -> &'a mut Mut { + cast::transmute_mut(self) + } + + /// Consume the Mut and extract the held value + pub fn unwrap(self) -> T { + match self.flag { + Unused => self.value, + // debug assert? This case should be statically prevented + // by regular &'a self borrowing and noncopyability. + _ => fail!("borrow inconsistency in Mut"), + } + } + + /// Borrow the Mut for immutable access through a wrapped pointer + /// + /// The borrow lasts until the returned `ReadPtr` expires its scope. + /// Multiple simultaneous immutable borrows are possible. + /// + /// Fails if the slot is already borrowed mutably. + #[inline] + pub fn borrow<'a>(&'a self) -> ReadPtr<'a, T> { + unsafe { + let mut_self = self.as_mut(); + mut_self.flag = match mut_self.flag { + Writing => fail!("borrow: Mut reserved by borrow_mut"), + Unused => 1, + n => n + 1, + }; + } + ReadPtr{parent: self} + } + + /// Borrow the Mut for mutable access through a wrapped pointer. + /// + /// The borrow lasts until the returned `WritePtr` expires its scope. + /// `borrow_mut` is an exclusive borrow. + /// + /// Fails if the slot has any outstanding borrow. + #[inline] + pub fn borrow_mut<'a>(&'a self) -> WritePtr<'a, T> { + unsafe { + let mut_self = self.as_mut(); + mut_self.flag = match mut_self.flag { + Unused => Writing, + _ => fail!("borrow_mut: Mut already in use"), + }; + WritePtr{parent: mut_self} + } + } + + /// Borrow the Mut and apply `f` + #[inline] + pub fn map(&self, f: &fn(&T) -> U) -> U { + let r_ptr = self.borrow(); + f(r_ptr.get()) + } + + /// Borrow the Mut mutably and apply `f` + #[inline] + pub fn map_mut(&self, f: &fn(&mut T) -> U) -> U { + let mut m_ptr = self.borrow_mut(); + f(m_ptr.get()) + } +} + +impl Mut> { + /// Create a Mut holding `Some(value)` + #[inline] + pub fn new_some(value: U) -> Mut> { + Mut::new(Some(value)) + } + + /// Borrow the Mut mutably, replace the held value with None, + /// and return the held Option value. + /// + /// Fails if the Mut could not be borrowed mutably. + #[inline] + pub fn take(&self) -> Option { + // specialize for performance + unsafe { + match self.flag { + Unused => self.as_mut().value.take(), + _ => fail!("Mut::take: Mut already in use"), + } + } + } + + /// Borrow the Mut mutably, replace the held value with None, + /// and return the unwrapped Option value. + /// + /// Fails if the Mut could not be borrowed mutably, + /// or if the held value is `None`. + #[inline] + pub fn take_unwrap(&self) -> U { + self.take().expect("Mut::take_unwrap: attempt to unwrap empty Mut") + } + + /// Replace the held value with `Some(value)` + /// + /// Fails if the Mut could not be borrowed mutably, + /// or if the held value is not `None`. + #[inline] + pub fn put_back(&self, value: U) { + let mut mptr = self.borrow_mut(); + if !mptr.get().is_none() { + fail!("Mut::put_back: already holding Some value") + } + *mptr.get() = Some(value); + } +} + +/// A borrowed pointer that holds its borrow +/// until it expires its scope. +pub struct ReadPtr<'self, T> { + priv parent: &'self Mut +} + +impl<'self, T> ReadPtr<'self, T> { + /// Resolve the `ReadPtr` to a borrowed pointer + #[inline] + pub fn get<'a>(&'a self) -> &'a T { + &self.parent.value + } +} + +#[unsafe_destructor] +impl<'self, T> Drop for ReadPtr<'self, T> { + fn drop(&mut self) { + unsafe { + let mut_par = self.parent.as_mut(); + match mut_par.flag { + // XXX: should be debug assert? + Writing | Unused => error!("ReadPtr::drop: borrow inconsistency in Mut"), + n => mut_par.flag = n - 1, + } + } + } +} + +/// A mutable borrowed pointer that holds its borrow +/// until it expires its scope. +pub struct WritePtr<'self, T> { + priv parent: &'self mut Mut +} + +impl<'self, T> WritePtr<'self, T> { + /// Resolve the `ReadPtr` to a mutable borrowed pointer + #[inline] + pub fn get<'a>(&'a mut self) -> &'a mut T { + &mut self.parent.value + } +} + +#[unsafe_destructor] +impl<'self, T> Drop for WritePtr<'self, T> { + fn drop(&mut self) { + unsafe { + let mut_par = self.parent.as_mut(); + match mut_par.flag { + Writing => mut_par.flag = Unused, + // XXX: should debug assert? + _ => error!("WritePtr::drop: borrow inconsistency in Mut") + } + } + } +} + +impl Clone for Mut { + fn clone(&self) -> Mut { + let rptr = self.borrow(); + Mut::new(rptr.get().clone()) + } +} + +impl DeepClone for Mut { + fn deep_clone(&self) -> Mut { + let rptr = self.borrow(); + Mut::new(rptr.get().deep_clone()) + } +} + +impl Eq for Mut { + fn eq(&self, other: &Mut) -> bool { + let rptr = self.borrow(); + let optr = other.borrow(); + rptr.get() == optr.get() + } +} + + +#[cfg(test)] +pub fn test_read_then_read_x() { + use util::ignore; + + let obj = Mut::new(1); + let r = obj.borrow(); + let q = obj.borrow(); + assert_eq!(r.get(), q.get()); + + match obj.flag { 2 => (), _ => fail!() } + ignore(r); + match obj.flag { 1 => (), _ => fail!() } + ignore(q); + match obj.flag { Unused => (), _ => fail!() } +} + + +#[cfg(test)] +mod tests { + use super::*; + use option::{Some, None}; + use util::ignore; + + #[test] + fn test_read_then_read() { + test_read_then_read_x() + } + + #[test] + #[should_fail] + fn test_read_release_partial_then_write() { + let obj = Mut::new(1); + let r = obj.borrow(); + let q = obj.borrow(); + assert_eq!(r.get(), q.get()); + ignore(r); + let _ = obj.borrow_mut(); + } + + #[test] + #[should_fail] + fn test_write_then_write() { + let obj = Mut::new(1); + let mptr = obj.borrow_mut(); + let nptr = obj.borrow_mut(); + ignore(mptr); + ignore(nptr); + } + + #[test] + fn test_read_release_then_write() { + let obj = Mut::new(1); + let r = obj.borrow(); + let q = obj.borrow(); + assert_eq!(r.get(), q.get()); + ignore(r); + ignore(q); + let mut m = obj.borrow_mut(); + *m.get() = 99; + ignore(m); + let r = obj.borrow(); + assert_eq!(*r.get(), 99); + } + + + #[test] + #[should_fail] + fn test_read_then_write() { + let obj = Mut::new(1); + let r = obj.borrow(); + let _ = obj.borrow_mut(); + ignore(r); + } + + #[test] + fn test_option_take() { + let obj = Mut::new(Some(3)); + let v = None::.unwrap_or_else(|| obj.take_unwrap()); + assert_eq!(v, 3); + assert!(obj.map(|x| x.is_none())); + } +} diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index 9dc0abdfbd88a..385f205128af0 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use cell::Cell; +use mutable::Mut; use c_str::ToCStr; use cast::transmute; use io::{Writer, WriterUtil}; @@ -49,9 +49,9 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) { None => ~[] }; let borrows = f(borrows); - let borrows = Cell::new(borrows); + let borrows = Mut::new_some(borrows); do Local::borrow |task: &mut Task| { - task.borrow_list = Some(borrows.take()); + task.borrow_list = Some(borrows.take_unwrap()); } } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index a8cd9bd66d7de..94646b0a4c014 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -24,7 +24,7 @@ use unstable::atomics::{AtomicUint, AtomicOption, Acquire, Relaxed, SeqCst}; use unstable::sync::UnsafeArc; use util::Void; use comm::{GenericChan, GenericSmartChan, GenericPort, Peekable}; -use cell::Cell; +use mutable::Mut; use clone::Clone; use tuple::ImmutableTuple; @@ -158,9 +158,9 @@ impl ChanOne { Scheduler::run_task(woken_task); }; } else { - let recvr = Cell::new(recvr); + let recvr = Mut::new_some(recvr); do Local::borrow |sched: &mut Scheduler| { - sched.enqueue_blocked_task(recvr.take()); + sched.enqueue_blocked_task(recvr.take_unwrap()); } } } @@ -433,26 +433,26 @@ type StreamPortOne = PortOne>; /// A channel with unbounded size. pub struct Chan { // FIXME #5372. Using Cell because we don't take &mut self - next: Cell> + next: Mut>> } /// An port with unbounded size. pub struct Port { // FIXME #5372. Using Cell because we don't take &mut self - next: Cell> + next: Mut>> } pub fn stream() -> (Port, Chan) { let (pone, cone) = oneshot(); - let port = Port { next: Cell::new(pone) }; - let chan = Chan { next: Cell::new(cone) }; + let port = Port { next: Mut::new_some(pone) }; + let chan = Chan { next: Mut::new_some(cone) }; return (port, chan); } impl Chan { fn try_send_inner(&self, val: T, do_resched: bool) -> bool { let (next_pone, next_cone) = oneshot(); - let cone = self.next.take(); + let cone = self.next.take_unwrap(); self.next.put_back(next_cone); cone.try_send_inner(StreamPayload { val: val, next: next_pone }, do_resched) } @@ -490,10 +490,11 @@ impl GenericPort for Port { } fn try_recv(&self) -> Option { - do self.next.take_opt().map_move_default(None) |pone| { + let mut mnext = self.next.borrow_mut(); + do mnext.get().take().map_move_default(None) |pone| { match pone.try_recv() { Some(StreamPayload { val, next }) => { - self.next.put_back(next); + *mnext.get() = Some(next); Some(val) } None => None @@ -504,7 +505,8 @@ impl GenericPort for Port { impl Peekable for Port { fn peek(&self) -> bool { - self.next.with_mut_ref(|p| p.peek()) + let mut mnext = self.next.borrow_mut(); + mnext.get().get_mut_ref().peek() } } @@ -515,18 +517,20 @@ impl Peekable for Port { impl<'self, T> SelectInner for &'self Port { #[inline] fn optimistic_check(&mut self) -> bool { - do self.next.with_mut_ref |pone| { pone.optimistic_check() } + let mut mnext = self.next.borrow_mut(); + mnext.get().get_mut_ref().optimistic_check() } #[inline] fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool { - let task = Cell::new(task); - do self.next.with_mut_ref |pone| { pone.block_on(sched, task.take()) } + let mut mnext = self.next.borrow_mut(); + mnext.get().get_mut_ref().block_on(sched, task) } #[inline] fn unblock_from(&mut self) -> bool { - do self.next.with_mut_ref |pone| { pone.unblock_from() } + let mut mnext = self.next.borrow_mut(); + mnext.get().get_mut_ref().unblock_from() } } @@ -553,7 +557,7 @@ impl Select for Port { } impl<'self, T> SelectPortInner for &'self Port { fn recv_ready(self) -> Option { - match self.next.take().recv_ready() { + match self.next.take_unwrap().recv_ready() { Some(StreamPayload { val, next }) => { self.next.put_back(next); Some(val) @@ -572,7 +576,7 @@ pub struct SharedChan { impl SharedChan { pub fn new(chan: Chan) -> SharedChan { - let next = chan.next.take(); + let next = chan.next.take_unwrap(); let next = AtomicOption::new(~next); SharedChan { next: UnsafeArc::new(next) } } @@ -626,7 +630,7 @@ pub struct SharedPort { impl SharedPort { pub fn new(port: Port) -> SharedPort { // Put the data port into a new link pipe - let next_data_port = port.next.take(); + let next_data_port = port.next.take_unwrap(); let (next_link_port, next_link_chan) = oneshot(); next_link_chan.send(next_data_port); let next_link = AtomicOption::new(~next_link_port); @@ -717,7 +721,7 @@ mod test { use super::*; use option::*; use rt::test::*; - use cell::Cell; + use mutable::Mut; use num::Times; use rt::util; @@ -841,9 +845,9 @@ mod test { fn oneshot_multi_task_recv_then_send() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell::new(port); + let port_cell = Mut::new_some(port); do spawntask { - assert!(port_cell.take().recv() == ~10); + assert!(port_cell.take_unwrap().recv() == ~10); } chan.send(~10); @@ -854,13 +858,13 @@ mod test { fn oneshot_multi_task_recv_then_close() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell::new(port); - let chan_cell = Cell::new(chan); + let port_cell = Mut::new_some(port); + let chan_cell = Mut::new_some(chan); do spawntask_later { - let _cell = chan_cell.take(); + let _cell = chan_cell.take_unwrap(); } let res = do spawntask_try { - assert!(port_cell.take().recv() == ~10); + assert!(port_cell.take_unwrap().recv() == ~10); }; assert!(res.is_err()); } @@ -872,9 +876,9 @@ mod test { do stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let port_cell = Cell::new(port); + let port_cell = Mut::new_some(port); let thread = do spawntask_thread { - let _p = port_cell.take(); + let _p = port_cell.take_unwrap(); }; let _chan = chan; thread.join(); @@ -888,13 +892,13 @@ mod test { do stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell::new(chan); - let port_cell = Cell::new(port); + let chan_cell = Mut::new_some(chan); + let port_cell = Mut::new_some(port); let thread1 = do spawntask_thread { - let _p = port_cell.take(); + let _p = port_cell.take_unwrap(); }; let thread2 = do spawntask_thread { - let c = chan_cell.take(); + let c = chan_cell.take_unwrap(); c.send(1); }; thread1.join(); @@ -909,19 +913,19 @@ mod test { do stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell::new(chan); - let port_cell = Cell::new(port); + let chan_cell = Mut::new_some(chan); + let port_cell = Mut::new_some(port); let thread1 = do spawntask_thread { - let port_cell = Cell::new(port_cell.take()); + let port_cell = Mut::new_some(port_cell.take_unwrap()); let res = do spawntask_try { - port_cell.take().recv(); + port_cell.take_unwrap().recv(); }; assert!(res.is_err()); }; let thread2 = do spawntask_thread { - let chan_cell = Cell::new(chan_cell.take()); + let chan_cell = Mut::new_some(chan_cell.take_unwrap()); do spawntask { - chan_cell.take(); + chan_cell.take_unwrap(); } }; thread1.join(); @@ -936,13 +940,13 @@ mod test { do stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let chan_cell = Cell::new(chan); - let port_cell = Cell::new(port); + let chan_cell = Mut::new_some(chan); + let port_cell = Mut::new_some(port); let thread1 = do spawntask_thread { - chan_cell.take().send(~10); + chan_cell.take_unwrap().send(~10); }; let thread2 = do spawntask_thread { - assert!(port_cell.take().recv() == ~10); + assert!(port_cell.take_unwrap().recv() == ~10); }; thread1.join(); thread2.join(); @@ -963,9 +967,9 @@ mod test { fn send(chan: Chan<~int>, i: int) { if i == 10 { return } - let chan_cell = Cell::new(chan); + let chan_cell = Mut::new_some(chan); do spawntask_random { - let chan = chan_cell.take(); + let chan = chan_cell.take_unwrap(); chan.send(~i); send(chan, i + 1); } @@ -974,9 +978,9 @@ mod test { fn recv(port: Port<~int>, i: int) { if i == 10 { return } - let port_cell = Cell::new(port); + let port_cell = Mut::new_some(port); do spawntask_random { - let port = port_cell.take(); + let port = port_cell.take_unwrap(); assert!(port.recv() == ~i); recv(port, i + 1); }; @@ -1139,19 +1143,19 @@ mod test { let cshared = SharedChan::new(cshared); let mp = megapipe(); - let pone = Cell::new(pone); - do spawntask { pone.take().recv(); } - let pstream = Cell::new(pstream); - do spawntask { pstream.take().recv(); } - let pshared = Cell::new(pshared); - do spawntask { pshared.take().recv(); } - let p_mp = Cell::new(mp.clone()); - do spawntask { p_mp.take().recv(); } + let pone = Mut::new_some(pone); + do spawntask { pone.take_unwrap().recv(); } + let pstream = Mut::new_some(pstream); + do spawntask { pstream.take_unwrap().recv(); } + let pshared = Mut::new_some(pshared); + do spawntask { pshared.take_unwrap().recv(); } + let p_mp = Mut::new_some(mp.clone()); + do spawntask { p_mp.take_unwrap().recv(); } - let cs = Cell::new((cone, cstream, cshared, mp)); + let cs = Mut::new_some((cone, cstream, cshared, mp)); unsafe { do atomically { - let (cone, cstream, cshared, mp) = cs.take(); + let (cone, cstream, cshared, mp) = cs.take_unwrap(); cone.send_deferred(()); cstream.send_deferred(()); cshared.send_deferred(()); diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index 1c48d6e7f1e13..bf047ac827bc0 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -639,7 +639,7 @@ fn extend_sign(val: u64, nbytes: uint) -> i64 { mod test { use super::ReaderUtil; use option::{Some, None}; - use cell::Cell; + use mutable::Mut; use rt::io::mem::{MemReader, MemWriter}; use rt::io::mock::MockReader; use rt::io::{read_error, placeholder_error}; @@ -654,16 +654,15 @@ mod test { #[test] fn read_byte_0_bytes() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - Some(0) - } else { - buf[0] = 10; - Some(1) - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + Some(0) + } else { + buf[0] = 10; + Some(1) } }; let byte = reader.read_byte(); @@ -695,16 +694,15 @@ mod test { #[test] fn bytes_0_bytes() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - Some(0) - } else { - buf[0] = 10; - Some(1) - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + Some(0) + } else { + buf[0] = 10; + Some(1) } }; let byte = reader.bytes().next(); @@ -744,19 +742,18 @@ mod test { #[test] fn read_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - buf[1] = 11; - Some(2) - } else { - buf[0] = 12; - buf[1] = 13; - Some(2) - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + buf[1] = 11; + Some(2) + } else { + buf[0] = 12; + buf[1] = 13; + Some(2) } }; let bytes = reader.read_bytes(4); @@ -783,19 +780,18 @@ mod test { #[test] fn push_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - buf[1] = 11; - Some(2) - } else { - buf[0] = 12; - buf[1] = 13; - Some(2) - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + buf[1] = 11; + Some(2) + } else { + buf[0] = 12; + buf[1] = 13; + Some(2) } }; let mut buf = ~[8, 9]; @@ -817,17 +813,16 @@ mod test { #[test] fn push_bytes_error() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - Some(1) - } else { - read_error::cond.raise(placeholder_error()); - None - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + Some(1) + } else { + read_error::cond.raise(placeholder_error()); + None } }; let mut buf = ~[8, 9]; @@ -843,17 +838,16 @@ mod test { // push_bytes unsafely sets the vector length. This is testing that // upon failure the length is reset correctly. let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - Some(1) - } else { - read_error::cond.raise(placeholder_error()); - None - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + Some(1) + } else { + read_error::cond.raise(placeholder_error()); + None } }; let buf = @mut ~[8, 9]; @@ -869,22 +863,21 @@ mod test { #[test] fn read_to_end() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - buf[1] = 11; - Some(2) - } else if *count == 1 { - *count = 2; - buf[0] = 12; - buf[1] = 13; - Some(2) - } else { - None - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + buf[1] = 11; + Some(2) + } else if *mcount.get() == 1 { + *mcount.get() = 2; + buf[0] = 12; + buf[1] = 13; + Some(2) + } else { + None } }; let buf = reader.read_to_end(); @@ -895,18 +888,17 @@ mod test { #[should_fail] fn read_to_end_error() { let mut reader = MockReader::new(); - let count = Cell::new(0); + let count = Mut::new(0); reader.read = |buf| { - do count.with_mut_ref |count| { - if *count == 0 { - *count = 1; - buf[0] = 10; - buf[1] = 11; - Some(2) - } else { - read_error::cond.raise(placeholder_error()); - None - } + let mut mcount = count.borrow_mut(); + if *mcount.get() == 0 { + *mcount.get() = 1; + buf[0] = 10; + buf[1] = 11; + Some(2) + } else { + read_error::cond.raise(placeholder_error()); + None } }; let buf = reader.read_to_end(); diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index 55abc4ab13586..6f40a4da9132c 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -154,7 +154,7 @@ impl Acceptor for TcpAcceptor { #[cfg(test)] mod test { use super::*; - use cell::Cell; + use mutable::Mut; use rt::test::*; use rt::io::net::ip::{Ipv4Addr, SocketAddr}; use rt::io::*; @@ -204,12 +204,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; stream.read(buf); @@ -217,7 +217,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let mut stream = TcpStream::connect(addr); stream.write([99]); } @@ -229,12 +229,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; stream.read(buf); @@ -242,7 +242,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let mut stream = TcpStream::connect(addr); stream.write([99]); } @@ -254,12 +254,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; let nread = stream.read(buf); @@ -267,7 +267,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -279,12 +279,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; let nread = stream.read(buf); @@ -292,7 +292,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -305,12 +305,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; let nread = stream.read(buf); @@ -320,7 +320,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -333,12 +333,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let mut buf = [0]; let nread = stream.read(buf); @@ -348,7 +348,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -361,12 +361,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let buf = [0]; loop { @@ -383,7 +383,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -396,12 +396,12 @@ mod test { do run_in_mt_newsched_task { let addr = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept(); let buf = [0]; loop { @@ -418,7 +418,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let _stream = TcpStream::connect(addr); // Close } @@ -431,12 +431,12 @@ mod test { let addr = next_test_ip4(); let max = 10; let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for ref mut stream in acceptor.incoming().take(max) { let mut buf = [0]; stream.read(buf); @@ -445,7 +445,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); do max.times { let mut stream = TcpStream::connect(addr); stream.write([99]); @@ -460,12 +460,12 @@ mod test { let addr = next_test_ip6(); let max = 10; let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for ref mut stream in acceptor.incoming().take(max) { let mut buf = [0]; stream.read(buf); @@ -474,7 +474,7 @@ mod test { } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); do max.times { let mut stream = TcpStream::connect(addr); stream.write([99]); @@ -489,16 +489,16 @@ mod test { let addr = next_test_ip4(); static MAX: int = 10; let (port, chan) = oneshot(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { - let stream = Cell::new(stream); + let stream = Mut::new_some(stream); // Start another task to handle the connection do spawntask { - let mut stream = stream.take(); + let mut stream = stream.take_unwrap(); let mut buf = [0]; stream.read(buf); assert!(buf[0] == i as u8); @@ -531,16 +531,16 @@ mod test { let addr = next_test_ip6(); static MAX: int = 10; let (port, chan) = oneshot(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { - let stream = Cell::new(stream); + let stream = Mut::new_some(stream); // Start another task to handle the connection do spawntask { - let mut stream = stream.take(); + let mut stream = stream.take_unwrap(); let mut buf = [0]; stream.read(buf); assert!(buf[0] == i as u8); @@ -573,16 +573,16 @@ mod test { let addr = next_test_ip4(); static MAX: int = 10; let (port, chan) = oneshot(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for stream in acceptor.incoming().take(MAX as uint) { - let stream = Cell::new(stream); + let stream = Mut::new_some(stream); // Start another task to handle the connection do spawntask_later { - let mut stream = stream.take(); + let mut stream = stream.take_unwrap(); let mut buf = [0]; stream.read(buf); assert!(buf[0] == 99); @@ -614,16 +614,16 @@ mod test { let addr = next_test_ip6(); static MAX: int = 10; let (port, chan) = oneshot(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); for stream in acceptor.incoming().take(MAX as uint) { - let stream = Cell::new(stream); + let stream = Mut::new_some(stream); // Start another task to handle the connection do spawntask_later { - let mut stream = stream.take(); + let mut stream = stream.take_unwrap(); let mut buf = [0]; stream.read(buf); assert!(buf[0] == 99); @@ -670,18 +670,18 @@ mod test { fn peer_name(addr: SocketAddr) { do run_in_mt_newsched_task { let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let mut acceptor = TcpListener::bind(addr).listen(); - chan.take().send(()); + chan.take_unwrap().send(()); acceptor.accept(); } do spawntask { - port.take().recv(); + port.take_unwrap().recv(); let stream = TcpStream::connect(addr); assert!(stream.is_some()); diff --git a/src/libstd/rt/io/net/udp.rs b/src/libstd/rt/io/net/udp.rs index a65c918351ad9..9ee2bff5dc8ee 100644 --- a/src/libstd/rt/io/net/udp.rs +++ b/src/libstd/rt/io/net/udp.rs @@ -113,7 +113,7 @@ mod test { use rt::io::*; use option::{Some, None}; use rt::comm::oneshot; - use cell::Cell; + use mutable::Mut; #[test] #[ignore] fn bind_error() { @@ -137,13 +137,13 @@ mod test { let server_ip = next_test_ip4(); let client_ip = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { match UdpSocket::bind(server_ip) { Some(ref mut server) => { - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf = [0]; match server.recvfrom(buf) { Some((nread, src)) => { @@ -161,7 +161,7 @@ mod test { do spawntask { match UdpSocket::bind(client_ip) { Some(ref mut client) => { - port.take().recv(); + port.take_unwrap().recv(); client.sendto([99], server_ip) } None => fail!() @@ -176,13 +176,13 @@ mod test { let server_ip = next_test_ip6(); let client_ip = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { match UdpSocket::bind(server_ip) { Some(ref mut server) => { - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf = [0]; match server.recvfrom(buf) { Some((nread, src)) => { @@ -200,7 +200,7 @@ mod test { do spawntask { match UdpSocket::bind(client_ip) { Some(ref mut client) => { - port.take().recv(); + port.take_unwrap().recv(); client.sendto([99], server_ip) } None => fail!() @@ -215,15 +215,15 @@ mod test { let server_ip = next_test_ip4(); let client_ip = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { match UdpSocket::bind(server_ip) { Some(server) => { let server = ~server; let mut stream = server.connect(client_ip); - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf = [0]; match stream.read(buf) { Some(nread) => { @@ -242,7 +242,7 @@ mod test { Some(client) => { let client = ~client; let mut stream = client.connect(server_ip); - port.take().recv(); + port.take_unwrap().recv(); stream.write([99]); } None => fail!() @@ -257,15 +257,15 @@ mod test { let server_ip = next_test_ip6(); let client_ip = next_test_ip6(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { match UdpSocket::bind(server_ip) { Some(server) => { let server = ~server; let mut stream = server.connect(client_ip); - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf = [0]; match stream.read(buf) { Some(nread) => { @@ -284,7 +284,7 @@ mod test { Some(client) => { let client = ~client; let mut stream = client.connect(server_ip); - port.take().recv(); + port.take_unwrap().recv(); stream.write([99]); } None => fail!() diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index 92dc62490ed1b..ddf3c7e073a95 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -151,7 +151,7 @@ There are two known issues with the current scheme for exit code propagation. */ use cast; -use cell::Cell; +use mutable::Mut; use either::{Either, Left, Right}; use option::{Option, Some, None}; use prelude::*; @@ -479,15 +479,15 @@ impl KillHandle { // Couldn't unwrap; children still alive. Reparent entire handle as // our own tombstone, to be unwrapped later. Left(this) => { - let this = Cell::new(this); // :( + let this = Mut::new_some(this); // :( do add_lazy_tombstone(parent) |other_tombstones| { - let this = Cell::new(this.take()); // :( - let others = Cell::new(other_tombstones); // :( + let this = Mut::new_some(this.take_unwrap()); // :( + let others = Mut::new_some(other_tombstones); // :( || { // Prefer to check tombstones that were there first, // being "more fair" at the expense of tail-recursion. - others.take().map_move_default(true, |f| f()) && { - let mut inner = this.take().unwrap(); + others.take_unwrap().map_move_default(true, |f| f()) && { + let mut inner = this.take_unwrap().unwrap(); (!inner.any_child_failed) && inner.child_tombstones.take().map_move_default(true, |f| f()) } @@ -502,14 +502,14 @@ impl KillHandle { // don't want to wait on now. Give them to our parent. Right(KillHandleInner { any_child_failed: false, child_tombstones: Some(f), _ }) => { - let f = Cell::new(f); // :( + let f = Mut::new_some(f); // :( do add_lazy_tombstone(parent) |other_tombstones| { - let f = Cell::new(f.take()); // :( - let others = Cell::new(other_tombstones); // :( + let f = Mut::new_some(f.take_unwrap()); // :( + let others = Mut::new_some(other_tombstones); // :( || { // Prefer fairness to tail-recursion, as in above case. - others.take().map_move_default(true, |f| f()) && - f.take()() + others.take_unwrap().map_move_default(true, |f| f()) && + f.take_unwrap()() } } } @@ -695,7 +695,7 @@ impl Drop for Death { #[cfg(test)] mod test { #[allow(unused_mut)]; - use cell::Cell; + use mutable::Mut; use rt::test::*; use super::*; use util; @@ -866,9 +866,9 @@ mod test { let mut handle = make_kill_handle(); assert!(handle.kill().is_none()); assert!(handle.killed()); - let handle_cell = Cell::new(handle); + let handle_cell = Mut::new_some(handle); let result = do spawntask_try { - handle_cell.take().inhibit_kill(false); + handle_cell.take_unwrap().inhibit_kill(false); }; assert!(result.is_err()); } @@ -881,9 +881,9 @@ mod test { handle.inhibit_kill(false); assert!(handle.kill().is_none()); assert!(!handle.killed()); - let handle_cell = Cell::new(handle); + let handle_cell = Mut::new_some(handle); let result = do spawntask_try { - handle_cell.take().allow_kill(false); + handle_cell.take_unwrap().allow_kill(false); }; assert!(result.is_err()); } diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index d4f31879c003a..ecc27db424467 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -14,7 +14,7 @@ use rt::task::Task; use rt::local_ptr; use rt::rtio::{EventLoop, IoFactoryObject}; //use borrow::to_uint; -use cell::Cell; +use mutable::Mut; pub trait Local { fn put(value: ~Self); @@ -58,10 +58,10 @@ impl Local for Task { impl Local for Scheduler { fn put(value: ~Scheduler) { - let value = Cell::new(value); + let value = Mut::new_some(value); do Local::borrow |task: &mut Task| { let task = task; - task.sched = Some(value.take()); + task.sched = Some(value.take_unwrap()); }; } #[inline] diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 3f9b7fc83df98..4c865f45e88e2 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -18,7 +18,7 @@ use libc::c_void; use cast; use ptr; -use cell::Cell; +use mutable::Mut; use option::{Option, Some, None}; use unstable::finally::Finally; use tls = rt::thread_local_storage; @@ -104,12 +104,12 @@ pub unsafe fn borrow(f: &fn(&mut T)) { // XXX: Need a different abstraction from 'finally' here to avoid unsafety let unsafe_ptr = cast::transmute_mut_region(&mut *value); - let value_cell = Cell::new(value); + let value_cell = Mut::new_some(value); do (|| { f(unsafe_ptr); }).finally { - put(value_cell.take()); + put(value_cell.take_unwrap()); } } diff --git a/src/libstd/rt/message_queue.rs b/src/libstd/rt/message_queue.rs index 99b5156b31955..f8344718d0eb2 100644 --- a/src/libstd/rt/message_queue.rs +++ b/src/libstd/rt/message_queue.rs @@ -14,7 +14,7 @@ use container::Container; use kinds::Send; use vec::OwnedVector; -use cell::Cell; +use mutable::Mut; use option::*; use unstable::sync::{UnsafeArc, LittleLock}; use clone::Clone; @@ -42,11 +42,11 @@ impl MessageQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell::new(value); + let value = Mut::new_some(value); let state = self.state.get(); do (*state).lock.lock { (*state).count += 1; - (*state).queue.push(value.take()); + (*state).queue.push(value.take_unwrap()); } } } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 6df857b8d5517..5a949006e3b9f 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -56,7 +56,7 @@ Several modules in `core` are clients of `rt`: #[doc(hidden)]; -use cell::Cell; +use mutable::Mut; use clone::Clone; use container::Container; use iter::Iterator; @@ -236,7 +236,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { let nscheds = util::default_sched_threads(); - let main = Cell::new(main); + let main = Mut::new_some(main); // The shared list of sleeping schedulers. let sleepers = SleeperList::new(); @@ -300,11 +300,11 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { // When the main task exits, after all the tasks in the main // task tree, shut down the schedulers and set the exit code. - let handles = Cell::new(handles); + let handles = Mut::new_some(handles); let on_exit: ~fn(bool) = |exit_success| { assert_once_ever!("last task exiting"); - let mut handles = handles.take(); + let mut handles = handles.take_unwrap(); for handle in handles.mut_iter() { handle.send(Shutdown); } @@ -325,22 +325,22 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { let mut threads = ~[]; - let on_exit = Cell::new(on_exit); + let on_exit = Mut::new_some(on_exit); if !use_main_sched { // In the case where we do not use a main_thread scheduler we // run the main task in one of our threads. - let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, main.take()); - main_task.death.on_exit = Some(on_exit.take()); - let main_task_cell = Cell::new(main_task); + let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, main.take_unwrap()); + main_task.death.on_exit = Some(on_exit.take_unwrap()); + let main_task_cell = Mut::new_some(main_task); let sched = scheds.pop(); - let sched_cell = Cell::new(sched); + let sched_cell = Mut::new_some(sched); let thread = do Thread::start { - let sched = sched_cell.take(); - sched.bootstrap(main_task_cell.take()); + let sched = sched_cell.take_unwrap(); + sched.bootstrap(main_task_cell.take_unwrap()); }; threads.push(thread); } @@ -348,9 +348,9 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { // Run each remaining scheduler in a thread. for sched in scheds.move_rev_iter() { rtdebug!("creating regular schedulers"); - let sched_cell = Cell::new(sched); + let sched_cell = Mut::new_some(sched); let thread = do Thread::start { - let mut sched = sched_cell.take(); + let mut sched = sched_cell.take_unwrap(); let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool, None) || { rtdebug!("boostraping a non-primary scheduler"); }; @@ -369,8 +369,8 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { let home = Sched(main_sched.make_handle()); let mut main_task = ~Task::new_root_homed(&mut main_sched.stack_pool, None, - home, main.take()); - main_task.death.on_exit = Some(on_exit.take()); + home, main.take_unwrap()); + main_task.death.on_exit = Some(on_exit.take_unwrap()); rtdebug!("bootstrapping main_task"); main_sched.bootstrap(main_task); diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 854fdadfb00d2..1f5a541657783 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -25,7 +25,7 @@ use rt::local_ptr; use rt::local::Local; use rt::rtio::{RemoteCallback, PausibleIdleCallback}; use borrow::{to_uint}; -use cell::Cell; +use mutable::Mut; use rand::{XorShiftRng, RngUtil}; use iter::range; use vec::{OwnedVector}; @@ -211,9 +211,9 @@ impl Scheduler { // Our scheduler must be in the task before the event loop // is started. - let self_sched = Cell::new(self_sched); + let self_sched = Mut::new_some(self_sched); do Local::borrow |stask: &mut Task| { - stask.sched = Some(self_sched.take()); + stask.sched = Some(self_sched.take_unwrap()); }; (*event_loop).run(); @@ -691,9 +691,9 @@ impl Scheduler { } pub fn run_task_later(next_task: ~Task) { - let next_task = Cell::new(next_task); + let next_task = Mut::new_some(next_task); do Local::borrow |sched: &mut Scheduler| { - sched.enqueue_task(next_task.take()); + sched.enqueue_task(next_task.take_unwrap()); }; } @@ -784,7 +784,7 @@ mod test { use borrow::to_uint; use rt::local::*; use rt::sched::{Scheduler}; - use cell::Cell; + use mutable::Mut; use rt::thread::Thread; use rt::task::{Task, Sched}; use rt::util; @@ -907,7 +907,7 @@ mod test { queues.clone(), sleepers.clone()); - let normal_handle = Cell::new(normal_sched.make_handle()); + let normal_handle = Mut::new_some(normal_sched.make_handle()); let friend_handle = normal_sched.make_handle(); @@ -920,7 +920,7 @@ mod test { false, Some(friend_handle)); - let special_handle = Cell::new(special_sched.make_handle()); + let special_handle = Mut::new_some(special_sched.make_handle()); let t1_handle = special_sched.make_handle(); let t4_handle = special_sched.make_handle(); @@ -951,26 +951,26 @@ mod test { }; rtdebug!("task4 id: **%u**", borrow::to_uint(task4)); - let task1 = Cell::new(task1); - let task2 = Cell::new(task2); - let task3 = Cell::new(task3); - let task4 = Cell::new(task4); + let task1 = Mut::new_some(task1); + let task2 = Mut::new_some(task2); + let task3 = Mut::new_some(task3); + let task4 = Mut::new_some(task4); // Signal from the special task that we are done. let (port, chan) = oneshot::<()>(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); let normal_task = ~do Task::new_root(&mut normal_sched.stack_pool, None) { rtdebug!("*about to submit task2*"); - Scheduler::run_task(task2.take()); + Scheduler::run_task(task2.take_unwrap()); rtdebug!("*about to submit task4*"); - Scheduler::run_task(task4.take()); + Scheduler::run_task(task4.take_unwrap()); rtdebug!("*normal_task done*"); - port.take().recv(); - let mut nh = normal_handle.take(); + port.take_unwrap().recv(); + let mut nh = normal_handle.take_unwrap(); nh.send(Shutdown); - let mut sh = special_handle.take(); + let mut sh = special_handle.take_unwrap(); sh.send(Shutdown); }; @@ -978,27 +978,27 @@ mod test { let special_task = ~do Task::new_root(&mut special_sched.stack_pool, None) { rtdebug!("*about to submit task1*"); - Scheduler::run_task(task1.take()); + Scheduler::run_task(task1.take_unwrap()); rtdebug!("*about to submit task3*"); - Scheduler::run_task(task3.take()); + Scheduler::run_task(task3.take_unwrap()); rtdebug!("*done with special_task*"); - chan.take().send(()); + chan.take_unwrap().send(()); }; rtdebug!("special task: %u", borrow::to_uint(special_task)); - let special_sched = Cell::new(special_sched); - let normal_sched = Cell::new(normal_sched); - let special_task = Cell::new(special_task); - let normal_task = Cell::new(normal_task); + let special_sched = Mut::new_some(special_sched); + let normal_sched = Mut::new_some(normal_sched); + let special_task = Mut::new_some(special_task); + let normal_task = Mut::new_some(normal_task); let normal_thread = do Thread::start { - normal_sched.take().bootstrap(normal_task.take()); + normal_sched.take_unwrap().bootstrap(normal_task.take_unwrap()); rtdebug!("finished with normal_thread"); }; let special_thread = do Thread::start { - special_sched.take().bootstrap(special_task.take()); + special_sched.take_unwrap().bootstrap(special_task.take_unwrap()); rtdebug!("finished with special_sched"); }; @@ -1026,11 +1026,11 @@ mod test { do spawntask { let sched: ~Scheduler = Local::take(); do sched.deschedule_running_task_and_then |sched, task| { - let task = Cell::new(task); + let task = Mut::new_some(task); do sched.event_loop.callback_ms(10) { rtdebug!("in callback"); let mut sched: ~Scheduler = Local::take(); - sched.enqueue_blocked_task(task.take()); + sched.enqueue_blocked_task(task.take_unwrap()); Local::put(sched); } } @@ -1044,20 +1044,20 @@ mod test { do run_in_bare_thread { let (port, chan) = oneshot::<()>(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); let thread_one = do Thread::start { - let chan = Cell::new(chan.take()); + let chan = Mut::new_some(chan.take_unwrap()); do run_in_newsched_task_core { - chan.take().send(()); + chan.take_unwrap().send(()); } }; let thread_two = do Thread::start { - let port = Cell::new(port.take()); + let port = Mut::new_some(port.take_unwrap()); do run_in_newsched_task_core { - port.take().recv(); + port.take_unwrap().recv(); } }; @@ -1091,10 +1091,10 @@ mod test { let mut handle = sched.make_handle(); - let sched = Cell::new(sched); + let sched = Mut::new_some(sched); let thread = do Thread::start { - let mut sched = sched.take(); + let mut sched = sched.take_unwrap(); let bootstrap_task = ~Task::new_root(&mut sched.stack_pool, None, ||()); sched.bootstrap(bootstrap_task); }; @@ -1122,9 +1122,9 @@ mod test { let mut ports = ~[]; do 10.times { let (port, chan) = oneshot(); - let chan_cell = Cell::new(chan); + let chan_cell = Mut::new_some(chan); do spawntask_later { - chan_cell.take().send(()); + chan_cell.take_unwrap().send(()); } ports.push(port); } diff --git a/src/libstd/rt/sleeper_list.rs b/src/libstd/rt/sleeper_list.rs index f4fdf15cda62e..6e42900b22b2f 100644 --- a/src/libstd/rt/sleeper_list.rs +++ b/src/libstd/rt/sleeper_list.rs @@ -14,7 +14,7 @@ use container::Container; use vec::OwnedVector; use option::{Option, Some, None}; -use cell::Cell; +use mutable::Mut; use unstable::sync::{UnsafeArc, LittleLock}; use rt::sched::SchedHandle; use clone::Clone; @@ -41,12 +41,12 @@ impl SleeperList { } pub fn push(&mut self, handle: SchedHandle) { - let handle = Cell::new(handle); + let handle = Mut::new_some(handle); unsafe { let state = self.state.get(); do (*state).lock.lock { (*state).count += 1; - (*state).stack.push(handle.take()); + (*state).stack.push(handle.take_unwrap()); } } } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 09bd89ec94a18..a587589bb5e6d 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -32,7 +32,7 @@ use rt::stack::{StackSegment, StackPool}; use rt::context::Context; use unstable::finally::Finally; use task::spawn::Taskgroup; -use cell::Cell; +use mutable::Mut; // The Task struct represents all state associated with a rust // task. There are at this point two primary "subtypes" of task, @@ -91,14 +91,14 @@ impl Task { // A helper to build a new task using the dynamically found // scheduler and task. Only works in GreenTask context. pub fn build_homed_child(stack_size: Option, f: ~fn(), home: SchedHome) -> ~Task { - let f = Cell::new(f); - let home = Cell::new(home); + let f = Mut::new_some(f); + let home = Mut::new_some(home); do Local::borrow |running_task: &mut Task| { let mut sched = running_task.sched.take_unwrap(); let new_task = ~running_task.new_child_homed(&mut sched.stack_pool, stack_size, - home.take(), - f.take()); + home.take_unwrap(), + f.take_unwrap()); running_task.sched = Some(sched); new_task } @@ -109,14 +109,14 @@ impl Task { } pub fn build_homed_root(stack_size: Option, f: ~fn(), home: SchedHome) -> ~Task { - let f = Cell::new(f); - let home = Cell::new(home); + let f = Mut::new_some(f); + let home = Mut::new_some(home); do Local::borrow |running_task: &mut Task| { let mut sched = running_task.sched.take_unwrap(); let new_task = ~Task::new_root_homed(&mut sched.stack_pool, stack_size, - home.take(), - f.take()); + home.take_unwrap(), + f.take_unwrap()); running_task.sched = Some(sched); new_task } @@ -361,7 +361,7 @@ impl Coroutine { } fn build_start_wrapper(start: ~fn()) -> ~fn() { - let start_cell = Cell::new(start); + let start_cell = Mut::new_some(start); let wrapper: ~fn() = || { // First code after swap to this new context. Run our // cleanup job. @@ -390,7 +390,7 @@ impl Coroutine { // be in task context. By moving `start` out of // the closure, all the user code goes our of // scope while the task is still running. - let start = start_cell.take(); + let start = start_cell.take_unwrap(); start(); }; } diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index e92accd283b7e..09c4bb5f16019 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -10,7 +10,7 @@ use libc; use option::{Some, None}; -use cell::Cell; +use mutable::Mut; use clone::Clone; use container::Container; use iter::{Iterator, range}; @@ -43,9 +43,9 @@ pub fn new_test_uv_sched() -> Scheduler { } pub fn run_in_newsched_task(f: ~fn()) { - let f = Cell::new(f); + let f = Mut::new_some(f); do run_in_bare_thread { - run_in_newsched_task_core(f.take()); + run_in_newsched_task_core(f.take_unwrap()); } } @@ -54,10 +54,10 @@ pub fn run_in_newsched_task_core(f: ~fn()) { use rt::sched::Shutdown; let mut sched = ~new_test_uv_sched(); - let exit_handle = Cell::new(sched.make_handle()); + let exit_handle = Mut::new_some(sched.make_handle()); let on_exit: ~fn(bool) = |exit_status| { - exit_handle.take().send(Shutdown); + exit_handle.take_unwrap().send(Shutdown); rtassert!(exit_status); }; let mut task = ~Task::new_root(&mut sched.stack_pool, None, f); @@ -161,7 +161,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { // see comment in other function (raising fd limits) prepare_for_lots_of_tests(); - let f = Cell::new(f); + let f = Mut::new_some(f); do run_in_bare_thread { let nthreads = match os::getenv("RUST_RT_TEST_THREADS") { @@ -201,9 +201,9 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { scheds.push(sched); } - let handles = Cell::new(handles); + let handles = Mut::new_some(handles); let on_exit: ~fn(bool) = |exit_status| { - let mut handles = handles.take(); + let mut handles = handles.take_unwrap(); // Tell schedulers to exit for handle in handles.mut_iter() { handle.send(Shutdown); @@ -211,18 +211,18 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { rtassert!(exit_status); }; - let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, f.take()); + let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, f.take_unwrap()); main_task.death.on_exit = Some(on_exit); let mut threads = ~[]; - let main_task = Cell::new(main_task); + let main_task = Mut::new_some(main_task); let main_thread = { let sched = scheds.pop(); - let sched_cell = Cell::new(sched); + let sched_cell = Mut::new_some(sched); do Thread::start { - let sched = sched_cell.take(); - sched.bootstrap(main_task.take()); + let sched = sched_cell.take_unwrap(); + sched.bootstrap(main_task.take_unwrap()); } }; threads.push(main_thread); @@ -232,11 +232,11 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool, None) || { rtdebug!("bootstrapping non-primary scheduler"); }; - let bootstrap_task_cell = Cell::new(bootstrap_task); - let sched_cell = Cell::new(sched); + let bootstrap_task_cell = Mut::new_some(bootstrap_task); + let sched_cell = Mut::new_some(sched); let thread = do Thread::start { - let sched = sched_cell.take(); - sched.bootstrap(bootstrap_task_cell.take()); + let sched = sched_cell.take_unwrap(); + sched.bootstrap(bootstrap_task_cell.take_unwrap()); }; threads.push(thread); @@ -276,8 +276,8 @@ pub fn spawntask_random(f: ~fn()) { pub fn spawntask_try(f: ~fn()) -> Result<(),()> { let (port, chan) = oneshot(); - let chan = Cell::new(chan); - let on_exit: ~fn(bool) = |exit_status| chan.take().send(exit_status); + let chan = Mut::new_some(chan); + let on_exit: ~fn(bool) = |exit_status| chan.take_unwrap().send(exit_status); let mut new_task = Task::build_root(None, f); new_task.death.on_exit = Some(on_exit); @@ -292,10 +292,10 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> { /// Spawn a new task in a new scheduler and return a thread handle. pub fn spawntask_thread(f: ~fn()) -> Thread { - let f = Cell::new(f); + let f = Mut::new_some(f); let thread = do Thread::start { - run_in_newsched_task_core(f.take()); + run_in_newsched_task_core(f.take_unwrap()); }; return thread; diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index b8e535e4c7dfd..e96f966030955 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -88,7 +88,7 @@ impl Clone for Tube { #[cfg(test)] mod test { - use cell::Cell; + use mutable::Mut; use rt::test::*; use rt::rtio::EventLoop; use rt::sched::Scheduler; @@ -101,10 +101,10 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone_cell = Cell::new(tube_clone); + let tube_clone_cell = Mut::new_some(tube_clone); let sched: ~Scheduler = Local::take(); do sched.deschedule_running_task_and_then |sched, task| { - let mut tube_clone = tube_clone_cell.take(); + let mut tube_clone = tube_clone_cell.take_unwrap(); tube_clone.send(1); sched.enqueue_blocked_task(task); } @@ -118,12 +118,12 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell::new(tube_clone); + let tube_clone = Mut::new_some(tube_clone); let sched: ~Scheduler = Local::take(); do sched.deschedule_running_task_and_then |sched, task| { - let tube_clone = Cell::new(tube_clone.take()); + let tube_clone = Mut::new_some(tube_clone.take_unwrap()); do sched.event_loop.callback { - let mut tube_clone = tube_clone.take(); + let mut tube_clone = tube_clone.take_unwrap(); // The task should be blocked on this now and // sending will wake it up. tube_clone.send(1); @@ -142,19 +142,19 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell::new(tube_clone); + let tube_clone = Mut::new_some(tube_clone); let sched: ~Scheduler = Local::take(); do sched.deschedule_running_task_and_then |sched, task| { - callback_send(tube_clone.take(), 0); + callback_send(tube_clone.take_unwrap(), 0); fn callback_send(tube: Tube, i: int) { if i == 100 { return; } - let tube = Cell::new(Cell::new(tube)); + let tube = Mut::new_some(Mut::new_some(tube)); do Local::borrow |sched: &mut Scheduler| { - let tube = tube.take(); + let tube = tube.take_unwrap(); do sched.event_loop.callback { - let mut tube = tube.take(); + let mut tube = tube.take_unwrap(); // The task should be blocked on this now and // sending will wake it up. tube.send(i); diff --git a/src/libstd/rt/uv/addrinfo.rs b/src/libstd/rt/uv/addrinfo.rs index 83a7e64b1397f..6b438392c4641 100644 --- a/src/libstd/rt/uv/addrinfo.rs +++ b/src/libstd/rt/uv/addrinfo.rs @@ -9,7 +9,7 @@ // except according to those terms. use cast::transmute; -use cell::Cell; +use mutable::Mut; use c_str::ToCStr; use libc::{c_int, c_void}; use option::{Option, Some, None}; @@ -61,14 +61,14 @@ impl GetAddrInfoRequest { None => (None, null()) }; - let cb = Cell::new(cb); + let cb = Mut::new_some(cb); let wrapper_cb: GetAddrInfoCallback = |req, addrinfo, err| { // Capture some heap values that need to stay alive for the // getaddrinfo call let _ = &c_node; let _ = &c_service; - let cb = cb.take(); + let cb = cb.take_unwrap(); cb(req, addrinfo, err) }; diff --git a/src/libstd/rt/uv/async.rs b/src/libstd/rt/uv/async.rs index ff7bb9dd03abc..a7c2e69a23031 100644 --- a/src/libstd/rt/uv/async.rs +++ b/src/libstd/rt/uv/async.rs @@ -86,16 +86,16 @@ mod test { use rt::uv::Loop; use unstable::run_in_bare_thread; use rt::thread::Thread; - use cell::Cell; + use mutable::Mut; #[test] fn smoke_test() { do run_in_bare_thread { let mut loop_ = Loop::new(); let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) ); - let watcher_cell = Cell::new(watcher); + let watcher_cell = Mut::new_some(watcher); let thread = do Thread::start { - let mut watcher = watcher_cell.take(); + let mut watcher = watcher_cell.take_unwrap(); watcher.send(); }; loop_.run(); diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 2535e40ba4f0f..163348b3847d4 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -552,7 +552,7 @@ impl NativeHandle<*uvll::uv_udp_send_t> for UdpSendRequest { mod test { use super::*; use util::ignore; - use cell::Cell; + use mutable::Mut; use vec; use unstable::run_in_bare_thread; use rt::thread::Thread; @@ -641,7 +641,7 @@ mod test { let client_tcp_watcher = TcpWatcher::new(&mut loop_); let mut client_tcp_watcher = client_tcp_watcher.as_stream(); server_stream_watcher.accept(client_tcp_watcher); - let count_cell = Cell::new(0); + let count_mut = Mut::new(0); let server_stream_watcher = server_stream_watcher; rtdebug!("starting read"); let alloc: AllocCallback = |size| { @@ -651,22 +651,21 @@ mod test { rtdebug!("i'm reading!"); let buf = vec_from_uv_buf(buf); - let mut count = count_cell.take(); + let mut mcount = count_mut.borrow_mut(); if status.is_none() { rtdebug!("got %d bytes", nread); let buf = buf.unwrap(); for byte in buf.slice(0, nread as uint).iter() { - assert!(*byte == count as u8); + assert!(*byte == *mcount.get() as u8); rtdebug!("%u", *byte as uint); - count += 1; + *mcount.get() += 1; } } else { - assert_eq!(count, MAX); + assert_eq!(*mcount.get(), MAX); do stream_watcher.close { server_stream_watcher.close(||()); } } - count_cell.put_back(count); } } @@ -679,12 +678,12 @@ mod test { assert!(status.is_none()); let msg = ~[0, 1, 2, 3, 4, 5, 6 ,7 ,8, 9]; let buf = slice_to_uv_buf(msg); - let msg_cell = Cell::new(msg); + let msg_cell = Mut::new_some(msg); do stream_watcher.write(buf) |stream_watcher, status| { rtdebug!("writing"); assert!(status.is_none()); - let msg_cell = Cell::new(msg_cell.take()); - stream_watcher.close(||ignore(msg_cell.take())); + let msg_cell = Mut::new_some(msg_cell.take_unwrap()); + stream_watcher.close(||ignore(msg_cell.take_unwrap())); } } loop_.run(); @@ -716,7 +715,7 @@ mod test { let client_tcp_watcher = TcpWatcher::new(&mut loop_); let mut client_tcp_watcher = client_tcp_watcher.as_stream(); server_stream_watcher.accept(client_tcp_watcher); - let count_cell = Cell::new(0); + let count_mut = Mut::new(0); let server_stream_watcher = server_stream_watcher; rtdebug!("starting read"); let alloc: AllocCallback = |size| { @@ -727,23 +726,22 @@ mod test { rtdebug!("i'm reading!"); let buf = vec_from_uv_buf(buf); - let mut count = count_cell.take(); + let mut mcount = count_mut.borrow_mut(); if status.is_none() { rtdebug!("got %d bytes", nread); let buf = buf.unwrap(); let r = buf.slice(0, nread as uint); for byte in r.iter() { - assert!(*byte == count as u8); + assert!(*byte == *mcount.get() as u8); rtdebug!("%u", *byte as uint); - count += 1; + *mcount.get() += 1; } } else { - assert_eq!(count, MAX); + assert_eq!(*mcount.get(), MAX); do stream_watcher.close { server_stream_watcher.close(||()); } } - count_cell.put_back(count); } } @@ -756,12 +754,12 @@ mod test { assert!(status.is_none()); let msg = ~[0, 1, 2, 3, 4, 5, 6 ,7 ,8, 9]; let buf = slice_to_uv_buf(msg); - let msg_cell = Cell::new(msg); + let msg_cell = Mut::new_some(msg); do stream_watcher.write(buf) |stream_watcher, status| { rtdebug!("writing"); assert!(status.is_none()); - let msg_cell = Cell::new(msg_cell.take()); - stream_watcher.close(||ignore(msg_cell.take())); + let msg_cell = Mut::new_some(msg_cell.take_unwrap()); + stream_watcher.close(||ignore(msg_cell.take_unwrap())); } } loop_.run(); diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 76dcf6daae681..b7e7af39eaaf3 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -11,7 +11,7 @@ use c_str::ToCStr; use cast::transmute; use cast; -use cell::Cell; +use mutable::Mut; use clone::Clone; use libc::{c_int, c_uint, c_void}; use ops::Drop; @@ -86,7 +86,7 @@ trait HomingIO { fn restore_original_home(_dummy_self: Option, old: SchedHome) { use rt::sched::TaskFromFriend; - let old = Cell::new(old); + let old = Mut::new_some(old); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); do scheduler.deschedule_running_task_and_then |scheduler, task| { @@ -96,7 +96,7 @@ trait HomingIO { * RESOLUTION IDEA: Since the task is dead, we should just abort the IO action. */ do task.wake().map_move |mut task| { - task.give_home(old.take()); + task.give_home(old.take_unwrap()); scheduler.make_handle().send(TaskFromFriend(task)); }; } @@ -366,7 +366,8 @@ impl Drop for UvRemoteCallback { #[cfg(test)] mod test_remote { - use cell::Cell; + use mutable::Mut; + use option::{Some, None}; use rt::test::*; use rt::thread::Thread; use rt::tube::Tube; @@ -379,20 +380,21 @@ mod test_remote { do run_in_mt_newsched_task { let mut tube = Tube::new(); let tube_clone = tube.clone(); - let remote_cell = Cell::new_empty(); + let remote_cell = Mut::new(None); do Local::borrow |sched: &mut Scheduler| { let tube_clone = tube_clone.clone(); - let tube_clone_cell = Cell::new(tube_clone); + let tube_clone_cell = Mut::new_some(tube_clone); let remote = do sched.event_loop.remote_callback { // This could be called multiple times - if !tube_clone_cell.is_empty() { - tube_clone_cell.take().send(1); + match tube_clone_cell.take() { + None => (), + Some(ref mut tc) => tc.send(1) } }; remote_cell.put_back(remote); } let thread = do Thread::start { - remote_cell.take().fire(); + remote_cell.take_unwrap().fire(); }; assert!(tube.recv() == 1); @@ -415,15 +417,15 @@ fn uv_fs_helper(loop_: &mut Loop, path: &P, cb: ~fn(&mut FsRequest, &mut Loop, &P, ~fn(&FsRequest, Option))) -> Result<(), IoError> { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; - let path_cell = Cell::new(path); + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; + let path_cell = Mut::new_some(path); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); let mut new_req = FsRequest::new(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); - let path = path_cell.take(); + let task_cell = Mut::new_some(task); + let path = path_cell.take_unwrap(); do cb(&mut new_req, loop_, path) |_, err| { let res = match err { None => Ok(()), @@ -431,12 +433,13 @@ fn uv_fs_helper(loop_: &mut Loop, path: &P, }; unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; } } - assert!(!result_cell.is_empty()); - return result_cell.take(); + let res_opt = result_cell.take(); + assert!(!res_opt.is_none()); + return res_opt.unwrap(); } impl IoFactory for UvIoFactory { @@ -446,8 +449,8 @@ impl IoFactory for UvIoFactory { fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStreamObject, IoError> { // Create a cell in the task to hold the result. We will fill // the cell before resuming the task. - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; // Block this task and take ownership, switch to scheduler context do task::unkillable { // FIXME(#8674) @@ -455,7 +458,7 @@ impl IoFactory for UvIoFactory { do scheduler.deschedule_running_task_and_then |_, task| { let mut tcp = TcpWatcher::new(self.uv_loop()); - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); // Wait for a connection do tcp.connect(addr) |stream, status| { @@ -470,15 +473,15 @@ impl IoFactory for UvIoFactory { // Context switch let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } Some(_) => { - let task_cell = Cell::new(task_cell.take()); + let task_cell = Mut::new_some(task_cell.take_unwrap()); do stream.close { let res = Err(uv_error_to_io_error(status.unwrap())); unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } } @@ -486,8 +489,9 @@ impl IoFactory for UvIoFactory { } } - assert!(!result_cell.is_empty()); - return result_cell.take(); + let result = result_cell.take(); + assert!(result.is_some()); + return result.unwrap() } fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListenerObject, IoError> { @@ -501,10 +505,10 @@ impl IoFactory for UvIoFactory { do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do watcher.as_stream().close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } Err(uv_error_to_io_error(uverr)) @@ -524,10 +528,10 @@ impl IoFactory for UvIoFactory { do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do watcher.close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } Err(uv_error_to_io_error(uverr)) @@ -568,16 +572,16 @@ impl IoFactory for UvIoFactory { S_IRUSR | S_IWUSR, _ => 0 }; - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; - let path_cell = Cell::new(path); + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; + let path_cell = Mut::new_some(path); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); let open_req = file::FsRequest::new(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); - let path = path_cell.take(); + let task_cell = Mut::new_some(task); + let path = path_cell.take_unwrap(); do open_req.open(self.uv_loop(), path, flags as int, create_mode as int) |req,err| { if err.is_none() { @@ -589,18 +593,19 @@ impl IoFactory for UvIoFactory { let res = Ok(fs); unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } else { let res = Err(uv_error_to_io_error(err.unwrap())); unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } }; }; }; - assert!(!result_cell.is_empty()); - return result_cell.take(); + let result = result_cell.take(); + assert!(result.is_some()); + return result.unwrap() } fn fs_unlink(&mut self, path: &P) -> Result<(), IoError> { @@ -612,16 +617,16 @@ impl IoFactory for UvIoFactory { } fn fs_stat(&mut self, path: &P) -> Result { use str::StrSlice; - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; - let path_cell = Cell::new(path); + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; + let path_cell = Mut::new_some(path); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); let stat_req = file::FsRequest::new(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); - let path = path_cell.take(); + let task_cell = Mut::new_some(task); + let path = path_cell.take_unwrap(); let path_str = path.path_as_str(|p| p.to_owned()); do stat_req.stat(self.uv_loop(), path) |req,err| { @@ -644,25 +649,26 @@ impl IoFactory for UvIoFactory { }; unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; }; }; - assert!(!result_cell.is_empty()); - return result_cell.take(); + let result = result_cell.take(); + assert!(result.is_some()); + return result.unwrap() } fn get_host_addresses(&mut self, host: &str) -> Result<~[IpAddr], IoError> { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let host_ptr: *&str = &host; let addrinfo_req = GetAddrInfoRequest::new(); - let addrinfo_req_cell = Cell::new(addrinfo_req); + let addrinfo_req_cell = Mut::new_some(addrinfo_req); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); - let mut addrinfo_req = addrinfo_req_cell.take(); + let task_cell = Mut::new_some(task); + let mut addrinfo_req = addrinfo_req_cell.take_unwrap(); unsafe { do addrinfo_req.getaddrinfo(self.uv_loop(), Some(*host_ptr), @@ -673,14 +679,15 @@ impl IoFactory for UvIoFactory { }; (*result_cell_ptr).put_back(res); let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } } } addrinfo_req.delete(); - assert!(!result_cell.is_empty()); - return result_cell.take(); + let result = result_cell.take(); + assert!(result.is_some()); + return result.unwrap() } fn fs_mkdir(&mut self, path: &P) -> Result<(), IoError> { let mode = S_IRWXU as int; @@ -700,16 +707,16 @@ impl IoFactory for UvIoFactory { fn fs_readdir(&mut self, path: &P, flags: c_int) -> Result<~[Path], IoError> { use str::StrSlice; - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; - let path_cell = Cell::new(path); + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; + let path_cell = Mut::new_some(path); do task::unkillable { // FIXME(#8674) let scheduler: ~Scheduler = Local::take(); let stat_req = file::FsRequest::new(); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); - let path = path_cell.take(); + let task_cell = Mut::new_some(task); + let path = path_cell.take_unwrap(); let path_str = path.path_as_str(|p| p.to_owned()); do stat_req.readdir(self.uv_loop(), path, flags) |req,err| { @@ -728,12 +735,13 @@ impl IoFactory for UvIoFactory { }; unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; }; }; - assert!(!result_cell.is_empty()); - return result_cell.take(); + let result = result_cell.take(); + assert!(result.is_some()); + return result.unwrap() } } @@ -756,10 +764,10 @@ impl Drop for UvTcpListener { fn drop(&mut self) { do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { - let task = Cell::new(task); + let task = Mut::new_some(task); do self_.watcher.as_stream().close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task.take()); + scheduler.resume_blocked_task_immediately(task.take_unwrap()); } } } @@ -778,21 +786,20 @@ impl RtioTcpListener for UvTcpListener { fn listen(self) -> Result<~RtioTcpAcceptorObject, IoError> { do self.home_for_io_consume |self_| { let mut acceptor = ~UvTcpAcceptor::new(self_); - let incoming = Cell::new(acceptor.incoming.clone()); + let incoming = Mut::new(acceptor.incoming.clone()); do acceptor.listener.watcher.listen |mut server, status| { - do incoming.with_mut_ref |incoming| { - let inc = match status { - Some(_) => Err(standard_error(OtherIoError)), - None => { - let inc = TcpWatcher::new(&server.event_loop()); - // first accept call in the callback guarenteed to succeed - server.accept(inc.as_stream()); - let home = get_handle_to_current_scheduler!(); - Ok(~UvTcpStream { watcher: inc, home: home }) - } - }; - incoming.send(inc); - } + let inc = match status { + Some(_) => Err(standard_error(OtherIoError)), + None => { + let inc = TcpWatcher::new(&server.event_loop()); + // first accept call in the callback guarenteed to succeed + server.accept(inc.as_stream()); + let home = get_handle_to_current_scheduler!(); + Ok(~UvTcpStream { watcher: inc, home: home }) + } + }; + let mut mincoming = incoming.borrow_mut(); + mincoming.get().send(inc); }; Ok(acceptor) } @@ -869,10 +876,10 @@ impl Drop for UvTcpStream { fn drop(&mut self) { do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do self_.watcher.as_stream().close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } } @@ -890,12 +897,12 @@ impl RtioSocket for UvTcpStream { impl RtioTcpStream for UvTcpStream { fn read(&mut self, buf: &mut [u8]) -> Result { do self.home_for_io_with_sched |self_, scheduler| { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&mut [u8] = &buf; do scheduler.deschedule_running_task_and_then |_sched, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); // XXX: We shouldn't reallocate these callbacks every // call to read let alloc: AllocCallback = |_| unsafe { @@ -920,22 +927,23 @@ impl RtioTcpStream for UvTcpStream { unsafe { (*result_cell_ptr).put_back(result); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } - assert!(!result_cell.is_empty()); - result_cell.take() + let result = result_cell.take(); + assert!(result.is_some()); + result.unwrap() } } fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { do self.home_for_io_with_sched |self_, scheduler| { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&[u8] = &buf; do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; let mut watcher = self_.watcher.as_stream(); do watcher.write(buf) |_watcher, status| { @@ -948,12 +956,13 @@ impl RtioTcpStream for UvTcpStream { unsafe { (*result_cell_ptr).put_back(result); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } - assert!(!result_cell.is_empty()); - result_cell.take() + let result = result_cell.take(); + assert!(result.is_some()); + result.unwrap() } } @@ -1026,10 +1035,10 @@ impl Drop for UvUdpSocket { fn drop(&mut self) { do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do self_.watcher.close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } } @@ -1047,12 +1056,13 @@ impl RtioSocket for UvUdpSocket { impl RtioUdpSocket for UvUdpSocket { fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, SocketAddr), IoError> { do self.home_for_io_with_sched |self_, scheduler| { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&mut [u8] = &buf; do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let alloc: AllocCallback = |_| unsafe { slice_to_uv_buf(*buf_ptr) }; do self_.watcher.recv_start(alloc) |mut watcher, nread, _buf, addr, flags, status| { let _ = flags; // /XXX add handling for partials? @@ -1070,22 +1080,23 @@ impl RtioUdpSocket for UvUdpSocket { unsafe { (*result_cell_ptr).put_back(result); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } - assert!(!result_cell.is_empty()); - result_cell.take() + let result = result_cell.take(); + assert!(result.is_some()); + result.unwrap() } } fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> Result<(), IoError> { do self.home_for_io_with_sched |self_, scheduler| { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&[u8] = &buf; do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; do self_.watcher.send(buf, dst) |_watcher, status| { @@ -1097,12 +1108,13 @@ impl RtioUdpSocket for UvUdpSocket { unsafe { (*result_cell_ptr).put_back(result); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } - assert!(!result_cell.is_empty()); - result_cell.take() + let result = result_cell.take(); + assert!(result.is_some()); + result.unwrap() } } @@ -1244,10 +1256,10 @@ impl Drop for UvTimer { do self_.home_for_io_with_sched |self_, scheduler| { rtdebug!("closing UvTimer"); do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do self_.watcher.close { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } } @@ -1259,11 +1271,11 @@ impl RtioTimer for UvTimer { do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_sched, task| { rtdebug!("sleep: entered scheduler context"); - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); do self_.watcher.start(msecs, 0) |_, status| { assert!(status.is_none()); let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); } } self_.watcher.stop(); @@ -1293,13 +1305,13 @@ impl UvFileStream { } } fn base_read(&mut self, buf: &mut [u8], offset: i64) -> Result { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&mut [u8] = &buf; do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let read_req = file::FsRequest::new(); do read_req.read(&self_.loop_, self_.fd, buf, offset) |req, uverr| { let res = match uverr { @@ -1308,20 +1320,20 @@ impl UvFileStream { }; unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; }; }; - result_cell.take() + result_cell.take_unwrap() } fn base_write(&mut self, buf: &[u8], offset: i64) -> Result<(), IoError> { - let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell = Mut::new(None); + let result_cell_ptr: *Mut>> = &result_cell; let buf_ptr: *&[u8] = &buf; do self.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let write_req = file::FsRequest::new(); do write_req.write(&self_.loop_, self_.fd, buf, offset) |_, uverr| { let res = match uverr { @@ -1330,11 +1342,11 @@ impl UvFileStream { }; unsafe { (*result_cell_ptr).put_back(res); } let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; }; }; - result_cell.take() + result_cell.take_unwrap() } fn seek_common(&mut self, pos: i64, whence: c_int) -> Result{ @@ -1360,11 +1372,11 @@ impl Drop for UvFileStream { if self.close_on_drop { do self_.home_for_io_with_sched |self_, scheduler| { do scheduler.deschedule_running_task_and_then |_, task| { - let task_cell = Cell::new(task); + let task_cell = Mut::new_some(task); let close_req = file::FsRequest::new(); do close_req.close(&self.loop_, self_.fd) |_,_| { let scheduler: ~Scheduler = Local::take(); - scheduler.resume_blocked_task_immediately(task_cell.take()); + scheduler.resume_blocked_task_immediately(task_cell.take_unwrap()); }; }; } @@ -1447,13 +1459,13 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() { let mut sched2 = ~Scheduler::new(~UvEventLoop::new(), work_queue2, queues.clone(), sleepers.clone()); - let handle1 = Cell::new(sched1.make_handle()); - let handle2 = Cell::new(sched2.make_handle()); - let tasksFriendHandle = Cell::new(sched2.make_handle()); + let handle1 = Mut::new_some(sched1.make_handle()); + let handle2 = Mut::new_some(sched2.make_handle()); + let tasksFriendHandle = Mut::new_some(sched2.make_handle()); let on_exit: ~fn(bool) = |exit_status| { - handle1.take().send(Shutdown); - handle2.take().send(Shutdown); + handle1.take_unwrap().send(Shutdown); + handle2.take_unwrap().send(Shutdown); rtassert!(exit_status); }; @@ -1473,7 +1485,7 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() { // unblock task do task.wake().map_move |task| { // send self to sched2 - tasksFriendHandle.take().send(TaskFromFriend(task)); + tasksFriendHandle.take_unwrap().send(TaskFromFriend(task)); }; // sched1 should now sleep since it has nothing else to do } @@ -1488,18 +1500,18 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() { let mut main_task = ~Task::new_root(&mut sched1.stack_pool, None, test_function); main_task.death.on_exit = Some(on_exit); - let main_task = Cell::new(main_task); + let main_task = Mut::new_some(main_task); - let null_task = Cell::new(~do Task::new_root(&mut sched2.stack_pool, None) || {}); + let null_task = Mut::new_some(~do Task::new_root(&mut sched2.stack_pool, None) || {}); - let sched1 = Cell::new(sched1); - let sched2 = Cell::new(sched2); + let sched1 = Mut::new_some(sched1); + let sched2 = Mut::new_some(sched2); let thread1 = do Thread::start { - sched1.take().bootstrap(main_task.take()); + sched1.take_unwrap().bootstrap(main_task.take_unwrap()); }; let thread2 = do Thread::start { - sched2.take().bootstrap(null_task.take()); + sched2.take_unwrap().bootstrap(null_task.take_unwrap()); }; thread1.join(); @@ -1526,12 +1538,12 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() { let mut sched2 = ~Scheduler::new(~UvEventLoop::new(), work_queue2, queues.clone(), sleepers.clone()); - let handle1 = Cell::new(sched1.make_handle()); - let handle2 = Cell::new(sched2.make_handle()); + let handle1 = Mut::new_some(sched1.make_handle()); + let handle2 = Mut::new_some(sched2.make_handle()); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); let body1: ~fn() = || { let io: *mut IoFactoryObject = unsafe { @@ -1540,11 +1552,11 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() { let addr = next_test_ip4(); let socket = unsafe { (*io).udp_bind(addr) }; assert!(socket.is_ok()); - chan.take().send(socket); + chan.take_unwrap().send(socket); }; let body2: ~fn() = || { - let socket = port.take().recv(); + let socket = port.take_unwrap().recv(); assert!(socket.is_ok()); /* The socket goes out of scope and the destructor is called. * The destructor: @@ -1555,25 +1567,25 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() { }; let on_exit: ~fn(bool) = |exit| { - handle1.take().send(Shutdown); - handle2.take().send(Shutdown); + handle1.take_unwrap().send(Shutdown); + handle2.take_unwrap().send(Shutdown); rtassert!(exit); }; - let task1 = Cell::new(~Task::new_root(&mut sched1.stack_pool, None, body1)); + let task1 = Mut::new_some(~Task::new_root(&mut sched1.stack_pool, None, body1)); let mut task2 = ~Task::new_root(&mut sched2.stack_pool, None, body2); task2.death.on_exit = Some(on_exit); - let task2 = Cell::new(task2); + let task2 = Mut::new_some(task2); - let sched1 = Cell::new(sched1); - let sched2 = Cell::new(sched2); + let sched1 = Mut::new_some(sched1); + let sched2 = Mut::new_some(sched2); let thread1 = do Thread::start { - sched1.take().bootstrap(task1.take()); + sched1.take_unwrap().bootstrap(task1.take_unwrap()); }; let thread2 = do Thread::start { - sched2.take().bootstrap(task2.take()); + sched2.take_unwrap().bootstrap(task2.take_unwrap()); }; thread1.join(); @@ -1586,8 +1598,8 @@ fn test_simple_tcp_server_and_client() { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); // Start the server first so it's listening when we connect do spawntask { @@ -1595,7 +1607,7 @@ fn test_simple_tcp_server_and_client() { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let listener = (*io).tcp_bind(addr).unwrap(); let mut acceptor = listener.listen().unwrap(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept().unwrap(); let mut buf = [0, .. 2048]; let nread = stream.read(buf).unwrap(); @@ -1609,7 +1621,7 @@ fn test_simple_tcp_server_and_client() { do spawntask { unsafe { - port.take().recv(); + port.take_unwrap().recv(); let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut stream = (*io).tcp_connect(addr).unwrap(); stream.write([0, 1, 2, 3, 4, 5, 6, 7]); @@ -1640,16 +1652,16 @@ fn test_simple_tcp_server_and_client_on_diff_threads() { let mut client_sched = ~Scheduler::new(~UvEventLoop::new(), client_work_queue, queues.clone(), sleepers.clone()); - let server_handle = Cell::new(server_sched.make_handle()); - let client_handle = Cell::new(client_sched.make_handle()); + let server_handle = Mut::new_some(server_sched.make_handle()); + let client_handle = Mut::new_some(client_sched.make_handle()); let server_on_exit: ~fn(bool) = |exit_status| { - server_handle.take().send(Shutdown); + server_handle.take_unwrap().send(Shutdown); rtassert!(exit_status); }; let client_on_exit: ~fn(bool) = |exit_status| { - client_handle.take().send(Shutdown); + client_handle.take_unwrap().send(Shutdown); rtassert!(exit_status); }; @@ -1679,20 +1691,20 @@ fn test_simple_tcp_server_and_client_on_diff_threads() { let mut server_task = ~Task::new_root(&mut server_sched.stack_pool, None, server_fn); server_task.death.on_exit = Some(server_on_exit); - let server_task = Cell::new(server_task); + let server_task = Mut::new_some(server_task); let mut client_task = ~Task::new_root(&mut client_sched.stack_pool, None, client_fn); client_task.death.on_exit = Some(client_on_exit); - let client_task = Cell::new(client_task); + let client_task = Mut::new_some(client_task); - let server_sched = Cell::new(server_sched); - let client_sched = Cell::new(client_sched); + let server_sched = Mut::new_some(server_sched); + let client_sched = Mut::new_some(client_sched); let server_thread = do Thread::start { - server_sched.take().bootstrap(server_task.take()); + server_sched.take_unwrap().bootstrap(server_task.take_unwrap()); }; let client_thread = do Thread::start { - client_sched.take().bootstrap(client_task.take()); + client_sched.take_unwrap().bootstrap(client_task.take_unwrap()); }; server_thread.join(); @@ -1706,14 +1718,14 @@ fn test_simple_udp_server_and_client() { let server_addr = next_test_ip4(); let client_addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut server_socket = (*io).udp_bind(server_addr).unwrap(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf = [0, .. 2048]; let (nread,src) = server_socket.recvfrom(buf).unwrap(); assert_eq!(nread, 8); @@ -1729,7 +1741,7 @@ fn test_simple_udp_server_and_client() { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut client_socket = (*io).udp_bind(client_addr).unwrap(); - port.take().recv(); + port.take_unwrap().recv(); client_socket.sendto([0, 1, 2, 3, 4, 5, 6, 7], server_addr); } } @@ -1741,14 +1753,14 @@ fn test_read_and_block() { do run_in_mt_newsched_task { let addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { let io: *mut IoFactoryObject = unsafe { Local::unsafe_borrow() }; let listener = unsafe { (*io).tcp_bind(addr).unwrap() }; let mut acceptor = listener.listen().unwrap(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept().unwrap(); let mut buf = [0, .. 2048]; @@ -1771,8 +1783,8 @@ fn test_read_and_block() { // will trigger a read callback while we are // not ready for it do scheduler.deschedule_running_task_and_then |sched, task| { - let task = Cell::new(task); - sched.enqueue_blocked_task(task.take()); + let task = Mut::new_some(task); + sched.enqueue_blocked_task(task.take_unwrap()); } } } @@ -1783,7 +1795,7 @@ fn test_read_and_block() { do spawntask { unsafe { - port.take().recv(); + port.take_unwrap().recv(); let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut stream = (*io).tcp_connect(addr).unwrap(); stream.write([0, 1, 2, 3, 4, 5, 6, 7]); @@ -1802,15 +1814,15 @@ fn test_read_read_read() { let addr = next_test_ip4(); static MAX: uint = 500000; let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let listener = (*io).tcp_bind(addr).unwrap(); let mut acceptor = listener.listen().unwrap(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut stream = acceptor.accept().unwrap(); let buf = [1, .. 2048]; let mut total_bytes_written = 0; @@ -1823,7 +1835,7 @@ fn test_read_read_read() { do spawntask { unsafe { - port.take().recv(); + port.take_unwrap().recv(); let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut stream = (*io).tcp_connect(addr).unwrap(); let mut buf = [0, .. 2048]; @@ -1848,14 +1860,14 @@ fn test_udp_twice() { let server_addr = next_test_ip4(); let client_addr = next_test_ip4(); let (port, chan) = oneshot(); - let port = Cell::new(port); - let chan = Cell::new(chan); + let port = Mut::new_some(port); + let chan = Mut::new_some(chan); do spawntask { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut client = (*io).udp_bind(client_addr).unwrap(); - port.take().recv(); + port.take_unwrap().recv(); assert!(client.sendto([1], server_addr).is_ok()); assert!(client.sendto([2], server_addr).is_ok()); } @@ -1865,7 +1877,7 @@ fn test_udp_twice() { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut server = (*io).udp_bind(server_addr).unwrap(); - chan.take().send(()); + chan.take_unwrap().send(()); let mut buf1 = [0]; let mut buf2 = [0]; let (nread1, src1) = server.recvfrom(buf1).unwrap(); @@ -1893,15 +1905,15 @@ fn test_udp_many_read() { let (p1, c1) = oneshot(); let (p2, c2) = oneshot(); - let first = Cell::new((p1, c2)); - let second = Cell::new((p2, c1)); + let first = Mut::new_some((p1, c2)); + let second = Mut::new_some((p2, c1)); do spawntask { unsafe { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut server_out = (*io).udp_bind(server_out_addr).unwrap(); let mut server_in = (*io).udp_bind(server_in_addr).unwrap(); - let (port, chan) = first.take(); + let (port, chan) = first.take_unwrap(); chan.send(()); port.recv(); let msg = [1, .. 2048]; @@ -1927,7 +1939,7 @@ fn test_udp_many_read() { let io: *mut IoFactoryObject = Local::unsafe_borrow(); let mut client_out = (*io).udp_bind(client_out_addr).unwrap(); let mut client_in = (*io).udp_bind(client_in_addr).unwrap(); - let (port, chan) = second.take(); + let (port, chan) = second.take_unwrap(); port.recv(); chan.send(()); let mut total_bytes_recv = 0; diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index 24792f3904e51..640f198d4d186 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -12,7 +12,7 @@ use container::Container; use option::*; use vec::OwnedVector; use unstable::sync::Exclusive; -use cell::Cell; +use mutable::Mut; use kinds::Send; use clone::Clone; @@ -30,8 +30,8 @@ impl WorkQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell::new(value); - self.queue.with(|q| q.unshift(value.take()) ); + let value = Mut::new_some(value); + self.queue.with(|q| q.unshift(value.take_unwrap()) ); } } diff --git a/src/libstd/select.rs b/src/libstd/select.rs index 8c55e13ae5819..00eb150e444ed 100644 --- a/src/libstd/select.rs +++ b/src/libstd/select.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use cell::Cell; +use mutable::Mut; use comm; use container::Container; use iter::{Iterator, DoubleEndedIterator}; @@ -55,11 +55,11 @@ pub fn select(ports: &mut [A]) -> uint { // after letting the task get woken up. The and_then closure needs to delay // the task from resuming until all ports have become blocked_on. let (p,c) = comm::oneshot(); - let p = Cell::new(p); - let c = Cell::new(c); + let p = Mut::new_some(p); + let c = Mut::new_some(c); do (|| { - let c = Cell::new(c.take()); + let c = Mut::new_some(c.take_unwrap()); let sched: ~Scheduler = Local::take(); do sched.deschedule_running_task_and_then |sched, task| { let task_handles = task.make_selectable(ports.len()); @@ -73,15 +73,15 @@ pub fn select(ports: &mut [A]) -> uint { } } - let c = Cell::new(c.take()); - do sched.event_loop.callback { c.take().send_deferred(()) } + let c = Mut::new_some(c.take_unwrap()); + do sched.event_loop.callback { c.take_unwrap().send_deferred(()) } } }).finally { - let p = Cell::new(p.take()); + let p = Mut::new_some(p.take_unwrap()); // Unkillable is necessary not because getting killed is dangerous here, // but to force the recv not to use the same kill-flag that we used for // selecting. Otherwise a user-sender could spuriously wakeup us here. - do task::unkillable { p.take().recv(); } + do task::unkillable { p.take_unwrap().recv(); } } // Task resumes. Now unblock ourselves from all the ports we blocked on. @@ -133,7 +133,7 @@ mod test { use vec::*; use comm::GenericChan; use task; - use cell::Cell; + use mutable::Mut; use iter::{Iterator, range}; #[test] #[should_fail] @@ -250,9 +250,9 @@ mod test { let (p3,c3) = oneshot(); let (p4,c4) = oneshot(); - let x = Cell::new((c2, p3, c4)); + let x = Mut::new_some((c2, p3, c4)); do task::spawn { - let (c2, p3, c4) = x.take(); + let (c2, p3, c4) = x.take_unwrap(); p3.recv(); // handshake parent c4.send(()); // normal receive task::deschedule(); @@ -297,10 +297,10 @@ mod test { let (p,c) = oneshot(); ports.push(p); if send_on_chans.contains(&i) { - let c = Cell::new(c); + let c = Mut::new_some(c); do spawntask_random { task::deschedule(); - c.take().send(()); + c.take_unwrap().send(()); } } } @@ -320,17 +320,17 @@ mod test { fn select_killed() { do run_in_newsched_task { let (success_p, success_c) = oneshot::(); - let success_c = Cell::new(success_c); + let success_c = Mut::new_some(success_c); do task::try { - let success_c = Cell::new(success_c.take()); + let success_c = Mut::new_some(success_c.take_unwrap()); do task::unkillable { let (p,c) = oneshot(); - let c = Cell::new(c); + let c = Mut::new_some(c); do task::spawn { let (dead_ps, dead_cs) = unzip(range(0u, 5).map(|_| oneshot::<()>())); let mut ports = dead_ps; select(ports); // should get killed; nothing should leak - c.take().send(()); // must not happen + c.take_unwrap().send(()); // must not happen // Make sure dead_cs doesn't get closed until after select. let _ = dead_cs; } @@ -340,7 +340,7 @@ mod test { // wait for killed selector to close (NOT send on) its c. // hope to send 'true'. - success_c.take().send(p.try_recv().is_none()); + success_c.take_unwrap().send(p.try_recv().is_none()); } }; assert!(success_p.recv()); diff --git a/src/libstd/std.rs b/src/libstd/std.rs index e9d5dd416ade3..425ae5fd09a01 100644 --- a/src/libstd/std.rs +++ b/src/libstd/std.rs @@ -156,7 +156,7 @@ pub mod option; pub mod result; pub mod either; pub mod hashmap; -pub mod cell; +pub mod mutable; pub mod trie; diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index b52dd3a906bd6..5ca7abb536506 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -37,7 +37,7 @@ use prelude::*; -use cell::Cell; +use mutable::Mut; use comm::{stream, Chan, GenericChan, GenericPort, Port}; use result::Result; use result; @@ -315,10 +315,10 @@ impl TaskBuilder { f } }; - let prev_gen_body = Cell::new(prev_gen_body); + let prev_gen_body = Mut::new_some(prev_gen_body); let next_gen_body = { let f: ~fn(~fn()) -> ~fn() = |body| { - let prev_gen_body = prev_gen_body.take(); + let prev_gen_body = prev_gen_body.take_unwrap(); wrapper(prev_gen_body(body)) }; f @@ -366,9 +366,9 @@ impl TaskBuilder { /// Runs a task, while transferring ownership of one argument to the child. pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { - let arg = Cell::new(arg); + let arg = Mut::new_some(arg); do self.spawn { - f(arg.take()); + f(arg.take_unwrap()); } } @@ -970,11 +970,11 @@ struct Wrapper { fn test_add_wrapper() { let (po, ch) = stream::<()>(); let mut b0 = task(); - let ch = Cell::new(ch); + let ch = Mut::new_some(ch); do b0.add_wrapper |body| { - let ch = Cell::new(ch.take()); + let ch = Mut::new_some(ch.take_unwrap()); let result: ~fn() = || { - let ch = ch.take(); + let ch = ch.take_unwrap(); body(); ch.send(()); }; @@ -1067,12 +1067,12 @@ fn test_spawn_sched_childs_on_default_sched() { // Assuming tests run on the default scheduler let default_id = get_sched_id(); - let ch = Cell::new(ch); + let ch = Mut::new_some(ch); do spawn_sched(SingleThreaded) { let parent_sched_id = get_sched_id(); - let ch = Cell::new(ch.take()); + let ch = Mut::new_some(ch.take_unwrap()); do spawn { - let ch = ch.take(); + let ch = ch.take_unwrap(); let child_sched_id = get_sched_id(); assert!(parent_sched_id != child_sched_id); assert_eq!(child_sched_id, default_id); diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 58cea8d7d0ecb..b65afef85c325 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -75,7 +75,7 @@ use prelude::*; use cast::transmute; use cast; -use cell::Cell; +use mutable::Mut; use container::MutableMap; use comm::{Chan, GenericChan, oneshot}; use hashmap::{HashSet, HashSetMoveIterator}; @@ -242,7 +242,7 @@ fn each_ancestor(list: &mut AncestorList, // 'do_continue' - Did the forward_blk succeed at this point? (i.e., // should we recurse? or should our callers unwind?) - let forward_blk = Cell::new(forward_blk); + let forward_blk = Mut::new_some(forward_blk); // The map defaults to None, because if ancestors is None, we're at // the end of the list, which doesn't make sense to coalesce. @@ -250,7 +250,7 @@ fn each_ancestor(list: &mut AncestorList, // NB: Takes a lock! (this ancestor node) do access_ancestors(ancestor_arc) |nobe| { // Argh, but we couldn't give it to coalesce() otherwise. - let forward_blk = forward_blk.take(); + let forward_blk = forward_blk.take_unwrap(); // Check monotonicity check_generation(last_generation, nobe.generation); /*##########################################################* @@ -387,28 +387,28 @@ fn AutoNotify(chan: Chan) -> AutoNotify { fn enlist_in_taskgroup(state: TaskGroupInner, me: KillHandle, is_member: bool) -> bool { - let me = Cell::new(me); // :( + let me = Mut::new_some(me); // :( // If 'None', the group was failing. Can't enlist. do state.map_mut_default(false) |group| { (if is_member { &mut group.members } else { &mut group.descendants - }).insert(me.take()); + }).insert(me.take_unwrap()); true } } // NB: Runs in destructor/post-exit context. Can't 'fail'. fn leave_taskgroup(state: TaskGroupInner, me: &KillHandle, is_member: bool) { - let me = Cell::new(me); // :( + let me = Mut::new_some(me); // :( // If 'None', already failing and we've already gotten a kill signal. do state.map_mut |group| { (if is_member { &mut group.members } else { &mut group.descendants - }).remove(me.take()); + }).remove(me.take_unwrap()); }; } @@ -443,9 +443,9 @@ struct RuntimeGlue; impl RuntimeGlue { fn kill_task(mut handle: KillHandle) { do handle.kill().map_move |killed_task| { - let killed_task = Cell::new(killed_task); + let killed_task = Mut::new_some(killed_task); do Local::borrow |sched: &mut Scheduler| { - sched.enqueue_task(killed_task.take()); + sched.enqueue_task(killed_task.take_unwrap()); } }; } @@ -560,17 +560,17 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { rtassert!(in_green_task_context()); - let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised)); + let child_data = Mut::new_some(gen_child_taskgroup(opts.linked, opts.supervised)); let indestructible = opts.indestructible; let child_wrapper: ~fn() = || { // Child task runs this code. // If child data is 'None', the enlist is vacuously successful. - let enlist_success = do child_data.take().map_move_default(true) |child_data| { - let child_data = Cell::new(child_data); // :( + let enlist_success = do child_data.take_unwrap().map_move_default(true) |child_data| { + let child_data = Mut::new_some(child_data); // :( do Local::borrow |me: &mut Task| { - let (child_tg, ancestors) = child_data.take(); + let (child_tg, ancestors) = child_data.take_unwrap(); let mut ancestors = ancestors; let handle = me.death.kill_handle.get_ref(); // Atomically try to get into all of our taskgroups. @@ -634,23 +634,23 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { // Create a task that will later be used to join with the new scheduler // thread when it is ready to terminate let (thread_port, thread_chan) = oneshot(); - let thread_port_cell = Cell::new(thread_port); + let thread_port_cell = Mut::new_some(thread_port); let join_task = do Task::build_child(None) { rtdebug!("running join task"); - let thread_port = thread_port_cell.take(); + let thread_port = thread_port_cell.take_unwrap(); let thread: Thread = thread_port.recv(); thread.join(); }; // Put the scheduler into another thread - let new_sched_cell = Cell::new(new_sched); - let orig_sched_handle_cell = Cell::new((*sched).make_handle()); - let join_task_cell = Cell::new(join_task); + let new_sched_cell = Mut::new_some(new_sched); + let orig_sched_handle_cell = Mut::new_some((*sched).make_handle()); + let join_task_cell = Mut::new_some(join_task); let thread = do Thread::start { - let mut new_sched = new_sched_cell.take(); - let mut orig_sched_handle = orig_sched_handle_cell.take(); - let join_task = join_task_cell.take(); + let mut new_sched = new_sched_cell.take_unwrap(); + let mut orig_sched_handle = orig_sched_handle_cell.take_unwrap(); + let join_task = join_task_cell.take_unwrap(); let bootstrap_task = ~do Task::new_root(&mut new_sched.stack_pool, None) || { rtdebug!("boostrapping a 1:1 scheduler"); @@ -679,9 +679,9 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { if opts.notify_chan.is_some() { let notify_chan = opts.notify_chan.take_unwrap(); - let notify_chan = Cell::new(notify_chan); + let notify_chan = Mut::new_some(notify_chan); let on_exit: ~fn(bool) = |success| { - notify_chan.take().send( + notify_chan.take_unwrap().send( if success { Success } else { Failure } ) }; diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index e16e6384a4f16..b04f108a76bac 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -37,15 +37,15 @@ The executing thread has no access to a task pointer and will be using a normal large stack. */ pub fn run_in_bare_thread(f: ~fn()) { - use cell::Cell; + use mutable::Mut; use rt::thread::Thread; - let f_cell = Cell::new(f); + let f_cell = Mut::new_some(f); let (port, chan) = comm::stream(); // FIXME #4525: Unfortunate that this creates an extra scheduler but it's // necessary since rust_raw_thread_join is blocking do task::spawn_sched(task::SingleThreaded) { - Thread::start(f_cell.take()).join(); + Thread::start(f_cell.take_unwrap()).join(); chan.send(()); } port.recv(); diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index c2ef2300fc261..73062d7fd7081 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -9,7 +9,7 @@ // except according to those terms. use cast; -use cell::Cell; +use mutable::Mut; use comm; use libc; use ptr; @@ -114,10 +114,10 @@ impl UnsafeArc { /// If called when the task is already unkillable, unwrap will unkillably /// block; otherwise, an unwrapping task can be killed by linked failure. pub fn unwrap(self) -> T { - let this = Cell::new(self); // argh + let this = Mut::new_some(self); // argh do task::unkillable { unsafe { - let mut this = this.take(); + let mut this = this.take_unwrap(); // The ~ dtor needs to run if this code succeeds. let mut data: ~ArcData = cast::transmute(this.data); // Set up the unwrap protocol. @@ -141,14 +141,14 @@ impl UnsafeArc { data.data.take_unwrap() } else { // The *next* person who sees the refcount hit 0 will wake us. - let p1 = Cell::new(p1); // argh + let p1 = Mut::new_some(p1); // argh // Unlike the above one, this cell is necessary. It will get // taken either in the do block or in the finally block. - let c2_and_data = Cell::new((c2,data)); + let c2_and_data = Mut::new_some((c2,data)); do (|| { - do task::rekillable { p1.take().recv(); } + do task::rekillable { p1.take_unwrap().recv(); } // Got here. Back in the 'unkillable' without getting killed. - let (c2, data) = c2_and_data.take(); + let (c2, data) = c2_and_data.take_unwrap(); c2.send(true); // FIXME(#3224): it should be like this // let ~ArcData { data: user_data, _ } = data; @@ -160,11 +160,11 @@ impl UnsafeArc { // Killed during wait. Because this might happen while // someone else still holds a reference, we can't free // the data now; the "other" last refcount will free it. - let (c2, data) = c2_and_data.take(); + let (c2, data) = c2_and_data.take_unwrap(); c2.send(false); cast::forget(data); } else { - assert!(c2_and_data.is_empty()); + assert!(c2_and_data.map(|t| t.is_none())); } } } @@ -239,9 +239,9 @@ impl Drop for UnsafeArc{ // *awake* task with the data. match data.unwrapper.take(Acquire) { Some(~(message,response)) => { - let cell = Cell::new((message, response, data)); + let cell = Mut::new_some((message, response, data)); do task::unkillable { - let (message, response, data) = cell.take(); + let (message, response, data) = cell.take_unwrap(); // Send 'ready' and wait for a response. message.send(()); // Unkillable wait. Message guaranteed to come. @@ -418,7 +418,7 @@ externfn!(fn rust_unlock_little_lock(lock: rust_little_lock)) #[cfg(test)] mod tests { - use cell::Cell; + use mutable::Mut; use comm; use option::*; use prelude::*; @@ -542,11 +542,11 @@ mod tests { fn arclike_try_unwrap_unwrap_race() { // When an unwrap and a try_unwrap race, the unwrapper should always win. let x = UnsafeArc::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = Mut::new_some(x.clone()); let (p,c) = comm::stream(); do task::spawn { c.send(()); - assert!(x2.take().unwrap() == ~~"hello"); + assert!(x2.take_unwrap().unwrap() == ~~"hello"); c.send(()); } p.recv(); @@ -567,9 +567,9 @@ mod tests { #[test] fn exclusive_new_unwrap_contended() { let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = Mut::new_some(x.clone()); do task::spawn { - let x2 = x2.take(); + let x2 = x2.take_unwrap(); unsafe { do x2.with |_hello| { } } task::deschedule(); } @@ -577,12 +577,12 @@ mod tests { // Now try the same thing, but with the child task blocking. let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = Mut::new_some(x.clone()); let mut res = None; let mut builder = task::task(); builder.future_result(|r| res = Some(r)); do builder.spawn { - let x2 = x2.take(); + let x2 = x2.take_unwrap(); assert!(x2.unwrap() == ~~"hello"); } // Have to get rid of our reference before blocking. @@ -593,12 +593,12 @@ mod tests { #[test] #[should_fail] fn exclusive_new_unwrap_conflict() { let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = Mut::new_some(x.clone()); let mut res = None; let mut builder = task::task(); builder.future_result(|r| res = Some(r)); do builder.spawn { - let x2 = x2.take(); + let x2 = x2.take_unwrap(); assert!(x2.unwrap() == ~~"hello"); } assert!(x.unwrap() == ~~"hello"); diff --git a/src/rustdoc_ng/rustdoc_ng.rs b/src/rustdoc_ng/rustdoc_ng.rs index ec6ad6974e975..adf42748f8df4 100644 --- a/src/rustdoc_ng/rustdoc_ng.rs +++ b/src/rustdoc_ng/rustdoc_ng.rs @@ -22,7 +22,7 @@ extern mod rustc; extern mod extra; use extra::serialize::Encodable; -use std::cell::Cell; + pub mod core; pub mod doctree; @@ -41,6 +41,7 @@ pub fn main() { } pub fn main_args(args: &[~str]) { + use std::mutable::Mut; use extra::getopts::*; use extra::getopts::groups::*; @@ -61,7 +62,7 @@ pub fn main_args(args: &[~str]) { return; } - let libs = Cell::new(opt_strs(&matches, "L").map(|s| Path(*s))); + let libs = Mut::new_some(opt_strs(&matches, "L").map(|s| Path(*s))); let mut passes = if opt_present(&matches, "n") { ~[] @@ -76,11 +77,11 @@ pub fn main_args(args: &[~str]) { return; } - let cr = Cell::new(Path(matches.free[0])); + let cr = Mut::new_some(Path(matches.free[0])); let crate = do std::task::try { - let cr = cr.take(); - core::run_core(libs.take(), &cr) + let cr = cr.take_unwrap(); + core::run_core(libs.take_unwrap(), &cr) }.unwrap(); // { "schema": version, "crate": { parsed crate ... }, "plugins": { output of plugins ... }} diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index dd56d550e61c2..b58005f18f67d 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -20,7 +20,8 @@ extern mod extra; use extra::arc; use extra::future; use extra::time; -use std::cell::Cell; + +use std::mutable::Mut; use std::os; use std::uint; @@ -82,7 +83,7 @@ fn main() { let msg_per_task = from_str::(args[2]).unwrap(); let (num_chan, num_port) = init(); - let num_chan = Cell::new(num_chan); + let num_chan = Mut::new_some(num_chan); let start = time::precise_time_s(); @@ -92,11 +93,11 @@ fn main() { for i in range(1u, num_tasks) { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell::new(num_chan.take()); - let num_port = Cell::new(num_port); + let num_chan2 = Mut::new_some(num_chan.take_unwrap()); + let num_port = Mut::new_some(num_port); let new_future = do future::spawn() { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); + let num_chan = num_chan2.take_unwrap(); + let num_port1 = num_port.take_unwrap(); thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); @@ -104,7 +105,7 @@ fn main() { }; // do our iteration - thread_ring(0, msg_per_task, num_chan.take(), num_port); + thread_ring(0, msg_per_task, num_chan.take_unwrap(), num_port); // synchronize for f in futures.mut_iter() { diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 130bd4e7d16a1..98a05c748f875 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -20,7 +20,8 @@ extern mod extra; use extra::arc; use extra::future; use extra::time; -use std::cell::Cell; + +use std::mutable::Mut; use std::os; use std::uint; @@ -78,7 +79,7 @@ fn main() { let msg_per_task = from_str::(args[2]).unwrap(); let (num_chan, num_port) = init(); - let num_chan = Cell::new(num_chan); + let num_chan = Mut::new_some(num_chan); let start = time::precise_time_s(); @@ -88,11 +89,11 @@ fn main() { for i in range(1u, num_tasks) { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell::new(num_chan.take()); - let num_port = Cell::new(num_port); + let num_chan2 = Mut::new_some(num_chan.take_unwrap()); + let num_port = Mut::new_some(num_port); let new_future = do future::spawn { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); + let num_chan = num_chan2.take_unwrap(); + let num_port1 = num_port.take_unwrap(); thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); @@ -100,7 +101,7 @@ fn main() { }; // do our iteration - thread_ring(0, msg_per_task, num_chan.take(), num_port); + thread_ring(0, msg_per_task, num_chan.take_unwrap(), num_port); // synchronize for f in futures.mut_iter() { diff --git a/src/test/bench/rt-messaging-ping-pong.rs b/src/test/bench/rt-messaging-ping-pong.rs index ec796713c21d1..19dddaf0408c8 100644 --- a/src/test/bench/rt-messaging-ping-pong.rs +++ b/src/test/bench/rt-messaging-ping-pong.rs @@ -10,10 +10,11 @@ extern mod extra; +use std::mutable::Mut; use std::os; use std::uint; use std::rt::test::spawntask_later; -use std::cell::Cell; + // This is a simple bench that creates M pairs of of tasks. These // tasks ping-pong back and forth over a pair of streams. This is a @@ -29,14 +30,14 @@ fn ping_pong_bench(n: uint, m: uint) { // Create a stream B->A let (pb,cb) = stream::<()>(); - let pa = Cell::new(pa); - let ca = Cell::new(ca); - let pb = Cell::new(pb); - let cb = Cell::new(cb); + let pa = Mut::new_some(pa); + let ca = Mut::new_some(ca); + let pb = Mut::new_some(pb); + let cb = Mut::new_some(cb); do spawntask_later() || { - let chan = ca.take(); - let port = pb.take(); + let chan = ca.take_unwrap(); + let port = pb.take_unwrap(); do n.times { chan.send(()); port.recv(); @@ -44,8 +45,8 @@ fn ping_pong_bench(n: uint, m: uint) { } do spawntask_later() || { - let chan = cb.take(); - let port = pa.take(); + let chan = cb.take_unwrap(); + let port = pa.take_unwrap(); do n.times { port.recv(); chan.send(()); diff --git a/src/test/bench/rt-parfib.rs b/src/test/bench/rt-parfib.rs index 3c981611e5039..434257fd0d507 100644 --- a/src/test/bench/rt-parfib.rs +++ b/src/test/bench/rt-parfib.rs @@ -10,10 +10,11 @@ extern mod extra; +use std::mutable::Mut; use std::os; use std::uint; use std::rt::test::spawntask_later; -use std::cell::Cell; + use std::comm::*; // A simple implementation of parfib. One subtree is found in a new @@ -26,9 +27,9 @@ fn parfib(n: uint) -> uint { } let (port,chan) = oneshot::(); - let chan = Cell::new(chan); + let chan = Mut::new_some(chan); do spawntask_later { - chan.take().send(parfib(n-1)); + chan.take_unwrap().send(parfib(n-1)); }; let m2 = parfib(n-2); return (port.recv() + m2); diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index e4f395e5eca1b..5e50de235b1bb 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -12,7 +12,7 @@ extern mod extra; -use std::cell::Cell; + use std::comm::*; use std::io; use std::option; @@ -139,6 +139,7 @@ fn creature( } fn rendezvous(nn: uint, set: ~[color]) { + use std::mutable::Mut; // these ports will allow us to hear from the creatures let (from_creatures, to_rendezvous) = stream::(); @@ -158,9 +159,9 @@ fn rendezvous(nn: uint, set: ~[color]) { let to_rendezvous = to_rendezvous.clone(); let to_rendezvous_log = to_rendezvous_log.clone(); let (from_rendezvous, to_creature) = stream(); - let from_rendezvous = Cell::new(from_rendezvous); + let from_rendezvous = Mut::new_some(from_rendezvous); do task::spawn || { - creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(), + creature(ii, col, from_rendezvous.take_unwrap(), to_rendezvous.clone(), to_rendezvous_log.clone()); } to_creature diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 0827f7d34475b..176b156f047be 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -17,8 +17,9 @@ // // The filename is a song reference; google it in quotes. -use std::cell::Cell; + use std::comm; +use std::mutable::Mut; use std::os; use std::task; use std::uint; @@ -27,9 +28,9 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = Cell::new(c); + let c = Mut::new_some(c); do task::spawn_supervised { - let c = c.take(); + let c = c.take_unwrap(); if gens_left & 1 == 1 { task::deschedule(); // shake things up a bit } diff --git a/src/test/compile-fail/issue-7013.rs b/src/test/compile-fail/issue-7013.rs deleted file mode 100644 index fa22665e8c355..0000000000000 --- a/src/test/compile-fail/issue-7013.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod extra; -use extra::rc::RcMut; - -trait Foo -{ - fn set(&mut self, v: RcMut); -} - -struct B -{ - v: Option> -} - -impl Foo for B -{ - fn set(&mut self, v: RcMut) - { - self.v = Some(v); - } -} - -struct A -{ - v: ~Foo, -} - -fn main() -{ - let a = A {v: ~B{v: None} as ~Foo}; //~ ERROR cannot pack type `~B`, which does not fulfill `Send` - let v = RcMut::from_freeze(a); //~ ERROR instantiating a type parameter with an incompatible type - let w = v.clone(); - v.with_mut_borrow(|p| {p.v.set(w.clone());}) -} diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index e7b897ad90683..da375b9450359 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cell::Cell; + +use std::mutable::Mut; use std::task; struct Port(@T); @@ -29,10 +30,10 @@ fn main() { } } - let x = Cell::new(foo(Port(@()))); + let x = Mut::new_some(foo(Port(@()))); do task::spawn { - let y = x.take(); //~ ERROR does not fulfill `Send` + let y = x.take_unwrap(); //~ ERROR does not fulfill `Send` error!(y); } } diff --git a/src/test/compile-fail/rcmut-not-const-and-not-owned.rs b/src/test/compile-fail/rcmut-not-const-and-not-owned.rs index d645f35d96d7c..8d5fa8250440f 100644 --- a/src/test/compile-fail/rcmut-not-const-and-not-owned.rs +++ b/src/test/compile-fail/rcmut-not-const-and-not-owned.rs @@ -11,10 +11,10 @@ extern mod extra; fn o(_: &T) {} -fn c(_: &T) {} +//fn c(_: &T) {} fn main() { - let x = extra::rc::RcMut::from_send(0); - o(&x); //~ ERROR instantiating a type parameter with an incompatible type `extra::rc::RcMut`, which does not fulfill `Send` - c(&x); //~ ERROR instantiating a type parameter with an incompatible type `extra::rc::RcMut`, which does not fulfill `Freeze` + let x = extra::rc::Rc::from_send_mut(0); + o(&x); //~ ERROR instantiating a type parameter with an incompatible type `extra::rc::Rc>`, which does not fulfill `Send` + //c(&x); // XYZ instantiating a type parameter with an incompatible type `extra::rc::Rc>`, which does not fulfill `Freeze` } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 19f0843efd82c..a4063583c8921 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -312,15 +312,15 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = Cell::new(client_); - let server_ = Cell::new(server_); + let client_ = Mut::new_some(client_); + let server_ = Mut::new_some(server_); task::spawn {|client_| - let client__ = client_.take(); + let client__ = client_.take_unwrap(); client(client__); }; task::spawn {|server_| - let server__ = server_.take(); + let server__ = server_.take_unwrap(); server(server_ˊ); }; */ diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index 2399aa5b035cc..cd1b6d0b99e03 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cell::Cell; + +use std::mutable::Mut; use std::task; pub fn main() { test05(); } @@ -23,8 +24,8 @@ fn test05() { error!(*three + n); // will copy x into the closure assert_eq!(*three, 3); }; - let fn_to_send = Cell::new(fn_to_send); + let fn_to_send = Mut::new_some(fn_to_send); task::spawn(|| { - test05_start(fn_to_send.take()); + test05_start(fn_to_send.take_unwrap()); }); } diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 10116e569467c..b01ea5a172628 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,8 +13,9 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. -use std::cell::Cell; + use std::comm::*; +use std::mutable::Mut; use std::ptr; use std::task; @@ -55,9 +56,9 @@ fn joinable(f: ~fn()) -> Port { *b = true; } let (p, c) = stream(); - let c = Cell::new(c); + let c = Mut::new_some(c); do task::spawn_unlinked { - let ccc = c.take(); + let ccc = c.take_unwrap(); wrapper(ccc, f) } p diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index a4510ef70e1b2..e2ccfffee7011 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -18,8 +18,8 @@ extern mod extra; use extra::arc; use std::comm; +use std::mutable::Mut; use std::task; -use std::cell; trait Pet { fn name(&self, blk: &fn(&str)); @@ -71,14 +71,14 @@ fn main() { ~fishe as ~Pet:Freeze+Send, ~dogge2 as ~Pet:Freeze+Send]); let (p1,c1) = comm::stream(); - let arc1 = cell::Cell::new(arc.clone()); - do task::spawn { check_legs(arc1.take()); c1.send(()); } + let arc1 = Mut::new_some(arc.clone()); + do task::spawn { check_legs(arc1.take_unwrap()); c1.send(()); } let (p2,c2) = comm::stream(); - let arc2 = cell::Cell::new(arc.clone()); - do task::spawn { check_names(arc2.take()); c2.send(()); } + let arc2 = Mut::new_some(arc.clone()); + do task::spawn { check_names(arc2.take_unwrap()); c2.send(()); } let (p3,c3) = comm::stream(); - let arc3 = cell::Cell::new(arc.clone()); - do task::spawn { check_pedigree(arc3.take()); c3.send(()); } + let arc3 = Mut::new_some(arc.clone()); + do task::spawn { check_pedigree(arc3.take_unwrap()); c3.send(()); } p1.recv(); p2.recv(); p3.recv();