diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index 1ac6c215d27a5..c40cec262f822 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -260,7 +260,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { use core::cell::Cell; - let config = Cell(copy *config); - let testfile = Cell(testfile.to_str()); + let config = Cell::new(copy *config); + let testfile = Cell::new(testfile.to_str()); test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) } diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 6c838a82a2f98..15c24052563b4 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -558,7 +558,7 @@ mod tests { let arc = ~MutexARC(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); - let (c,p) = (Cell(c), Cell(p)); + let (c,p) = (Cell::new(c), Cell::new(p)); do task::spawn || { // wait until parent gets in comm::recv_one(p.take()); diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index 31218ca9a0a54..5efd6c33804a8 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -791,8 +791,8 @@ mod test { let addr0 = ip::v4::parse_addr("127.0.0.1"); - let begin_connect_chan = Cell(begin_connect_chan); - let accept_chan = Cell(accept_chan); + let begin_connect_chan = Cell::new(begin_connect_chan); + let accept_chan = Cell::new(accept_chan); // The server task let addr = copy addr0; diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 25a3259c69654..40cfeebd5dcd8 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -109,7 +109,7 @@ pub fn from_port(port: PortOne) -> Future { * waiting for the result to be received on the port. */ - let port = Cell(port); + let port = Cell::new(port); do from_fn { recv_one(port.take()) } @@ -137,7 +137,7 @@ pub fn spawn(blk: ~fn() -> A) -> Future { let (port, chan) = oneshot(); - let chan = Cell(chan); + let chan = Cell::new(chan); do task::spawn { let chan = chan.take(); send_one(chan, blk()); @@ -204,7 +204,7 @@ mod test { #[test] fn test_sendable_future() { let expected = "schlorf"; - let f = Cell(do spawn { expected }); + let f = Cell::new(do spawn { expected }); do task::spawn { let mut f = f.take(); let actual = f.get(); diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index 960319b9c3f99..87ebfdfb7976c 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -1830,7 +1830,7 @@ mod test { let (server_po, server_ch) = stream::<~str>(); let server_ch = SharedChan::new(server_ch); let server_ip_addr = ip::v4::parse_addr(server_ip); - let resp_cell = Cell(resp); + let resp_cell = Cell::new(resp); let listen_result = listen(server_ip_addr, server_port, 128, iotask, // on_establish_cb -- called when listener is set up @@ -1842,7 +1842,7 @@ mod test { // risky to run this on the loop, but some users // will want the POWER |new_conn, kill_ch| { - let resp_cell2 = Cell(resp_cell.take()); + let resp_cell2 = Cell::new(resp_cell.take()); debug!("SERVER: new connection!"); let (cont_po, cont_ch) = stream(); let server_ch = server_ch.clone(); diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index 1ec72f2ea9f65..96ad629ea8374 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -105,7 +105,7 @@ mod test_rc { #[test] fn test_clone() { - let x = rc_from_owned(Cell(5)); + let x = rc_from_owned(Cell::new(5)); let y = x.clone(); do x.borrow().with_mut_ref |inner| { *inner = 20; @@ -115,7 +115,7 @@ mod test_rc { #[test] fn test_deep_clone() { - let x = rc_from_owned(Cell(5)); + let x = rc_from_owned(Cell::new(5)); let y = x.deep_clone(); do x.borrow().with_mut_ref |inner| { *inner = 20; diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 79ecf4abbee5b..8f09ddea9ba78 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -818,7 +818,7 @@ mod tests { let s = ~semaphore(1); let s2 = ~s.clone(); let (p,c) = comm::stream(); - let child_data = Cell((s2, c)); + let child_data = Cell::new((s2, c)); do s.access { let (s2, c) = child_data.take(); do task::spawn || { @@ -999,7 +999,7 @@ mod tests { let mut sibling_convos = ~[]; for 2.times { let (p,c) = comm::stream(); - let c = Cell(c); + let c = Cell::new(c); sibling_convos.push(p); let mi = ~m2.clone(); // spawn sibling task diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 99903be8b22ae..6a9751b66e01e 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -568,7 +568,7 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, testfn: ~fn()) { - let testfn_cell = ::core::cell::Cell(testfn); + let testfn_cell = ::core::cell::Cell::new(testfn); do task::spawn { let mut result_future = None; // task::future_result(builder); diff --git a/src/libextra/timer.rs b/src/libextra/timer.rs index 4f662613b00af..f251336666309 100644 --- a/src/libextra/timer.rs +++ b/src/libextra/timer.rs @@ -282,7 +282,7 @@ mod test { for (times as uint).times { let mut rng = rand::rng(); - let expected = Cell(rng.gen_str(16u)); + let expected = Cell::new(rng.gen_str(16u)); let (test_po, test_ch) = stream::<~str>(); let hl_loop_clone = hl_loop.clone(); do task::spawn() { diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 5d494b1b9165b..b2fd998b73fd2 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -347,7 +347,7 @@ impl TPrep for Prep { _ => { let (port, chan) = oneshot(); let blk = replace(&mut bo, None).unwrap(); - let chan = Cell(chan); + let chan = Cell::new(chan); do task::spawn { let exe = Exec { diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index f99d096f03d75..99a5318c5aacd 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -546,7 +546,7 @@ use middle::typeck::infer::cres; use util::common::indenter; use util::ppaux::note_and_explain_region; -use core::cell::{Cell, empty_cell}; +use core::cell::Cell; use core::hashmap::{HashMap, HashSet}; use core::to_bytes; use core::uint; @@ -633,7 +633,7 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings { RegionVarBindings { tcx: tcx, var_spans: ~[], - values: empty_cell(), + values: Cell::empty(), constraints: HashMap::new(), lubs: HashMap::new(), glbs: HashMap::new(), diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index ae7968a4d467f..c4fc377bc8bf7 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -65,8 +65,8 @@ fn run(owner: SrvOwner, source: ~str, parse: Parser) -> T { let (po, ch) = stream(); - let source = Cell(source); - let parse = Cell(parse); + let source = Cell::new(source); + let parse = Cell::new(parse); do task::spawn { act(&po, source.take(), parse.take()); } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 4beb8583bae7b..691f0dfedc4ca 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -178,7 +178,7 @@ fn config_from_opts( } } }; - let process_output = Cell(process_output); + let process_output = Cell::new(process_output); let result = do result::chain(result) |config| { let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd()); let pandoc_cmd = maybe_find_pandoc( diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index d34aa7c9955d5..b17816d4e3652 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -28,7 +28,7 @@ use core::vec; use syntax; pub fn mk_pass(writer_factory: WriterFactory) -> Pass { - let writer_factory = Cell(writer_factory); + let writer_factory = Cell::new(writer_factory); Pass { name: ~"markdown", f: |srv, doc| run(srv, doc, writer_factory.take()) diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index 7e5444af05ced..96a67ea324356 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -23,7 +23,7 @@ use util::NominalOp; use core::cell::Cell; pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { - let op = Cell(op); + let op = Cell::new(op); Pass { name: copy name, f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc { diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc index 08325ffb2a3ec..56a87eb805579 100644 --- a/src/librusti/rusti.rc +++ b/src/librusti/rusti.rc @@ -365,8 +365,8 @@ pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str, } } - let line = Cell(line); - let r = Cell(copy *repl); + let line = Cell::new(line); + let r = Cell::new(copy *repl); let result = do task::try { run(r.take(), line.take()) }; diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index ab4752ff84770..2a8a01c627328 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -29,17 +29,17 @@ pub struct Cell { priv value: Option } -/// Creates a new full cell with the given value. -pub fn Cell(value: T) -> Cell { - Cell { value: Some(value) } -} +pub impl Cell { + /// Creates a new full cell with the given value. + fn new(value: T) -> Cell { + Cell { value: Some(value) } + } -/// Creates a new empty cell with no value inside. -pub fn empty_cell() -> Cell { - Cell { value: None } -} + /// Creates an empty cell. + pub fn empty() -> Cell { + Cell { value: None } + } -impl Cell { /// Yields the value, failing if the cell is empty. pub fn take(&self) -> T { let this = unsafe { transmute_mut(self) }; @@ -83,7 +83,7 @@ impl Cell { #[test] fn test_basic() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); assert!(!value_cell.is_empty()); let value = value_cell.take(); assert!(value == ~10); @@ -96,7 +96,7 @@ fn test_basic() { #[should_fail] #[ignore(cfg(windows))] fn test_take_empty() { - let value_cell = empty_cell::<~int>(); + let value_cell = Cell::empty::<~int>(); value_cell.take(); } @@ -104,14 +104,14 @@ fn test_take_empty() { #[should_fail] #[ignore(cfg(windows))] fn test_put_back_non_empty() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); value_cell.put_back(~20); } #[test] fn test_with_ref() { let good = 6; - let c = Cell(~[1, 2, 3, 4, 5, 6]); + let c = Cell::new(~[1, 2, 3, 4, 5, 6]); let l = do c.with_ref() |v| { v.len() }; assert_eq!(l, good); } @@ -120,7 +120,7 @@ fn test_with_ref() { fn test_with_mut_ref() { let good = ~[1, 2, 3]; let v = ~[1, 2]; - let c = Cell(v); + 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/rt/comm.rs b/src/libstd/rt/comm.rs index 54db03b6069c2..8a8f31bbdfa52 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -309,8 +309,8 @@ pub struct Port { pub fn stream() -> (Port, Chan) { let (pone, cone) = oneshot(); - let port = Port { next: Cell(pone) }; - let chan = Chan { next: Cell(cone) }; + let port = Port { next: Cell::new(pone) }; + let chan = Chan { next: Cell::new(cone) }; return (port, chan); } @@ -483,7 +483,7 @@ mod test { fn oneshot_multi_task_recv_then_send() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell(port); + let port_cell = Cell::new(port); do spawntask_immediately { assert!(port_cell.take().recv() == ~10); } @@ -496,8 +496,8 @@ mod test { fn oneshot_multi_task_recv_then_close() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell(port); - let chan_cell = Cell(chan); + let port_cell = Cell::new(port); + let chan_cell = Cell::new(chan); do spawntask_later { let _cell = chan_cell.take(); } @@ -513,7 +513,7 @@ mod test { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let port_cell = Cell(port); + let port_cell = Cell::new(port); let _thread = do spawntask_thread { let _p = port_cell.take(); }; @@ -527,8 +527,8 @@ mod test { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { let _p = port_cell.take(); }; @@ -545,17 +545,17 @@ mod test { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { - let port_cell = Cell(port_cell.take()); + let port_cell = Cell::new(port_cell.take()); let res = do spawntask_try { port_cell.take().recv(); }; assert!(res.is_err()); }; let _thread2 = do spawntask_thread { - let chan_cell = Cell(chan_cell.take()); + let chan_cell = Cell::new(chan_cell.take()); do spawntask { chan_cell.take(); } @@ -569,8 +569,8 @@ mod test { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { chan_cell.take().send(~10); }; @@ -593,7 +593,7 @@ mod test { fn send(chan: Chan<~int>, i: int) { if i == 10 { return } - let chan_cell = Cell(chan); + let chan_cell = Cell::new(chan); let _thread = do spawntask_thread { let chan = chan_cell.take(); chan.send(~i); @@ -604,7 +604,7 @@ mod test { fn recv(port: Port<~int>, i: int) { if i == 10 { return } - let port_cell = Cell(port); + let port_cell = Cell::new(port); let _thread = do spawntask_thread { let port = port_cell.take(); assert!(port.recv() == ~i); diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index fcbf31e87f2c0..7d6d89ce9979f 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -604,7 +604,7 @@ mod test { #[test] fn read_byte_0_bytes() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -652,7 +652,7 @@ mod test { #[test] fn read_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -691,7 +691,7 @@ mod test { #[test] fn push_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -725,7 +725,7 @@ mod test { #[test] fn push_bytes_error() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -754,7 +754,7 @@ 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(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -779,7 +779,7 @@ mod test { #[test] fn read_to_end() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -806,7 +806,7 @@ mod test { #[ignore(cfg(windows))] fn read_to_end_error() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index f7c03c13a5812..3607f781da3ff 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -287,7 +287,7 @@ mod test { do spawntask_immediately { let mut listener = TcpListener::bind(addr); for int::range(0, MAX) |i| { - let stream = Cell(listener.accept()); + let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection do spawntask_immediately { @@ -326,7 +326,7 @@ mod test { do spawntask_immediately { let mut listener = TcpListener::bind(addr); for int::range(0, MAX) |_| { - let stream = Cell(listener.accept()); + let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection do spawntask_later { diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 80d797e8c6543..0db903f81eec7 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -79,7 +79,7 @@ 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(value); + let value_cell = Cell::new(value); do (|| { f(unsafe_ptr); diff --git a/src/libstd/rt/message_queue.rs b/src/libstd/rt/message_queue.rs index fb1a533464669..5b60543344de1 100644 --- a/src/libstd/rt/message_queue.rs +++ b/src/libstd/rt/message_queue.rs @@ -30,7 +30,7 @@ impl MessageQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell(value); + let value = Cell::new(value); self.queue.with(|q| q.push(value.take()) ); } } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index f6017b92807d1..7a45977d478fd 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -187,6 +187,7 @@ pub fn context() -> RuntimeContext { use task::rt::rust_task; use self::local::Local; use self::sched::Scheduler; + use cell::Cell; // XXX: Hitting TLS twice to check if the scheduler exists // then to check for the task is not good for perf @@ -194,7 +195,7 @@ pub fn context() -> RuntimeContext { return OldTaskContext; } else { if Local::exists::() { - let context = ::cell::empty_cell(); + let context = Cell::empty(); do Local::borrow:: |sched| { if sched.in_task_context() { context.put_back(TaskContext); @@ -231,7 +232,7 @@ fn test_context() { let sched = Local::take::(); do sched.deschedule_running_task_and_then() |task| { assert_eq!(context(), SchedulerContext); - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 064eb63afc627..929b44f79b5d9 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -146,7 +146,7 @@ impl Scheduler { rtdebug!("ending running task"); do self.deschedule_running_task_and_then |dead_task| { - let dead_task = Cell(dead_task); + let dead_task = Cell::new(dead_task); do Local::borrow:: |sched| { dead_task.take().recycle(&mut sched.stack_pool); } @@ -159,7 +159,7 @@ impl Scheduler { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { - let last_task = Cell(last_task); + let last_task = Cell::new(last_task); do Local::borrow:: |sched| { sched.enqueue_task(last_task.take()); } @@ -170,7 +170,7 @@ impl Scheduler { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { - let last_task = Cell(last_task); + let last_task = Cell::new(last_task); do Local::borrow:: |sched| { sched.enqueue_task(last_task.take()); } @@ -462,7 +462,7 @@ mod test { }; // Context switch directly to the new task do sched.switch_running_tasks_and_then(task2) |task1| { - let task1 = Cell(task1); + let task1 = Cell::new(task1); do Local::borrow:: |sched| { sched.enqueue_task(task1.take()); } @@ -516,7 +516,7 @@ mod test { let sched = Local::take::(); assert!(sched.in_task_context()); do sched.deschedule_running_task_and_then() |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { assert!(!sched.in_task_context()); sched.enqueue_task(task.take()); @@ -539,7 +539,7 @@ mod test { let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let mut sched = Local::take::(); - let task = Cell(task); + let task = Cell::new(task); do sched.event_loop.callback_ms(10) { rtdebug!("in callback"); let mut sched = Local::take::(); diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index c60ae2bfeffc8..453eab09730ee 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -25,7 +25,7 @@ pub fn run_in_newsched_task(f: ~fn()) { use unstable::run_in_bare_thread; use rt::uv::uvio::UvEventLoop; - let f = Cell(f); + let f = Cell::new(f); do run_in_bare_thread { let mut sched = ~UvEventLoop::new_scheduler(); @@ -46,7 +46,7 @@ pub fn spawntask(f: ~fn()) { ~Task::without_unwinding(), f); do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); let sched = Local::take::(); sched.schedule_new_task(task.take()); } @@ -61,7 +61,7 @@ pub fn spawntask_immediately(f: ~fn()) { ~Task::without_unwinding(), f); do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } @@ -96,7 +96,7 @@ pub fn spawntask_random(f: ~fn()) { if run_now { do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } @@ -120,10 +120,10 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> { let failed_ptr: *mut bool = &mut failed; // Switch to the scheduler - let f = Cell(Cell(f)); + let f = Cell::new(Cell::new(f)); let sched = Local::take::(); do sched.deschedule_running_task_and_then() |old_task| { - let old_task = Cell(old_task); + let old_task = Cell::new(old_task); let f = f.take(); let mut sched = Local::take::(); let new_task = ~do Coroutine::new(&mut sched.stack_pool) { @@ -134,7 +134,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> { unsafe { *failed_ptr = task::failing(); } let sched = Local::take::(); do sched.switch_running_tasks_and_then(old_task.take()) |new_task| { - let new_task = Cell(new_task); + let new_task = Cell::new(new_task); do Local::borrow:: |sched| { sched.enqueue_task(new_task.take()); } @@ -153,7 +153,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread { use rt::sched::*; use rt::uv::uvio::UvEventLoop; - let f = Cell(f); + let f = Cell::new(f); let thread = do Thread::start { let mut sched = ~UvEventLoop::new_scheduler(); let task = ~Coroutine::with_task(&mut sched.stack_pool, diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index b2f475a696605..03e11dfad1d8d 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -105,7 +105,7 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone_cell = Cell(tube_clone); + let tube_clone_cell = Cell::new(tube_clone); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let mut tube_clone = tube_clone_cell.take(); @@ -123,7 +123,7 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell(Cell(Cell(tube_clone))); + let tube_clone = Cell::new(Cell::new(Cell::new(tube_clone))); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let tube_clone = tube_clone.take(); @@ -151,7 +151,7 @@ mod test { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell(tube_clone); + let tube_clone = Cell::new(tube_clone); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { callback_send(tube_clone.take(), 0); @@ -159,7 +159,7 @@ mod test { fn callback_send(tube: Tube, i: int) { if i == 100 { return; } - let tube = Cell(Cell(tube)); + let tube = Cell::new(Cell::new(tube)); do Local::borrow:: |sched| { let tube = tube.take(); do sched.event_loop.callback { diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 563d7fd1e81a1..4571747cebf6c 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -374,7 +374,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(0); + let count_cell = Cell::new(0); let server_stream_watcher = server_stream_watcher; rtdebug!("starting read"); let alloc: AllocCallback = |size| { @@ -414,11 +414,11 @@ mod test { let mut stream_watcher = stream_watcher; let msg = ~[0, 1, 2, 3, 4, 5, 6 ,7 ,8, 9]; let buf = slice_to_uv_buf(msg); - let msg_cell = Cell(msg); + let msg_cell = Cell::new(msg); do stream_watcher.write(buf) |stream_watcher, status| { rtdebug!("writing"); assert!(status.is_none()); - let msg_cell = Cell(msg_cell.take()); + let msg_cell = Cell::new(msg_cell.take()); stream_watcher.close(||ignore(msg_cell.take())); } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 1d4f65f1517f6..5b7439ad903b2 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -11,7 +11,7 @@ use option::*; use result::*; use ops::Drop; -use cell::{Cell, empty_cell}; +use cell::Cell; use cast::transmute; use clone::Clone; use rt::io::IoError; @@ -115,7 +115,7 @@ impl IoFactory for UvIoFactory { fn tcp_connect(&mut self, addr: IpAddr) -> 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 = empty_cell(); + let result_cell = Cell::empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); @@ -129,7 +129,7 @@ impl IoFactory for UvIoFactory { assert!(!scheduler.in_task_context()); } let mut tcp_watcher = TcpWatcher::new(self.uv_loop()); - let task_cell = Cell(task); + let task_cell = Cell::new(task); // Wait for a connection do tcp_watcher.connect(addr) |stream_watcher, status| { @@ -146,7 +146,7 @@ impl IoFactory for UvIoFactory { scheduler.resume_task_immediately(task_cell.take()); } else { rtdebug!("status is some"); - let task_cell = Cell(task_cell.take()); + let task_cell = Cell::new(task_cell.take()); do stream_watcher.close { let res = Err(uv_error_to_io_error(status.get())); unsafe { (*result_cell_ptr).put_back(res); } @@ -168,7 +168,7 @@ impl IoFactory for UvIoFactory { Err(uverr) => { let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.as_stream().close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -204,7 +204,7 @@ impl Drop for UvTcpListener { let watcher = self.watcher(); let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.as_stream().close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -225,9 +225,9 @@ impl RtioTcpListener for UvTcpListener { self.listening = true; let server_tcp_watcher = self.watcher(); - let incoming_streams_cell = Cell(self.incoming_streams.clone()); + let incoming_streams_cell = Cell::new(self.incoming_streams.clone()); - let incoming_streams_cell = Cell(incoming_streams_cell.take()); + let incoming_streams_cell = Cell::new(incoming_streams_cell.take()); let mut server_tcp_watcher = server_tcp_watcher; do server_tcp_watcher.listen |server_stream_watcher, status| { let maybe_stream = if status.is_none() { @@ -266,7 +266,7 @@ impl Drop for UvTcpStream { let watcher = self.watcher(); let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -277,7 +277,7 @@ impl Drop for UvTcpStream { impl RtioTcpStream for UvTcpStream { fn read(&mut self, buf: &mut [u8]) -> Result { - let result_cell = empty_cell(); + let result_cell = Cell::empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); @@ -290,7 +290,7 @@ impl RtioTcpStream for UvTcpStream { assert!(!scheduler.in_task_context()); } let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); // XXX: We shouldn't reallocate these callbacks every // call to read let alloc: AllocCallback = |_| unsafe { @@ -324,7 +324,7 @@ impl RtioTcpStream for UvTcpStream { } fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { - let result_cell = empty_cell(); + let result_cell = Cell::empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); assert!(scheduler.in_task_context()); @@ -332,7 +332,7 @@ impl RtioTcpStream for UvTcpStream { let buf_ptr: *&[u8] = &buf; do scheduler.deschedule_running_task_and_then |task| { let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; do watcher.write(buf) |_watcher, status| { let result = if status.is_none() { @@ -425,7 +425,7 @@ fn test_read_and_block() { // will trigger a read callback while we are // not ready for it do scheduler.deschedule_running_task_and_then |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |scheduler| { scheduler.enqueue_task(task.take()); } diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index 58d36113f0e35..cfffc55a58c80 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -30,7 +30,7 @@ impl WorkQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell(value); + let value = Cell::new(value); self.queue.with(|q| q.unshift(value.take()) ); } } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 7c9639bb8f3cb..223afbce091b8 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -308,7 +308,7 @@ impl TaskBuilder { f } }; - let prev_gen_body = Cell(prev_gen_body); + let prev_gen_body = Cell::new(prev_gen_body); let next_gen_body = { let f: ~fn(~fn()) -> ~fn() = |body| { let prev_gen_body = prev_gen_body.take(); @@ -354,7 +354,7 @@ impl TaskBuilder { /// Runs a task, while transfering ownership of one argument to the child. pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { - let arg = Cell(arg); + let arg = Cell::new(arg); do self.spawn { f(arg.take()); } @@ -791,9 +791,9 @@ struct Wrapper { fn test_add_wrapper() { let (po, ch) = stream::<()>(); let mut b0 = task(); - let ch = Cell(ch); + let ch = Cell::new(ch); do b0.add_wrapper |body| { - let ch = Cell(ch.take()); + let ch = Cell::new(ch.take()); let result: ~fn() = || { let ch = ch.take(); body(); @@ -890,10 +890,10 @@ fn test_spawn_sched_childs_on_default_sched() { // Assuming tests run on the default scheduler let default_id = unsafe { rt::rust_get_sched_id() }; - let ch = Cell(ch); + let ch = Cell::new(ch); do spawn_sched(SingleThreaded) { let parent_sched_id = unsafe { rt::rust_get_sched_id() }; - let ch = Cell(ch.take()); + let ch = Cell::new(ch.take()); do spawn { let ch = ch.take(); let child_sched_id = unsafe { rt::rust_get_sched_id() }; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 35cf6de3a15e3..87e9296657f48 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -594,7 +594,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { gen_child_taskgroup(opts.linked, opts.supervised); unsafe { - let child_data = Cell((child_tg, ancestors, f)); + let child_data = Cell::new((child_tg, ancestors, f)); // Being killed with the unsafe task/closure pointers would leak them. do unkillable { // Agh. Get move-mode items into the closure. FIXME (#2829) @@ -636,7 +636,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { notify_chan: Option>, f: ~fn()) -> ~fn() { - let child_data = Cell((child_arc, ancestors)); + let child_data = Cell::new((child_arc, ancestors)); let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) let mut (child_arc, ancestors) = child_data.take(); diff --git a/src/libstd/unstable/weak_task.rs b/src/libstd/unstable/weak_task.rs index d5c5230cef819..7819fe0059755 100644 --- a/src/libstd/unstable/weak_task.rs +++ b/src/libstd/unstable/weak_task.rs @@ -39,7 +39,7 @@ pub unsafe fn weaken_task(f: &fn(Port)) { let service = global_data_clone_create(global_data_key, create_global_service); let (shutdown_port, shutdown_chan) = stream::(); - let shutdown_port = Cell(shutdown_port); + let shutdown_port = Cell::new(shutdown_port); let task = get_task_id(); // Expect the weak task service to be alive assert!(service.try_send(RegisterWeakTask(task, shutdown_chan))); @@ -68,7 +68,7 @@ fn create_global_service() -> ~WeakTaskService { debug!("creating global weak task service"); let (port, chan) = stream::(); - let port = Cell(port); + let port = Cell::new(port); let chan = SharedChan::new(chan); let chan_clone = chan.clone(); @@ -76,7 +76,7 @@ fn create_global_service() -> ~WeakTaskService { task.unlinked(); do task.spawn { debug!("running global weak task service"); - let port = Cell(port.take()); + let port = Cell::new(port.take()); do (|| { let port = port.take(); // The weak task service is itself a weak task @@ -192,7 +192,7 @@ fn test_select_stream_and_oneshot() { use either::{Left, Right}; let (port, chan) = stream(); - let port = Cell(port); + let port = Cell::new(port); let (waitport, waitchan) = stream(); do spawn { unsafe { diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 3d3a6a68beb39..c0e147b2db556 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -84,7 +84,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Cell(num_chan); + let mut num_chan = Cell::new(num_chan); let start = time::precise_time_s(); @@ -94,8 +94,8 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan.take()); - let num_port = Cell(num_port); + let num_chan2 = Cell::new(num_chan.take()); + let num_port = Cell::new(num_port); let new_future = do future::spawn() { let num_chan = num_chan2.take(); let num_port1 = num_port.take(); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 46ca59f2d3159..9aaf565f36834 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -80,7 +80,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Cell(num_chan); + let mut num_chan = Cell::new(num_chan); let start = time::precise_time_s(); @@ -90,8 +90,8 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan.take()); - let num_port = Cell(num_port); + let num_chan2 = Cell::new(num_chan.take()); + let num_port = Cell::new(num_port); let new_future = do future::spawn { let num_chan = num_chan2.take(); let num_port1 = num_port.take(); diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 9a8c0656e84ad..63e4174a0fc7c 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -91,7 +91,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } @@ -112,7 +112,7 @@ pub fn spawn_service_recv( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()) } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index dcde474ace36a..53b47b1214437 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -160,7 +160,7 @@ 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(from_rendezvous); + let from_rendezvous = Cell::new(from_rendezvous); do task::spawn || { creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(), to_rendezvous_log.clone()); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 78923c8cc9688..e5732b7d5800e 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -27,7 +27,7 @@ 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(c); + let c = Cell::new(c); do task::spawn_supervised { let c = c.take(); if gens_left & 1 == 1 { diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 9847efd2dd58b..5e18a40a99c80 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -29,7 +29,7 @@ fn main() { } } - let x = Cell(foo(Port(@()))); + let x = Cell::new(foo(Port(@()))); do task::spawn { let y = x.take(); //~ ERROR value has non-owned type diff --git a/src/test/run-pass/pipe-detect-term.rs b/src/test/run-pass/pipe-detect-term.rs index a347fde422c64..abee0f36330e9 100644 --- a/src/test/run-pass/pipe-detect-term.rs +++ b/src/test/run-pass/pipe-detect-term.rs @@ -32,7 +32,7 @@ pub fn main() { let iotask = &uv::global_loop::get(); let (port, chan) = oneshot::init(); - let port = Cell(port); + let port = Cell::new(port); do spawn { match try_recv(port.take()) { Some(*) => { fail!() } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 8a0589f55ea4b..ab17607c4d7d5 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -113,8 +113,8 @@ mod test { pub fn main() { let (server_, client_) = ::pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = Cell::new(client_); + let server_ = Cell::new(server_); do task::spawn { let client__ = client_.take(); test::client(client__); diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index c993dafa489f0..a4268f9456b30 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -51,8 +51,8 @@ mod test { pub fn main() { let (server_, client_) = pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = Cell::new(client_); + let server_ = Cell::new(server_); do task::spawn { let client__ = client_.take(); diff --git a/src/test/run-pass/pipe-select.rs b/src/test/run-pass/pipe-select.rs index 8e28d3d12d9c9..0a860d0a1e22c 100644 --- a/src/test/run-pass/pipe-select.rs +++ b/src/test/run-pass/pipe-select.rs @@ -43,7 +43,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } diff --git a/src/test/run-pass/pipe-sleep.rs b/src/test/run-pass/pipe-sleep.rs index a6a81229e2846..dc88f36ba113a 100644 --- a/src/test/run-pass/pipe-sleep.rs +++ b/src/test/run-pass/pipe-sleep.rs @@ -42,7 +42,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } 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 d9f491297ea00..2399aa5b035cc 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -23,7 +23,7 @@ fn test05() { error!(*three + n); // will copy x into the closure assert_eq!(*three, 3); }; - let fn_to_send = Cell(fn_to_send); + let fn_to_send = Cell::new(fn_to_send); task::spawn(|| { test05_start(fn_to_send.take()); }); diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 6d35a9228b0c6..2025a5c304c8f 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -55,7 +55,7 @@ fn joinable(f: ~fn()) -> Port { *b = true; } let (p, c) = stream(); - let c = Cell(c); + let c = Cell::new(c); do task::spawn_unlinked { let ccc = c.take(); wrapper(ccc, f)