auto merge of #6928 : Blei/rust/fix-constructors, r=bstrie

As part of #3853
This commit is contained in:
bors 2013-06-04 09:37:41 -07:00
commit 69511c219c
52 changed files with 198 additions and 194 deletions

View File

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

View File

@ -558,7 +558,7 @@ fn test_mutex_arc_condvar() {
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());

View File

@ -660,7 +660,7 @@ mod test {
#[test]
#[ignore(reason = "ebml failure")]
fn test_serializing_memory_stream() {
let writer = BytesWriter();
let writer = BytesWriter::new();
let chan = serial::writer_chan(writer);
chan.send(10);
@ -708,7 +708,7 @@ fn test_serializing_boxes() {
#[test]
fn test_pod_memory_stream() {
let writer = BytesWriter();
let writer = BytesWriter::new();
let chan = pod::writer_chan(writer);
chan.send(10);
@ -791,8 +791,8 @@ fn test_some_tcp_stream<U:Unflattener<int>,F:Flattener<int>>(
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;

View File

@ -109,7 +109,7 @@ pub fn from_port<A:Owned>(port: PortOne<A>) -> Future<A> {
* 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<A:Owned>(blk: ~fn() -> A) -> Future<A> {
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 @@ fn test_futurefail() {
#[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();

View File

@ -1830,7 +1830,7 @@ fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str,
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 @@ fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str,
// 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();

View File

@ -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 @@ fn test_clone() {
#[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;

View File

@ -818,7 +818,7 @@ fn test_sem_runtime_friendly_blocking() {
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 @@ fn test_mutex_killed_broadcast() {
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

View File

@ -568,7 +568,7 @@ pub fn run_test(force_ignore: bool,
fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>,
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);

View File

@ -282,7 +282,7 @@ fn test_gl_timer_recv_timeout_after_time_passes() {
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() {

View File

@ -347,7 +347,7 @@ fn exec<T:Owned +
_ => {
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 {

View File

@ -1425,7 +1425,7 @@ fn encode_hash(ebml_w: &mut writer::Encoder, hash: &str) {
0, 0, 0, 1 ];
pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
let wr = @io::BytesWriter();
let wr = @io::BytesWriter::new();
let stats = Stats {
inline_bytes: 0,
attr_bytes: 0,

View File

@ -546,7 +546,7 @@ fn<a,b>(&a, &b, &a) fn<x,y>(&x, &y, &y) fn<a>(&a, &a, &a) fn<a,b,c>(&a,&b,&c)
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::new_empty(),
constraints: HashMap::new(),
lubs: HashMap::new(),
glbs: HashMap::new(),

View File

@ -65,8 +65,8 @@ fn run<T>(owner: SrvOwner<T>, 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());
}

View File

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

View File

@ -28,7 +28,7 @@
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())

View File

@ -23,7 +23,7 @@
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 {

View File

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

View File

@ -29,17 +29,17 @@ pub struct Cell<T> {
priv value: Option<T>
}
/// Creates a new full cell with the given value.
pub fn Cell<T>(value: T) -> Cell<T> {
Cell { value: Some(value) }
}
/// Creates a new empty cell with no value inside.
pub fn empty_cell<T>() -> Cell<T> {
Cell { value: None }
}
impl<T> Cell<T> {
/// Creates a new full cell with the given value.
pub fn new(value: T) -> Cell<T> {
Cell { value: Some(value) }
}
/// Creates a new empty cell with no value inside.
pub fn new_empty() -> Cell<T> {
Cell { value: None }
}
/// Yields the value, failing if the cell is empty.
pub fn take(&self) -> T {
let this = unsafe { transmute_mut(self) };
@ -83,7 +83,7 @@ pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
#[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::new_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);

View File

@ -982,6 +982,12 @@ pub struct FILERes {
f: *libc::FILE,
}
impl FILERes {
pub fn new(f: *libc::FILE) -> FILERes {
FILERes { f: f }
}
}
impl Drop for FILERes {
fn finalize(&self) {
unsafe {
@ -990,15 +996,9 @@ fn finalize(&self) {
}
}
pub fn FILERes(f: *libc::FILE) -> FILERes {
FILERes {
f: f
}
}
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader {
if cleanup {
@Wrapper { base: f, cleanup: FILERes(f) } as @Reader
@Wrapper { base: f, cleanup: FILERes::new(f) } as @Reader
} else {
@f as @Reader
}
@ -1183,7 +1183,7 @@ fn get_type(&self) -> WriterType {
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
if cleanup {
@Wrapper { base: f, cleanup: FILERes(f) } as @Writer
@Wrapper { base: f, cleanup: FILERes::new(f) } as @Writer
} else {
@f as @Writer
}
@ -1227,6 +1227,12 @@ pub struct FdRes {
fd: fd_t,
}
impl FdRes {
pub fn new(fd: fd_t) -> FdRes {
FdRes { fd: fd }
}
}
impl Drop for FdRes {
fn finalize(&self) {
unsafe {
@ -1235,15 +1241,9 @@ fn finalize(&self) {
}
}
pub fn FdRes(fd: fd_t) -> FdRes {
FdRes {
fd: fd
}
}
pub fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer {
if cleanup {
@Wrapper { base: fd, cleanup: FdRes(fd) } as @Writer
@Wrapper { base: fd, cleanup: FdRes::new(fd) } as @Writer
} else {
@fd as @Writer
}
@ -1634,6 +1634,15 @@ pub struct BytesWriter {
pos: @mut uint,
}
impl BytesWriter {
pub fn new() -> BytesWriter {
BytesWriter {
bytes: @mut ~[],
pos: @mut 0
}
}
}
impl Writer for BytesWriter {
fn write(&self, v: &[u8]) {
let v_len = v.len();
@ -1673,15 +1682,8 @@ fn get_type(&self) -> WriterType {
}
}
pub fn BytesWriter() -> BytesWriter {
BytesWriter {
bytes: @mut ~[],
pos: @mut 0
}
}
pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
let wr = @BytesWriter();
let wr = @BytesWriter::new();
f(wr as @Writer);
let @BytesWriter { bytes, _ } = wr;
copy *bytes
@ -1762,6 +1764,12 @@ pub struct Res<t> {
arg: Arg<t>,
}
impl <t: Copy> Res<t> {
pub fn new(arg: Arg<t>) -> Res<t> {
Res { arg: arg }
}
}
#[unsafe_destructor]
impl<T:Copy> Drop for Res<T> {
fn finalize(&self) {
@ -1776,12 +1784,6 @@ fn finalize(&self) {
}
}
pub fn Res<t: Copy>(arg: Arg<t>) -> Res<t>{
Res {
arg: arg
}
}
pub struct Arg<t> {
val: t,
opt_level: Option<Level>,
@ -1793,7 +1795,7 @@ pub struct Arg<t> {
// outer res
pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
blk: &fn(v: Res<*libc::FILE>)) {
blk(Res(Arg {
blk(Res::new(Arg {
val: file.f, opt_level: opt_level,
fsync_fn: |file, l| {
unsafe {
@ -1806,7 +1808,7 @@ pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
// fsync fd after executing blk
pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
blk: &fn(v: Res<fd_t>)) {
blk(Res(Arg {
blk(Res::new(Arg {
val: fd.fd, opt_level: opt_level,
fsync_fn: |fd, l| os::fsync_fd(fd, l) as int
}));
@ -1818,7 +1820,7 @@ pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
// Call o.fsync after executing blk
pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>,
blk: &fn(v: Res<@FSyncable>)) {
blk(Res(Arg {
blk(Res::new(Arg {
val: o, opt_level: opt_level,
fsync_fn: |o, l| o.fsync(l)
}));
@ -1993,7 +1995,7 @@ fn buffered_file_writer_bad_name() {
#[test]
fn bytes_buffer_overwrite() {
let wr = BytesWriter();
let wr = BytesWriter::new();
wr.write([0u8, 1u8, 2u8, 3u8]);
assert!(*wr.bytes == ~[0u8, 1u8, 2u8, 3u8]);
wr.seek(-2, SeekCur);

View File

@ -437,7 +437,7 @@ fn test_option_dance() {
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable());
let mut y = Some(util::NonCopyable::new());
let _y2 = y.swap_unwrap();
let _y3 = y.swap_unwrap();
}

View File

@ -309,8 +309,8 @@ pub struct Port<T> {
pub fn stream<T: Owned>() -> (Port<T>, Chan<T>) {
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 @@ fn oneshot_single_thread_peek_open() {
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 @@ fn oneshot_multi_task_recv_then_send() {
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 @@ fn oneshot_multi_thread_close_stress() {
for stress_factor().times {
do run_in_newsched_task {
let (port, chan) = oneshot::<int>();
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 @@ fn oneshot_multi_thread_send_close_stress() {
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 {
let _p = port_cell.take();
};
@ -545,17 +545,17 @@ fn oneshot_multi_thread_recv_close_stress() {
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 {
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 @@ fn oneshot_multi_thread_send_recv_stress() {
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 @@ fn stream_send_recv_stress() {
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 @@ fn send(chan: Chan<~int>, i: int) {
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);

View File

@ -604,7 +604,7 @@ fn read_byte() {
#[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 @@ fn read_bytes() {
#[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 @@ fn push_bytes() {
#[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 @@ fn push_bytes_eof() {
#[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 @@ fn push_bytes_fail_reset_len() {
// 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 @@ fn push_bytes_fail_reset_len() {
#[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 @@ fn read_to_end() {
#[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 {

View File

@ -287,7 +287,7 @@ fn multiple_connect_interleaved_greedy_schedule() {
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 @@ fn multiple_connect_interleaved_lazy_schedule() {
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 {

View File

@ -79,7 +79,7 @@ pub unsafe fn borrow<T>(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);

View File

@ -30,7 +30,7 @@ pub fn new() -> MessageQueue<T> {
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()) );
}
}

View File

@ -194,7 +194,7 @@ pub fn context() -> RuntimeContext {
return OldTaskContext;
} else {
if Local::exists::<Scheduler>() {
let context = ::cell::empty_cell();
let context = ::cell::Cell::new_empty();
do Local::borrow::<Scheduler> |sched| {
if sched.in_task_context() {
context.put_back(TaskContext);
@ -231,7 +231,7 @@ fn test_context() {
let sched = Local::take::<Scheduler>();
do sched.deschedule_running_task_and_then() |task| {
assert_eq!(context(), SchedulerContext);
let task = Cell(task);
let task = Cell::new(task);
do Local::borrow::<Scheduler> |sched| {
sched.enqueue_task(task.take());
}

View File

@ -146,7 +146,7 @@ pub fn terminate_current_task(~self) {
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::<Scheduler> |sched| {
dead_task.take().recycle(&mut sched.stack_pool);
}
@ -159,7 +159,7 @@ pub fn schedule_new_task(~self, task: ~Coroutine) {
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::<Scheduler> |sched| {
sched.enqueue_task(last_task.take());
}
@ -170,7 +170,7 @@ pub fn schedule_task(~self, task: ~Coroutine) {
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::<Scheduler> |sched| {
sched.enqueue_task(last_task.take());
}
@ -462,7 +462,7 @@ fn test_swap_tasks_then() {
};
// 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::<Scheduler> |sched| {
sched.enqueue_task(task1.take());
}
@ -516,7 +516,7 @@ fn test_block_task() {
let sched = Local::take::<Scheduler>();
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::<Scheduler> |sched| {
assert!(!sched.in_task_context());
sched.enqueue_task(task.take());
@ -539,7 +539,7 @@ fn test_io_callback() {
let sched = Local::take::<Scheduler>();
do sched.deschedule_running_task_and_then |task| {
let mut sched = Local::take::<Scheduler>();
let task = Cell(task);
let task = Cell::new(task);
do sched.event_loop.callback_ms(10) {
rtdebug!("in callback");
let mut sched = Local::take::<Scheduler>();

View File

@ -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::<Scheduler>();
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::<Scheduler> |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::<Scheduler> |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::<Scheduler>();
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::<Scheduler>();
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::<Scheduler>();
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::<Scheduler> |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,

View File

@ -105,7 +105,7 @@ fn simple_test() {
do run_in_newsched_task {
let mut tube: Tube<int> = 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::<Scheduler>();
do sched.deschedule_running_task_and_then |task| {
let mut tube_clone = tube_clone_cell.take();
@ -123,7 +123,7 @@ fn blocking_test() {
do run_in_newsched_task {
let mut tube: Tube<int> = 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::<Scheduler>();
do sched.deschedule_running_task_and_then |task| {
let tube_clone = tube_clone.take();
@ -151,7 +151,7 @@ fn many_blocking_test() {
do run_in_newsched_task {
let mut tube: Tube<int> = Tube::new();
let tube_clone = tube.clone();
let tube_clone = Cell(tube_clone);
let tube_clone = Cell::new(tube_clone);
let sched = Local::take::<Scheduler>();
do sched.deschedule_running_task_and_then |task| {
callback_send(tube_clone.take(), 0);
@ -159,7 +159,7 @@ fn many_blocking_test() {
fn callback_send(tube: Tube<int>, i: int) {
if i == 100 { return; }
let tube = Cell(Cell(tube));
let tube = Cell::new(Cell::new(tube));
do Local::borrow::<Scheduler> |sched| {
let tube = tube.take();
do sched.event_loop.callback {

View File

@ -374,7 +374,7 @@ fn listen() {
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 @@ fn listen() {
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()));
}
}

View File

@ -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::new_empty();
let result_cell_ptr: *Cell<Result<~RtioTcpStreamObject, IoError>> = &result_cell;
let scheduler = Local::take::<Scheduler>();
@ -129,7 +129,7 @@ fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError>
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 @@ fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError>
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 @@ fn tcp_bind(&mut self, addr: IpAddr) -> Result<~RtioTcpListenerObject, IoError>
Err(uverr) => {
let scheduler = Local::take::<Scheduler>();
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>();
scheduler.resume_task_immediately(task_cell.take());
@ -204,7 +204,7 @@ fn finalize(&self) {
let watcher = self.watcher();
let scheduler = Local::take::<Scheduler>();
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>();
scheduler.resume_task_immediately(task_cell.take());
@ -225,9 +225,9 @@ fn accept(&mut self) -> Result<~RtioTcpStreamObject, IoError> {
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 @@ fn finalize(&self) {
let watcher = self.watcher();
let scheduler = Local::take::<Scheduler>();
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>();
scheduler.resume_task_immediately(task_cell.take());
@ -277,7 +277,7 @@ fn finalize(&self) {
impl RtioTcpStream for UvTcpStream {
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
let result_cell = empty_cell();
let result_cell = Cell::new_empty();
let result_cell_ptr: *Cell<Result<uint, IoError>> = &result_cell;
let scheduler = Local::take::<Scheduler>();
@ -290,7 +290,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
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 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
}
fn write(&mut self, buf: &[u8]) -> Result<(), IoError> {
let result_cell = empty_cell();
let result_cell = Cell::new_empty();
let result_cell_ptr: *Cell<Result<(), IoError>> = &result_cell;
let scheduler = Local::take::<Scheduler>();
assert!(scheduler.in_task_context());
@ -332,7 +332,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), IoError> {
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| {
scheduler.enqueue_task(task.take());
}

View File

@ -16,7 +16,7 @@
use super::rtio::*;
use ops::Drop;
use old_iter::CopyableIter;
use cell::{Cell, empty_cell};
use cell::Cell;
use cast::transmute;
use super::sched::{Scheduler, local_sched};
@ -103,7 +103,7 @@ impl IoFactory for UvIoFactory {
fn connect(&mut self, addr: IpAddr) -> Option<~StreamObject> {
// 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::new_empty();
let result_cell_ptr: *Cell<Option<~StreamObject>> = &result_cell;
let scheduler = local_sched::take();
@ -117,7 +117,7 @@ fn connect(&mut self, addr: IpAddr) -> Option<~StreamObject> {
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| {
@ -175,7 +175,7 @@ impl TcpListener for UvTcpListener {
fn listen(&mut self) -> Option<~StreamObject> {
rtdebug!("entering listen");
let result_cell = empty_cell();
let result_cell = Cell::new_empty();
let result_cell_ptr: *Cell<Option<~StreamObject>> = &result_cell;
let server_tcp_watcher = self.watcher();
@ -184,7 +184,7 @@ fn listen(&mut self) -> Option<~StreamObject> {
assert!(scheduler.in_task_context());
do scheduler.deschedule_running_task_and_then |task| {
let task_cell = Cell(task);
let task_cell = Cell::new(task);
let mut server_tcp_watcher = server_tcp_watcher;
do server_tcp_watcher.listen |server_stream_watcher, status| {
let maybe_stream = if status.is_none() {
@ -239,7 +239,7 @@ fn finalize(&self) {
impl Stream for UvStream {
fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()> {
let result_cell = empty_cell();
let result_cell = Cell::new_empty();
let result_cell_ptr: *Cell<Result<uint, ()>> = &result_cell;
let scheduler = local_sched::take();
@ -252,7 +252,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()> {
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 {
@ -286,7 +286,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()> {
}
fn write(&mut self, buf: &[u8]) -> Result<(), ()> {
let result_cell = empty_cell();
let result_cell = Cell::new_empty();
let result_cell_ptr: *Cell<Result<(), ()>> = &result_cell;
let scheduler = local_sched::take();
assert!(scheduler.in_task_context());
@ -294,7 +294,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), ()> {
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 { &*buf_ptr };
// XXX: OMGCOPIES
let buf = buf.to_vec();
@ -390,7 +390,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_sched::borrow |scheduler| {
scheduler.task_queue.push_back(task.take());
}

View File

@ -30,7 +30,7 @@ pub fn new() -> WorkQueue<T> {
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()) );
}
}

View File

@ -308,7 +308,7 @@ pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) {
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 @@ pub fn spawn(&mut self, f: ~fn()) {
/// Runs a task, while transfering ownership of one argument to the child.
pub fn spawn_with<A:Owned>(&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() };

View File

@ -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 make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc,
notify_chan: Option<Chan<TaskResult>>,
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();

View File

@ -39,7 +39,7 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
let service = global_data_clone_create(global_data_key,
create_global_service);
let (shutdown_port, shutdown_chan) = stream::<ShutdownMsg>();
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::<ServiceMsg>();
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 {

View File

@ -79,13 +79,15 @@ pub struct NonCopyable {
priv i: (),
}
impl NonCopyable {
/// Creates a dummy non-copyable structure and returns it for use.
pub fn new() -> NonCopyable { NonCopyable { i: () } }
}
impl Drop for NonCopyable {
fn finalize(&self) { }
}
/// Creates a dummy non-copyable structure and returns it for use.
pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
/// A type with no inhabitants
pub enum Void { }
@ -152,7 +154,7 @@ pub fn test_swap() {
}
#[test]
pub fn test_replace() {
let mut x = Some(NonCopyable());
let mut x = Some(NonCopyable::new());
let y = replace(&mut x, None);
assert!(x.is_none());
assert!(y.is_some());

View File

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

View File

@ -74,7 +74,7 @@ fn main() {
let msg_per_task = uint::from_str(args[2]).get();
let (num_port, num_chan) = ring::init();
let mut num_chan = Cell(num_chan);
let mut num_chan = Cell::new(num_chan);
let start = time::precise_time_s();
@ -84,8 +84,8 @@ fn main() {
for uint::range(1u, num_tasks) |i| {
//error!("spawning %?", i);
let (num_port, new_chan) = ring::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();

View File

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

View File

@ -91,7 +91,7 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
// 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<T:Owned,Tb:Owned>(
// 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())
}

View File

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

View File

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

View File

@ -29,7 +29,7 @@ fn foo(x: Port<()>) -> foo {
}
}
let x = Cell(foo(Port(@())));
let x = Cell::new(foo(Port(@())));
do task::spawn {
let y = x.take(); //~ ERROR value has non-owned type

View File

@ -318,8 +318,8 @@ pub fn main() {
// Commented out because of option::get error
let (client_, server_) = pingpong::init();
let client_ = Cell(client_);
let server_ = Cell(server_);
let client_ = Cell::new(client_);
let server_ = Cell::new(server_);
task::spawn {|client_|
let client__ = client_.take();

View File

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

View File

@ -113,8 +113,8 @@ pub fn server(chan: ::pingpong::server::ping) {
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__);

View File

@ -51,8 +51,8 @@ pub fn server(chan: ::pingpong::server::ping) {
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();

View File

@ -43,7 +43,7 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
// 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());
}

View File

@ -42,7 +42,7 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
// 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());
}

View File

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

View File

@ -55,7 +55,7 @@ fn wrapper(c: Chan<bool>, f: &fn()) {
*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)