libextra: Another round of de-Cell-ing.
34 uses of `Cell` remain.
This commit is contained in:
parent
5aad292fb9
commit
786dea207d
35 changed files with 211 additions and 387 deletions
|
|
@ -20,7 +20,6 @@ extern mod extra;
|
|||
use extra::arc;
|
||||
use extra::future::Future;
|
||||
use extra::time;
|
||||
use std::cell::Cell;
|
||||
use std::os;
|
||||
use std::uint;
|
||||
|
||||
|
|
@ -91,12 +90,8 @@ 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);
|
||||
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();
|
||||
thread_ring(i, msg_per_task, num_chan, num_port1)
|
||||
thread_ring(i, msg_per_task, num_chan, num_port)
|
||||
};
|
||||
futures.push(new_future);
|
||||
num_chan = new_chan;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ extern mod extra;
|
|||
use extra::arc;
|
||||
use extra::future::Future;
|
||||
use extra::time;
|
||||
use std::cell::Cell;
|
||||
use std::os;
|
||||
use std::uint;
|
||||
|
||||
|
|
@ -87,12 +86,8 @@ 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);
|
||||
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();
|
||||
thread_ring(i, msg_per_task, num_chan, num_port1)
|
||||
thread_ring(i, msg_per_task, num_chan, num_port)
|
||||
};
|
||||
futures.push(new_future);
|
||||
num_chan = new_chan;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ extern mod extra;
|
|||
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
|
||||
|
|
@ -24,19 +23,14 @@ fn ping_pong_bench(n: uint, m: uint) {
|
|||
|
||||
// Create pairs of tasks that pingpong back and forth.
|
||||
fn run_pair(n: uint) {
|
||||
// Create a stream A->B
|
||||
let (pa,ca) = stream::<()>();
|
||||
// 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);
|
||||
// Create a stream A->B
|
||||
let (pa,ca) = stream::<()>();
|
||||
// Create a stream B->A
|
||||
let (pb,cb) = stream::<()>();
|
||||
|
||||
do spawntask_later() || {
|
||||
let chan = ca.take();
|
||||
let port = pb.take();
|
||||
let chan = ca;
|
||||
let port = pb;
|
||||
n.times(|| {
|
||||
chan.send(());
|
||||
port.recv();
|
||||
|
|
@ -44,8 +38,8 @@ fn ping_pong_bench(n: uint, m: uint) {
|
|||
}
|
||||
|
||||
do spawntask_later() || {
|
||||
let chan = cb.take();
|
||||
let port = pa.take();
|
||||
let chan = cb;
|
||||
let port = pa;
|
||||
n.times(|| {
|
||||
port.recv();
|
||||
chan.send(());
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ extern mod extra;
|
|||
use std::os;
|
||||
use std::uint;
|
||||
use std::rt::test::spawntask_later;
|
||||
use std::cell::Cell;
|
||||
use std::comm::oneshot;
|
||||
|
||||
// A simple implementation of parfib. One subtree is found in a new
|
||||
|
|
@ -26,9 +25,8 @@ fn parfib(n: uint) -> uint {
|
|||
}
|
||||
|
||||
let (port,chan) = oneshot::<uint>();
|
||||
let chan = Cell::new(chan);
|
||||
do spawntask_later {
|
||||
chan.take().send(parfib(n-1));
|
||||
chan.send(parfib(n-1));
|
||||
};
|
||||
let m2 = parfib(n-2);
|
||||
return (port.recv() + m2);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
extern mod extra;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::comm::{stream, SharedChan};
|
||||
use std::option;
|
||||
use std::os;
|
||||
|
|
@ -156,9 +155,11 @@ 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);
|
||||
do task::spawn || {
|
||||
creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(),
|
||||
do task::spawn {
|
||||
creature(ii,
|
||||
col,
|
||||
from_rendezvous,
|
||||
to_rendezvous.clone(),
|
||||
to_rendezvous_log.clone());
|
||||
}
|
||||
to_creature
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
//
|
||||
// The filename is a song reference; google it in quotes.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::comm;
|
||||
use std::os;
|
||||
use std::task;
|
||||
|
|
@ -27,9 +26,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::new(c);
|
||||
do spawn {
|
||||
let c = c.take();
|
||||
if gens_left & 1 == 1 {
|
||||
task::deschedule(); // shake things up a bit
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue