1
Fork 0

Convert more core types to camel case

This commit is contained in:
Brian Anderson 2012-08-15 14:10:46 -07:00
parent af43613795
commit 9c6890f488
57 changed files with 415 additions and 390 deletions

View file

@ -2975,9 +2975,9 @@ the string in response. The child terminates when `0` is received.
Here is the function that implements the child task: Here is the function that implements the child task:
~~~~ ~~~~
# import comm::{port, chan}; # import comm::{Port, port, Chan, chan};
fn stringifier(from_parent: port<uint>, fn stringifier(from_parent: Port<uint>,
to_parent: chan<~str>) { to_parent: Chan<~str>) {
let mut value: uint; let mut value: uint;
loop { loop {
value = from_parent.recv(); value = from_parent.recv();
@ -2999,9 +2999,9 @@ Here is the code for the parent task:
~~~~ ~~~~
# import task::{spawn_conversation}; # import task::{spawn_conversation};
# import comm::{chan, port}; # import comm::{Chan, chan, Port, port};
# fn stringifier(from_parent: comm::port<uint>, # fn stringifier(from_parent: comm::Port<uint>,
# to_parent: comm::chan<~str>) { # to_parent: comm::Chan<~str>) {
# comm::send(to_parent, ~"22"); # comm::send(to_parent, ~"22");
# comm::send(to_parent, ~"23"); # comm::send(to_parent, ~"23");
# comm::send(to_parent, ~"0"); # comm::send(to_parent, ~"0");

View file

@ -62,12 +62,12 @@ fn run(lib_path: ~str,
writeclose(pipe_in.out, input); writeclose(pipe_in.out, input);
let p = pipes::port_set(); let p = pipes::port_set();
let ch = p.chan(); let ch = p.chan();
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in); let errput = readclose(pipe_err.in);
ch.send((2, errput)); ch.send((2, errput));
} }
let ch = p.chan(); let ch = p.chan();
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in); let output = readclose(pipe_out.in);
ch.send((1, output)); ch.send((1, output));
} }

View file

@ -30,8 +30,8 @@
import either::Either; import either::Either;
import libc::size_t; import libc::size_t;
export port; export Port, port;
export chan; export Chan, chan;
export send; export send;
export recv; export recv;
export peek; export peek;
@ -48,8 +48,8 @@ export listen;
* transmitted. If a port value is copied, both copies refer to the same * transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s. * port. Ports may be associated with multiple `chan`s.
*/ */
enum port<T: send> { enum Port<T: send> {
port_t(@port_ptr<T>) Port_(@PortPtr<T>)
} }
// It's critical that this only have one variant, so it has a record // It's critical that this only have one variant, so it has a record
@ -64,27 +64,27 @@ enum port<T: send> {
* data will be silently dropped. Channels may be duplicated and * data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels. * themselves transmitted over other channels.
*/ */
enum chan<T: send> { enum Chan<T: send> {
chan_t(port_id) Chan_(port_id)
} }
/// Constructs a port /// Constructs a port
fn port<T: send>() -> port<T> { fn port<T: send>() -> Port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t))) Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
} }
impl<T: send> port<T> { impl<T: send> Port<T> {
fn chan() -> chan<T> { chan(self) } fn chan() -> Chan<T> { chan(self) }
fn send(+v: T) { self.chan().send(v) } fn send(+v: T) { self.chan().send(v) }
fn recv() -> T { recv(self) } fn recv() -> T { recv(self) }
fn peek() -> bool { peek(self) } fn peek() -> bool { peek(self) }
} }
impl<T: send> chan<T> { impl<T: send> Chan<T> {
fn chan() -> chan<T> { self } fn chan() -> Chan<T> { self }
fn send(+v: T) { send(self, v) } fn send(+v: T) { send(self, v) }
fn recv() -> T { recv_chan(self) } fn recv() -> T { recv_chan(self) }
fn peek() -> bool { peek_chan(self) } fn peek() -> bool { peek_chan(self) }
@ -92,12 +92,12 @@ impl<T: send> chan<T> {
} }
/// Open a new receiving channel for the duration of a function /// Open a new receiving channel for the duration of a function
fn listen<T: send, U>(f: fn(chan<T>) -> U) -> U { fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
let po = port(); let po = port();
f(po.chan()) f(po.chan())
} }
class port_ptr<T:send> { class PortPtr<T:send> {
let po: *rust_port; let po: *rust_port;
new(po: *rust_port) { self.po = po; } new(po: *rust_port) { self.po = po; }
drop unsafe { drop unsafe {
@ -130,9 +130,9 @@ class port_ptr<T:send> {
* Fails if the port is detached or dead. Fails if the port * Fails if the port is detached or dead. Fails if the port
* is owned by a different task. * is owned by a different task.
*/ */
fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U { fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
class portref { class PortRef {
let p: *rust_port; let p: *rust_port;
new(p: *rust_port) { self.p = p; } new(p: *rust_port) { self.p = p; }
drop { drop {
@ -142,7 +142,7 @@ fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
} }
} }
let p = portref(rustrt::rust_port_take(*ch)); let p = PortRef(rustrt::rust_port_take(*ch));
if ptr::is_null(p.p) { if ptr::is_null(p.p) {
fail ~"unable to locate port for channel" fail ~"unable to locate port for channel"
@ -157,16 +157,16 @@ fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
* Constructs a channel. The channel is bound to the port used to * Constructs a channel. The channel is bound to the port used to
* construct it. * construct it.
*/ */
fn chan<T: send>(p: port<T>) -> chan<T> { fn chan<T: send>(p: Port<T>) -> Chan<T> {
chan_t(rustrt::get_port_id((**p).po)) Chan_(rustrt::get_port_id((**p).po))
} }
/** /**
* Sends data over a channel. The sent data is moved into the channel, * Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it. * whereupon the caller loses access to it.
*/ */
fn send<T: send>(ch: chan<T>, +data: T) { fn send<T: send>(ch: Chan<T>, +data: T) {
let chan_t(p) = ch; let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *(); let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr); let res = rustrt::rust_port_id_send(p, data_ptr);
if res != 0u unsafe { if res != 0u unsafe {
@ -180,17 +180,17 @@ fn send<T: send>(ch: chan<T>, +data: T) {
* Receive from a port. If no data is available on the port then the * Receive from a port. If no data is available on the port then the
* task will block until data becomes available. * task will block until data becomes available.
*/ */
fn recv<T: send>(p: port<T>) -> T { recv_((**p).po) } fn recv<T: send>(p: Port<T>) -> T { recv_((**p).po) }
/// Returns true if there are messages available /// Returns true if there are messages available
fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) } fn peek<T: send>(p: Port<T>) -> bool { peek_((**p).po) }
#[doc(hidden)] #[doc(hidden)]
fn recv_chan<T: send>(ch: comm::chan<T>) -> T { fn recv_chan<T: send>(ch: comm::Chan<T>) -> T {
as_raw_port(ch, |x|recv_(x)) as_raw_port(ch, |x|recv_(x))
} }
fn peek_chan<T: send>(ch: comm::chan<T>) -> bool { fn peek_chan<T: send>(ch: comm::Chan<T>) -> bool {
as_raw_port(ch, |x|peek_(x)) as_raw_port(ch, |x|peek_(x))
} }
@ -221,7 +221,7 @@ fn peek_(p: *rust_port) -> bool {
} }
/// Receive on one of two ports /// Receive on one of two ports
fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>) fn select2<A: send, B: send>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> { -> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po]; let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0u, yieldp = ptr::addr_of(yield); let yield = 0u, yieldp = ptr::addr_of(yield);
@ -257,9 +257,10 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
/* Implementation details */ /* Implementation details */
#[allow(non_camel_case_types)] // runtime type
enum rust_port {} enum rust_port {}
#[allow(non_camel_case_types)] // runtime type
type port_id = int; type port_id = int;
#[abi = "cdecl"] #[abi = "cdecl"]
@ -329,7 +330,7 @@ fn chan_chan_infer() {
#[test] #[test]
fn chan_chan() { fn chan_chan() {
let p = port::<chan<int>>(), p2 = port::<int>(); let p = port::<Chan<int>>(), p2 = port::<int>();
let c = chan(p); let c = chan(p);
send(c, chan(p2)); send(c, chan(p2));
recv(p); recv(p);

View file

@ -235,8 +235,11 @@ mod dlist_iter {
mod send_map; mod send_map;
// Concurrency // Concurrency
#[warn(non_camel_case_types)]
mod comm; mod comm;
#[warn(non_camel_case_types)]
mod task; mod task;
//#[warn(non_camel_ase_types)] pipec code continues to trip this warning
mod future; mod future;
mod pipes; mod pipes;

View file

@ -18,7 +18,7 @@
import either::Either; import either::Either;
import pipes::recv; import pipes::recv;
export future; export Future;
export extensions; export extensions;
export from_value; export from_value;
export from_port; export from_port;
@ -31,12 +31,12 @@ export spawn;
export future_pipe; export future_pipe;
#[doc = "The future type"] #[doc = "The future type"]
enum future<A> = { enum Future<A> = {
mut v: Either<@A, fn@() -> A> mut v: Either<@A, fn@() -> A>
}; };
/// Methods on the `future` type /// Methods on the `future` type
impl<A:copy send> future<A> { impl<A:copy send> Future<A> {
fn get() -> A { fn get() -> A {
//! Get the value of the future //! Get the value of the future
@ -51,7 +51,7 @@ impl<A:copy send> future<A> {
} }
} }
fn from_value<A>(+val: A) -> future<A> { fn from_value<A>(+val: A) -> Future<A> {
/*! /*!
* Create a future from a value * Create a future from a value
* *
@ -59,7 +59,7 @@ fn from_value<A>(+val: A) -> future<A> {
* not block. * not block.
*/ */
future({ Future({
mut v: either::Left(@val) mut v: either::Left(@val)
}) })
} }
@ -68,7 +68,7 @@ macro_rules! move_it {
{$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } } {$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } }
} }
fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> future<A> { fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
#[doc = " #[doc = "
Create a future from a port Create a future from a port
@ -87,7 +87,7 @@ fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> future<A> {
} }
} }
fn from_fn<A>(f: fn@() -> A) -> future<A> { fn from_fn<A>(f: fn@() -> A) -> Future<A> {
/*! /*!
* Create a future from a function. * Create a future from a function.
* *
@ -96,12 +96,12 @@ fn from_fn<A>(f: fn@() -> A) -> future<A> {
* function. It is not spawned into another task. * function. It is not spawned into another task.
*/ */
future({ Future({
mut v: either::Right(f) mut v: either::Right(f)
}) })
} }
fn spawn<A:send>(+blk: fn~() -> A) -> future<A> { fn spawn<A:send>(+blk: fn~() -> A) -> Future<A> {
/*! /*!
* Create a future from a unique closure. * Create a future from a unique closure.
* *
@ -114,13 +114,13 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
})) }))
} }
fn get<A:copy>(future: &future<A>) -> A { fn get<A:copy>(future: &Future<A>) -> A {
//! Get the value of the future //! Get the value of the future
do with(future) |v| { *v } do with(future) |v| { *v }
} }
fn with<A,B>(future: &future<A>, blk: fn((&A)) -> B) -> B { fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
//! Work with the value without copying it //! Work with the value without copying it
let v = match copy future.v { let v = match copy future.v {

View file

@ -24,7 +24,7 @@ import option::{some, none};
import getcwd = rustrt::rust_getcwd; import getcwd = rustrt::rust_getcwd;
import consts::*; import consts::*;
import task::task_builder; import task::TaskBuilder;
export close, fclose, fsync_fd, waitpid; export close, fclose, fsync_fd, waitpid;
export env, getenv, setenv, fdopen, pipe; export env, getenv, setenv, fdopen, pipe;
@ -135,9 +135,9 @@ mod global_env {
} }
enum Msg { enum Msg {
MsgGetEnv(~str, comm::chan<option<~str>>), MsgGetEnv(~str, comm::Chan<option<~str>>),
MsgSetEnv(~str, ~str, comm::chan<()>), MsgSetEnv(~str, ~str, comm::Chan<()>),
MsgEnv(comm::chan<~[(~str,~str)]>) MsgEnv(comm::Chan<~[(~str,~str)]>)
} }
fn getenv(n: ~str) -> option<~str> { fn getenv(n: ~str) -> option<~str> {
@ -161,18 +161,18 @@ mod global_env {
comm::recv(po) comm::recv(po)
} }
fn get_global_env_chan() -> comm::chan<Msg> { fn get_global_env_chan() -> comm::Chan<Msg> {
let global_ptr = rustrt::rust_global_env_chan_ptr(); let global_ptr = rustrt::rust_global_env_chan_ptr();
unsafe { unsafe {
priv::chan_from_global_ptr(global_ptr, || { priv::chan_from_global_ptr(global_ptr, || {
// FIXME (#2621): This would be a good place to use a very // FIXME (#2621): This would be a good place to use a very
// small foreign stack // small foreign stack
task::task().sched_mode(task::single_threaded).unlinked() task::task().sched_mode(task::SingleThreaded).unlinked()
}, global_env_task) }, global_env_task)
} }
} }
fn global_env_task(msg_po: comm::port<Msg>) { fn global_env_task(msg_po: comm::Port<Msg>) {
unsafe { unsafe {
do priv::weaken_task |weak_po| { do priv::weaken_task |weak_po| {
loop { loop {

View file

@ -7,7 +7,7 @@
export chan_from_global_ptr, weaken_task; export chan_from_global_ptr, weaken_task;
import compare_and_swap = rustrt::rust_compare_and_swap_ptr; import compare_and_swap = rustrt::rust_compare_and_swap_ptr;
import task::task_builder; import task::TaskBuilder;
#[allow(non_camel_case_types)] // runtime type #[allow(non_camel_case_types)] // runtime type
type rust_port_id = uint; type rust_port_id = uint;
@ -29,9 +29,9 @@ type GlobalPtr = *libc::uintptr_t;
*/ */
unsafe fn chan_from_global_ptr<T: send>( unsafe fn chan_from_global_ptr<T: send>(
global: GlobalPtr, global: GlobalPtr,
task_fn: fn() -> task::task_builder, task_fn: fn() -> task::TaskBuilder,
+f: fn~(comm::port<T>) +f: fn~(comm::Port<T>)
) -> comm::chan<T> { ) -> comm::Chan<T> {
enum Msg { enum Msg {
Proceed, Proceed,
@ -185,7 +185,7 @@ fn test_from_global_chan2() {
* * Weak tasks must not be supervised. A supervised task keeps * * Weak tasks must not be supervised. A supervised task keeps
* a reference to its parent, so the parent will not die. * a reference to its parent, so the parent will not die.
*/ */
unsafe fn weaken_task(f: fn(comm::port<()>)) { unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
unsafe { unsafe {
@ -195,8 +195,8 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
f(po); f(po);
class Unweaken { class Unweaken {
let ch: comm::chan<()>; let ch: comm::Chan<()>;
new(ch: comm::chan<()>) { self.ch = ch; } new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe { drop unsafe {
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch)); rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
} }

View file

@ -173,9 +173,9 @@ impl<T> *T: Ptr {
#[test] #[test]
fn test() { fn test() {
unsafe { unsafe {
type pair = {mut fst: int, mut snd: int}; type Pair = {mut fst: int, mut snd: int};
let p = {mut fst: 10, mut snd: 20}; let p = {mut fst: 10, mut snd: 20};
let pptr: *mut pair = mut_addr_of(p); let pptr: *mut Pair = mut_addr_of(p);
let iptr: *mut int = unsafe::reinterpret_cast(pptr); let iptr: *mut int = unsafe::reinterpret_cast(pptr);
assert (*iptr == 10);; assert (*iptr == 10);;
*iptr = 30; *iptr = 30;

View file

@ -298,11 +298,11 @@ fn program_output(prog: &str, args: &[~str]) ->
// clever way to do this. // clever way to do this.
let p = comm::port(); let p = comm::port();
let ch = comm::chan(p); let ch = comm::chan(p);
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in); let errput = readclose(pipe_err.in);
comm::send(ch, (2, errput)); comm::send(ch, (2, errput));
}; };
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in); let output = readclose(pipe_out.in);
comm::send(ch, (1, output)); comm::send(ch, (1, output));
}; };

View file

@ -29,14 +29,15 @@
import result::result; import result::result;
export task; export Task;
export task_result; export TaskResult;
export notification; export Notification;
export sched_mode; export SchedMode;
export sched_opts; export SchedOpts;
export task_opts; export TaskOpts;
export task_builder; export TaskBuilder;
export task;
export default_task_opts; export default_task_opts;
export get_opts; export get_opts;
export set_opts; export set_opts;
@ -69,16 +70,16 @@ export local_data_get;
export local_data_set; export local_data_set;
export local_data_modify; export local_data_modify;
export single_threaded; export SingleThreaded;
export thread_per_core; export ThreadPerCore;
export thread_per_task; export ThreadPerTask;
export manual_threads; export ManualThreads;
export platform_thread; export PlatformThread;
/* Data types */ /* Data types */
/// A handle to a task /// A handle to a task
enum task { task_handle(task_id) } enum Task { TaskHandle(task_id) }
/** /**
* Indicates the manner in which a task exited. * Indicates the manner in which a task exited.
@ -91,34 +92,34 @@ enum task { task_handle(task_id) }
* If you wish for this result's delivery to block until all linked and/or * If you wish for this result's delivery to block until all linked and/or
* children tasks complete, recommend using a result future. * children tasks complete, recommend using a result future.
*/ */
enum task_result { enum TaskResult {
success, Success,
failure, Failure,
} }
/// A message type for notifying of task lifecycle events /// A message type for notifying of task lifecycle events
enum notification { enum Notification {
/// Sent when a task exits with the task handle and result /// Sent when a task exits with the task handle and result
exit(task, task_result) Exit(Task, TaskResult)
} }
/// Scheduler modes /// Scheduler modes
enum sched_mode { enum SchedMode {
/// All tasks run in the same OS thread /// All tasks run in the same OS thread
single_threaded, SingleThreaded,
/// Tasks are distributed among available CPUs /// Tasks are distributed among available CPUs
thread_per_core, ThreadPerCore,
/// Each task runs in its own OS thread /// Each task runs in its own OS thread
thread_per_task, ThreadPerTask,
/// Tasks are distributed among a fixed number of OS threads /// Tasks are distributed among a fixed number of OS threads
manual_threads(uint), ManualThreads(uint),
/** /**
* Tasks are scheduled on the main OS thread * Tasks are scheduled on the main OS thread
* *
* The main OS thread is the thread used to launch the runtime which, * The main OS thread is the thread used to launch the runtime which,
* in most cases, is the process's initial thread as created by the OS. * in most cases, is the process's initial thread as created by the OS.
*/ */
platform_thread PlatformThread
} }
/** /**
@ -136,8 +137,8 @@ enum sched_mode {
* default these foreign stacks have unspecified size, but with this * default these foreign stacks have unspecified size, but with this
* option their size can be precisely specified. * option their size can be precisely specified.
*/ */
type sched_opts = { type SchedOpts = {
mode: sched_mode, mode: SchedMode,
foreign_stack_size: option<uint> foreign_stack_size: option<uint>
}; };
@ -168,11 +169,11 @@ type sched_opts = {
* into foreign code that blocks. Without doing so in a different * into foreign code that blocks. Without doing so in a different
* scheduler other tasks will be impeded or even blocked indefinitely. * scheduler other tasks will be impeded or even blocked indefinitely.
*/ */
type task_opts = { type TaskOpts = {
linked: bool, linked: bool,
supervised: bool, supervised: bool,
notify_chan: option<comm::chan<notification>>, notify_chan: option<comm::Chan<Notification>>,
sched: option<sched_opts>, sched: option<SchedOpts>,
}; };
/** /**
@ -189,8 +190,8 @@ type task_opts = {
// the run function move them in. // the run function move them in.
// FIXME (#2585): Replace the 'consumed' bit with move mode on self // FIXME (#2585): Replace the 'consumed' bit with move mode on self
enum task_builder = { enum TaskBuilder = {
opts: task_opts, opts: TaskOpts,
gen_body: fn@(+fn~()) -> fn~(), gen_body: fn@(+fn~()) -> fn~(),
can_not_copy: option<util::NonCopyable>, can_not_copy: option<util::NonCopyable>,
mut consumed: bool, mut consumed: bool,
@ -201,8 +202,8 @@ enum task_builder = {
* configuration methods can be chained. * configuration methods can be chained.
* For example, task().unlinked().spawn is equivalent to spawn_unlinked. * For example, task().unlinked().spawn is equivalent to spawn_unlinked.
*/ */
fn task() -> task_builder { fn task() -> TaskBuilder {
task_builder({ TaskBuilder({
opts: default_task_opts(), opts: default_task_opts(),
gen_body: |body| body, // Identity function gen_body: |body| body, // Identity function
can_not_copy: none, can_not_copy: none,
@ -210,23 +211,23 @@ fn task() -> task_builder {
}) })
} }
priv impl task_builder { priv impl TaskBuilder {
fn consume() -> task_builder { fn consume() -> TaskBuilder {
if self.consumed { if self.consumed {
fail ~"Cannot copy a task_builder"; // Fake move mode on self fail ~"Cannot copy a task_builder"; // Fake move mode on self
} }
self.consumed = true; self.consumed = true;
task_builder({ can_not_copy: none, mut consumed: false, with *self }) TaskBuilder({ can_not_copy: none, mut consumed: false, with *self })
} }
} }
impl task_builder { impl TaskBuilder {
/** /**
* Decouple the child task's failure from the parent's. If either fails, * Decouple the child task's failure from the parent's. If either fails,
* the other will not be killed. * the other will not be killed.
*/ */
fn unlinked() -> task_builder { fn unlinked() -> TaskBuilder {
task_builder({ TaskBuilder({
opts: { linked: false with self.opts }, opts: { linked: false with self.opts },
can_not_copy: none, can_not_copy: none,
with *self.consume() with *self.consume()
@ -237,8 +238,8 @@ impl task_builder {
* child's failure will not kill the parent, but the parent's will kill * child's failure will not kill the parent, but the parent's will kill
* the child. * the child.
*/ */
fn supervised() -> task_builder { fn supervised() -> TaskBuilder {
task_builder({ TaskBuilder({
opts: { linked: false, supervised: true with self.opts }, opts: { linked: false, supervised: true with self.opts },
can_not_copy: none, can_not_copy: none,
with *self.consume() with *self.consume()
@ -248,8 +249,8 @@ impl task_builder {
* Link the child task's and parent task's failures. If either fails, the * Link the child task's and parent task's failures. If either fails, the
* other will be killed. * other will be killed.
*/ */
fn linked() -> task_builder { fn linked() -> TaskBuilder {
task_builder({ TaskBuilder({
opts: { linked: true, supervised: false with self.opts }, opts: { linked: true, supervised: false with self.opts },
can_not_copy: none, can_not_copy: none,
with *self.consume() with *self.consume()
@ -273,7 +274,7 @@ impl task_builder {
* # Failure * # Failure
* Fails if a future_result was already set for this task. * Fails if a future_result was already set for this task.
*/ */
fn future_result(blk: fn(+future::future<task_result>)) -> task_builder { fn future_result(blk: fn(+future::Future<TaskResult>)) -> TaskBuilder {
// FIXME (#1087, #1857): Once linked failure and notification are // FIXME (#1087, #1857): Once linked failure and notification are
// handled in the library, I can imagine implementing this by just // handled in the library, I can imagine implementing this by just
// registering an arbitrary number of task::on_exit handlers and // registering an arbitrary number of task::on_exit handlers and
@ -284,25 +285,25 @@ impl task_builder {
} }
// Construct the future and give it to the caller. // Construct the future and give it to the caller.
let po = comm::port::<notification>(); let po = comm::port::<Notification>();
let ch = comm::chan(po); let ch = comm::chan(po);
blk(do future::from_fn { blk(do future::from_fn {
match comm::recv(po) { match comm::recv(po) {
exit(_, result) => result Exit(_, result) => result
} }
}); });
// Reconfigure self to use a notify channel. // Reconfigure self to use a notify channel.
task_builder({ TaskBuilder({
opts: { notify_chan: some(ch) with self.opts }, opts: { notify_chan: some(ch) with self.opts },
can_not_copy: none, can_not_copy: none,
with *self.consume() with *self.consume()
}) })
} }
/// Configure a custom scheduler mode for the task. /// Configure a custom scheduler mode for the task.
fn sched_mode(mode: sched_mode) -> task_builder { fn sched_mode(mode: SchedMode) -> TaskBuilder {
task_builder({ TaskBuilder({
opts: { sched: some({ mode: mode, foreign_stack_size: none}) opts: { sched: some({ mode: mode, foreign_stack_size: none})
with self.opts }, with self.opts },
can_not_copy: none, can_not_copy: none,
@ -322,9 +323,9 @@ impl task_builder {
* generator by applying the task body which results from the * generator by applying the task body which results from the
* existing body generator to the new body generator. * existing body generator to the new body generator.
*/ */
fn add_wrapper(wrapper: fn@(+fn~()) -> fn~()) -> task_builder { fn add_wrapper(wrapper: fn@(+fn~()) -> fn~()) -> TaskBuilder {
let prev_gen_body = self.gen_body; let prev_gen_body = self.gen_body;
task_builder({ TaskBuilder({
gen_body: |body| { wrapper(prev_gen_body(body)) }, gen_body: |body| { wrapper(prev_gen_body(body)) },
can_not_copy: none, can_not_copy: none,
with *self.consume() with *self.consume()
@ -366,7 +367,7 @@ impl task_builder {
* otherwise be required to establish communication from the parent * otherwise be required to establish communication from the parent
* to the child. * to the child.
*/ */
fn spawn_listener<A: send>(+f: fn~(comm::port<A>)) -> comm::chan<A> { fn spawn_listener<A: send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
let setup_po = comm::port(); let setup_po = comm::port();
let setup_ch = comm::chan(setup_po); let setup_ch = comm::chan(setup_po);
do self.spawn { do self.spawn {
@ -382,8 +383,8 @@ impl task_builder {
* Runs a new task, setting up communication in both directions * Runs a new task, setting up communication in both directions
*/ */
fn spawn_conversation<A: send, B: send> fn spawn_conversation<A: send, B: send>
(+f: fn~(comm::port<A>, comm::chan<B>)) (+f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::port<B>, comm::chan<A>) { -> (comm::Port<B>, comm::Chan<A>) {
let from_child = comm::port(); let from_child = comm::port();
let to_parent = comm::chan(from_child); let to_parent = comm::chan(from_child);
let to_child = do self.spawn_listener |from_parent| { let to_child = do self.spawn_listener |from_parent| {
@ -414,8 +415,8 @@ impl task_builder {
comm::send(ch, f()); comm::send(ch, f());
} }
match future::get(&option::unwrap(result)) { match future::get(&option::unwrap(result)) {
success => result::ok(comm::recv(po)), Success => result::ok(comm::recv(po)),
failure => result::err(()) Failure => result::err(())
} }
} }
} }
@ -423,7 +424,7 @@ impl task_builder {
/* Task construction */ /* Task construction */
fn default_task_opts() -> task_opts { fn default_task_opts() -> TaskOpts {
/*! /*!
* The default task options * The default task options
* *
@ -486,7 +487,7 @@ fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
task().spawn_with(arg, f) task().spawn_with(arg, f)
} }
fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> { fn spawn_listener<A:send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
/*! /*!
* Runs a new task while providing a channel from the parent to the child * Runs a new task while providing a channel from the parent to the child
* *
@ -497,8 +498,8 @@ fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> {
} }
fn spawn_conversation<A: send, B: send> fn spawn_conversation<A: send, B: send>
(+f: fn~(comm::port<A>, comm::chan<B>)) (+f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::port<B>, comm::chan<A>) { -> (comm::Port<B>, comm::Chan<A>) {
/*! /*!
* Runs a new task, setting up communication in both directions * Runs a new task, setting up communication in both directions
* *
@ -508,7 +509,7 @@ fn spawn_conversation<A: send, B: send>
task().spawn_conversation(f) task().spawn_conversation(f)
} }
fn spawn_sched(mode: sched_mode, +f: fn~()) { fn spawn_sched(mode: SchedMode, +f: fn~()) {
/*! /*!
* Creates a new scheduler and executes a task on it * Creates a new scheduler and executes a task on it
* *
@ -555,10 +556,10 @@ fn failing() -> bool {
rustrt::rust_task_is_unwinding(rustrt::rust_get_task()) rustrt::rust_task_is_unwinding(rustrt::rust_get_task())
} }
fn get_task() -> task { fn get_task() -> Task {
//! Get a handle to the running task //! Get a handle to the running task
task_handle(rustrt::get_task_id()) TaskHandle(rustrt::get_task_id())
} }
/** /**
@ -577,28 +578,28 @@ fn get_task() -> task {
* ~~~ * ~~~
*/ */
unsafe fn unkillable<U>(f: fn() -> U) -> U { unsafe fn unkillable<U>(f: fn() -> U) -> U {
class allow_failure { class AllowFailure {
let t: *rust_task; let t: *rust_task;
new(t: *rust_task) { self.t = t; } new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_allow_kill(self.t); } drop { rustrt::rust_task_allow_kill(self.t); }
} }
let t = rustrt::rust_get_task(); let t = rustrt::rust_get_task();
let _allow_failure = allow_failure(t); let _allow_failure = AllowFailure(t);
rustrt::rust_task_inhibit_kill(t); rustrt::rust_task_inhibit_kill(t);
f() f()
} }
/// The inverse of unkillable. Only ever to be used nested in unkillable(). /// The inverse of unkillable. Only ever to be used nested in unkillable().
unsafe fn rekillable<U>(f: fn() -> U) -> U { unsafe fn rekillable<U>(f: fn() -> U) -> U {
class disallow_failure { class DisallowFailure {
let t: *rust_task; let t: *rust_task;
new(t: *rust_task) { self.t = t; } new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_inhibit_kill(self.t); } drop { rustrt::rust_task_inhibit_kill(self.t); }
} }
let t = rustrt::rust_get_task(); let t = rustrt::rust_get_task();
let _allow_failure = disallow_failure(t); let _allow_failure = DisallowFailure(t);
rustrt::rust_task_allow_kill(t); rustrt::rust_task_allow_kill(t);
f() f()
} }
@ -608,7 +609,7 @@ unsafe fn rekillable<U>(f: fn() -> U) -> U {
* For use with exclusive ARCs, which use pthread mutexes directly. * For use with exclusive ARCs, which use pthread mutexes directly.
*/ */
unsafe fn atomically<U>(f: fn() -> U) -> U { unsafe fn atomically<U>(f: fn() -> U) -> U {
class defer_interrupts { class DeferInterrupts {
let t: *rust_task; let t: *rust_task;
new(t: *rust_task) { self.t = t; } new(t: *rust_task) { self.t = t; }
drop { drop {
@ -617,7 +618,7 @@ unsafe fn atomically<U>(f: fn() -> U) -> U {
} }
} }
let t = rustrt::rust_get_task(); let t = rustrt::rust_get_task();
let _interrupts = defer_interrupts(t); let _interrupts = DeferInterrupts(t);
rustrt::rust_task_inhibit_kill(t); rustrt::rust_task_inhibit_kill(t);
rustrt::rust_task_inhibit_yield(t); rustrt::rust_task_inhibit_yield(t);
f() f()
@ -685,17 +686,21 @@ unsafe fn atomically<U>(f: fn() -> U) -> U {
* *
****************************************************************************/ ****************************************************************************/
#[allow(non_camel_case_types)] // runtime type
type sched_id = int; type sched_id = int;
#[allow(non_camel_case_types)] // runtime type
type task_id = int; type task_id = int;
// These are both opaque runtime/compiler types that we don't know the // These are both opaque runtime/compiler types that we don't know the
// structure of and should only deal with via unsafe pointer // structure of and should only deal with via unsafe pointer
#[allow(non_camel_case_types)] // runtime type
type rust_task = libc::c_void; type rust_task = libc::c_void;
#[allow(non_camel_case_types)] // runtime type
type rust_closure = libc::c_void; type rust_closure = libc::c_void;
type taskset = send_map::linear::LinearMap<*rust_task,()>; type TaskSet = send_map::linear::LinearMap<*rust_task,()>;
fn new_taskset() -> taskset { fn new_taskset() -> TaskSet {
pure fn task_hash(t: &*rust_task) -> uint { pure fn task_hash(t: &*rust_task) -> uint {
let task: *rust_task = *t; let task: *rust_task = *t;
hash::hash_uint(task as uint) as uint hash::hash_uint(task as uint) as uint
@ -708,33 +713,33 @@ fn new_taskset() -> taskset {
send_map::linear::linear_map(task_hash, task_eq) send_map::linear::linear_map(task_hash, task_eq)
} }
fn taskset_insert(tasks: &mut taskset, task: *rust_task) { fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
let didnt_overwrite = tasks.insert(task, ()); let didnt_overwrite = tasks.insert(task, ());
assert didnt_overwrite; assert didnt_overwrite;
} }
fn taskset_remove(tasks: &mut taskset, task: *rust_task) { fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
let was_present = tasks.remove(&task); let was_present = tasks.remove(&task);
assert was_present; assert was_present;
} }
fn taskset_each(tasks: &taskset, blk: fn(+*rust_task) -> bool) { fn taskset_each(tasks: &TaskSet, blk: fn(+*rust_task) -> bool) {
tasks.each_key(blk) tasks.each_key(blk)
} }
// One of these per group of linked-failure tasks. // One of these per group of linked-failure tasks.
type taskgroup_data = { type TaskGroupData = {
// All tasks which might kill this group. When this is empty, the group // All tasks which might kill this group. When this is empty, the group
// can be "GC"ed (i.e., its link in the ancestor list can be removed). // can be "GC"ed (i.e., its link in the ancestor list can be removed).
mut members: taskset, mut members: TaskSet,
// All tasks unidirectionally supervised by (directly or transitively) // All tasks unidirectionally supervised by (directly or transitively)
// tasks in this group. // tasks in this group.
mut descendants: taskset, mut descendants: TaskSet,
}; };
type taskgroup_arc = unsafe::Exclusive<option<taskgroup_data>>; type TaskGroupArc = unsafe::Exclusive<option<TaskGroupData>>;
type taskgroup_inner = &mut option<taskgroup_data>; type TaskGroupInner = &mut option<TaskGroupData>;
// A taskgroup is 'dead' when nothing can cause it to fail; only members can. // A taskgroup is 'dead' when nothing can cause it to fail; only members can.
pure fn taskgroup_is_dead(tg: &taskgroup_data) -> bool { pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
(&tg.members).is_empty() (&tg.members).is_empty()
} }
@ -745,7 +750,7 @@ pure fn taskgroup_is_dead(tg: &taskgroup_data) -> bool {
// taskgroup which was spawned-unlinked. Tasks from intermediate generations // taskgroup which was spawned-unlinked. Tasks from intermediate generations
// have references to the middle of the list; when intermediate generations // have references to the middle of the list; when intermediate generations
// die, their node in the list will be collected at a descendant's spawn-time. // die, their node in the list will be collected at a descendant's spawn-time.
type ancestor_node = { type AncestorNode = {
// Since the ancestor list is recursive, we end up with references to // Since the ancestor list is recursive, we end up with references to
// exclusives within other exclusives. This is dangerous business (if // exclusives within other exclusives. This is dangerous business (if
// circular references arise, deadlock and memory leaks are imminent). // circular references arise, deadlock and memory leaks are imminent).
@ -754,20 +759,20 @@ type ancestor_node = {
// FIXME(#3068): Make the generation counter togglable with #[cfg(debug)]. // FIXME(#3068): Make the generation counter togglable with #[cfg(debug)].
generation: uint, generation: uint,
// Should really be an immutable non-option. This way appeases borrowck. // Should really be an immutable non-option. This way appeases borrowck.
mut parent_group: option<taskgroup_arc>, mut parent_group: option<TaskGroupArc>,
// Recursive rest of the list. // Recursive rest of the list.
mut ancestors: ancestor_list, mut ancestors: AncestorList,
}; };
enum ancestor_list = option<unsafe::Exclusive<ancestor_node>>; enum AncestorList = option<unsafe::Exclusive<AncestorNode>>;
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
#[inline(always)] #[inline(always)]
fn access_group<U>(x: taskgroup_arc, blk: fn(taskgroup_inner) -> U) -> U { fn access_group<U>(x: TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U {
unsafe { x.with(blk) } unsafe { x.with(blk) }
} }
#[inline(always)] #[inline(always)]
fn access_ancestors<U>(x: unsafe::Exclusive<ancestor_node>, fn access_ancestors<U>(x: unsafe::Exclusive<AncestorNode>,
blk: fn(x: &mut ancestor_node) -> U) -> U { blk: fn(x: &mut AncestorNode) -> U) -> U {
unsafe { x.with(blk) } unsafe { x.with(blk) }
} }
@ -779,21 +784,21 @@ fn access_ancestors<U>(x: unsafe::Exclusive<ancestor_node>,
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
// FIXME(#2190): Change option<fn@(...)> to option<fn&(...)>, to save on // FIXME(#2190): Change option<fn@(...)> to option<fn&(...)>, to save on
// allocations. Once that bug is fixed, changing the sigil should suffice. // allocations. Once that bug is fixed, changing the sigil should suffice.
fn each_ancestor(list: &mut ancestor_list, fn each_ancestor(list: &mut AncestorList,
bail_opt: option<fn@(taskgroup_inner)>, bail_opt: option<fn@(TaskGroupInner)>,
forward_blk: fn(taskgroup_inner) -> bool) forward_blk: fn(TaskGroupInner) -> bool)
-> bool { -> bool {
// "Kickoff" call - there was no last generation. // "Kickoff" call - there was no last generation.
return !coalesce(list, bail_opt, forward_blk, uint::max_value); return !coalesce(list, bail_opt, forward_blk, uint::max_value);
// Recursively iterates, and coalesces afterwards if needed. Returns // Recursively iterates, and coalesces afterwards if needed. Returns
// whether or not unwinding is needed (i.e., !successful iteration). // whether or not unwinding is needed (i.e., !successful iteration).
fn coalesce(list: &mut ancestor_list, fn coalesce(list: &mut AncestorList,
bail_opt: option<fn@(taskgroup_inner)>, bail_opt: option<fn@(TaskGroupInner)>,
forward_blk: fn(taskgroup_inner) -> bool, forward_blk: fn(TaskGroupInner) -> bool,
last_generation: uint) -> bool { last_generation: uint) -> bool {
// Need to swap the list out to use it, to appease borrowck. // Need to swap the list out to use it, to appease borrowck.
let tmp_list = util::replace(list, ancestor_list(none)); let tmp_list = util::replace(list, AncestorList(none));
let (coalesce_this, early_break) = let (coalesce_this, early_break) =
iterate(tmp_list, bail_opt, forward_blk, last_generation); iterate(tmp_list, bail_opt, forward_blk, last_generation);
// What should our next ancestor end up being? // What should our next ancestor end up being?
@ -816,10 +821,10 @@ fn each_ancestor(list: &mut ancestor_list,
// bool: // bool:
// True if the supplied block did 'break', here or in any recursive // True if the supplied block did 'break', here or in any recursive
// calls. If so, must call the unwinder on all previous nodes. // calls. If so, must call the unwinder on all previous nodes.
fn iterate(ancestors: ancestor_list, fn iterate(ancestors: AncestorList,
bail_opt: option<fn@(taskgroup_inner)>, bail_opt: option<fn@(TaskGroupInner)>,
forward_blk: fn(taskgroup_inner) -> bool, forward_blk: fn(TaskGroupInner) -> bool,
last_generation: uint) -> (option<ancestor_list>, bool) { last_generation: uint) -> (option<AncestorList>, bool) {
// At each step of iteration, three booleans are at play which govern // At each step of iteration, three booleans are at play which govern
// how the iteration should behave. // how the iteration should behave.
// 'nobe_is_dead' - Should the list should be coalesced at this point? // 'nobe_is_dead' - Should the list should be coalesced at this point?
@ -885,7 +890,7 @@ fn each_ancestor(list: &mut ancestor_list,
if nobe_is_dead { if nobe_is_dead {
// Swap the list out here; the caller replaces us with it. // Swap the list out here; the caller replaces us with it.
let rest = util::replace(&mut nobe.ancestors, let rest = util::replace(&mut nobe.ancestors,
ancestor_list(none)); AncestorList(none));
(some(rest), need_unwind) (some(rest), need_unwind)
} else { } else {
(none, need_unwind) (none, need_unwind)
@ -894,8 +899,8 @@ fn each_ancestor(list: &mut ancestor_list,
}; };
// Wrapper around exclusive::with that appeases borrowck. // Wrapper around exclusive::with that appeases borrowck.
fn with_parent_tg<U>(parent_group: &mut option<taskgroup_arc>, fn with_parent_tg<U>(parent_group: &mut option<TaskGroupArc>,
blk: fn(taskgroup_inner) -> U) -> U { blk: fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside. // If this trips, more likely the problem is 'blk' failed inside.
let tmp_arc = option::swap_unwrap(parent_group); let tmp_arc = option::swap_unwrap(parent_group);
let result = do access_group(tmp_arc) |tg_opt| { blk(tg_opt) }; let result = do access_group(tmp_arc) |tg_opt| { blk(tg_opt) };
@ -906,16 +911,16 @@ fn each_ancestor(list: &mut ancestor_list,
} }
// One of these per task. // One of these per task.
class tcb { class Tcb {
let me: *rust_task; let me: *rust_task;
// List of tasks with whose fates this one's is intertwined. // List of tasks with whose fates this one's is intertwined.
let tasks: taskgroup_arc; // 'none' means the group has failed. let tasks: TaskGroupArc; // 'none' means the group has failed.
// Lists of tasks who will kill us if they fail, but whom we won't kill. // Lists of tasks who will kill us if they fail, but whom we won't kill.
let mut ancestors: ancestor_list; let mut ancestors: AncestorList;
let is_main: bool; let is_main: bool;
let notifier: option<auto_notify>; let notifier: option<AutoNotify>;
new(me: *rust_task, -tasks: taskgroup_arc, -ancestors: ancestor_list, new(me: *rust_task, -tasks: TaskGroupArc, -ancestors: AncestorList,
is_main: bool, -notifier: option<auto_notify>) { is_main: bool, -notifier: option<AutoNotify>) {
self.me = me; self.me = me;
self.tasks = tasks; self.tasks = tasks;
self.ancestors = ancestors; self.ancestors = ancestors;
@ -947,20 +952,20 @@ class tcb {
} }
} }
class auto_notify { class AutoNotify {
let notify_chan: comm::chan<notification>; let notify_chan: comm::Chan<Notification>;
let mut failed: bool; let mut failed: bool;
new(chan: comm::chan<notification>) { new(chan: comm::Chan<Notification>) {
self.notify_chan = chan; self.notify_chan = chan;
self.failed = true; // Un-set above when taskgroup successfully made. self.failed = true; // Un-set above when taskgroup successfully made.
} }
drop { drop {
let result = if self.failed { failure } else { success }; let result = if self.failed { Failure } else { Success };
comm::send(self.notify_chan, exit(get_task(), result)); comm::send(self.notify_chan, Exit(get_task(), result));
} }
} }
fn enlist_in_taskgroup(state: taskgroup_inner, me: *rust_task, fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
is_member: bool) -> bool { is_member: bool) -> bool {
let newstate = util::replace(state, none); let newstate = util::replace(state, none);
// If 'none', the group was failing. Can't enlist. // If 'none', the group was failing. Can't enlist.
@ -976,7 +981,7 @@ fn enlist_in_taskgroup(state: taskgroup_inner, me: *rust_task,
} }
// NB: Runs in destructor/post-exit context. Can't 'fail'. // NB: Runs in destructor/post-exit context. Can't 'fail'.
fn leave_taskgroup(state: taskgroup_inner, me: *rust_task, is_member: bool) { fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) {
let newstate = util::replace(state, none); let newstate = util::replace(state, none);
// If 'none', already failing and we've already gotten a kill signal. // If 'none', already failing and we've already gotten a kill signal.
if newstate.is_some() { if newstate.is_some() {
@ -988,7 +993,7 @@ fn leave_taskgroup(state: taskgroup_inner, me: *rust_task, is_member: bool) {
} }
// NB: Runs in destructor/post-exit context. Can't 'fail'. // NB: Runs in destructor/post-exit context. Can't 'fail'.
fn kill_taskgroup(state: taskgroup_inner, me: *rust_task, is_main: bool) { fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
// NB: We could do the killing iteration outside of the group arc, by // NB: We could do the killing iteration outside of the group arc, by
// having "let mut newstate" here, swapping inside, and iterating after. // having "let mut newstate" here, swapping inside, and iterating after.
// But that would let other exiting tasks fall-through and exit while we // But that would let other exiting tasks fall-through and exit while we
@ -1031,7 +1036,7 @@ macro_rules! taskgroup_key {
} }
fn gen_child_taskgroup(linked: bool, supervised: bool) fn gen_child_taskgroup(linked: bool, supervised: bool)
-> (taskgroup_arc, ancestor_list, bool) { -> (TaskGroupArc, AncestorList, bool) {
let spawner = rustrt::rust_get_task(); let spawner = rustrt::rust_get_task();
/*######################################################################* /*######################################################################*
* Step 1. Get spawner's taskgroup info. * Step 1. Get spawner's taskgroup info.
@ -1047,7 +1052,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
mut descendants: new_taskset() })); mut descendants: new_taskset() }));
// Main task/group has no ancestors, no notifier, etc. // Main task/group has no ancestors, no notifier, etc.
let group = let group =
@tcb(spawner, tasks, ancestor_list(none), true, none); @Tcb(spawner, tasks, AncestorList(none), true, none);
unsafe { local_set(spawner, taskgroup_key!(), group); } unsafe { local_set(spawner, taskgroup_key!(), group); }
group group
} }
@ -1080,18 +1085,18 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
}; };
assert new_generation < uint::max_value; assert new_generation < uint::max_value;
// Build a new node in the ancestor list. // Build a new node in the ancestor list.
ancestor_list(some(unsafe::exclusive( AncestorList(some(unsafe::exclusive(
{ generation: new_generation, { generation: new_generation,
mut parent_group: some(spawner_group.tasks.clone()), mut parent_group: some(spawner_group.tasks.clone()),
mut ancestors: old_ancestors }))) mut ancestors: old_ancestors })))
} else { } else {
// Child has no ancestors. // Child has no ancestors.
ancestor_list(none) AncestorList(none)
}; };
(g,a, false) (g,a, false)
}; };
fn share_ancestors(ancestors: &mut ancestor_list) -> ancestor_list { fn share_ancestors(ancestors: &mut AncestorList) -> AncestorList {
// Appease the borrow-checker. Really this wants to be written as: // Appease the borrow-checker. Really this wants to be written as:
// match ancestors // match ancestors
// some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) } // some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) }
@ -1101,14 +1106,14 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
let ancestor_arc = option::unwrap(tmp); let ancestor_arc = option::unwrap(tmp);
let result = ancestor_arc.clone(); let result = ancestor_arc.clone();
**ancestors <- some(ancestor_arc); **ancestors <- some(ancestor_arc);
ancestor_list(some(result)) AncestorList(some(result))
} else { } else {
ancestor_list(none) AncestorList(none)
} }
} }
} }
fn spawn_raw(+opts: task_opts, +f: fn~()) { fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
let (child_tg, ancestors, is_main) = let (child_tg, ancestors, is_main) =
gen_child_taskgroup(opts.linked, opts.supervised); gen_child_taskgroup(opts.linked, opts.supervised);
@ -1146,9 +1151,9 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
// (3a) If any of those fails, it leaves all groups, and does nothing. // (3a) If any of those fails, it leaves all groups, and does nothing.
// (3b) Otherwise it builds a task control structure and puts it in TLS, // (3b) Otherwise it builds a task control structure and puts it in TLS,
// (4) ...and runs the provided body function. // (4) ...and runs the provided body function.
fn make_child_wrapper(child: *rust_task, +child_arc: taskgroup_arc, fn make_child_wrapper(child: *rust_task, +child_arc: TaskGroupArc,
+ancestors: ancestor_list, is_main: bool, +ancestors: AncestorList, is_main: bool,
notify_chan: option<comm::chan<notification>>, notify_chan: option<comm::Chan<Notification>>,
+f: fn~()) -> fn~() { +f: fn~()) -> fn~() {
let child_data = ~mut some((child_arc, ancestors)); let child_data = ~mut some((child_arc, ancestors));
return fn~() { return fn~() {
@ -1158,10 +1163,10 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
// Even if the below code fails to kick the child off, we must // Even if the below code fails to kick the child off, we must
// send something on the notify channel. // send something on the notify channel.
let notifier = notify_chan.map(|c| auto_notify(c)); let notifier = notify_chan.map(|c| AutoNotify(c));
if enlist_many(child, child_arc, &mut ancestors) { if enlist_many(child, child_arc, &mut ancestors) {
let group = @tcb(child, child_arc, ancestors, let group = @Tcb(child, child_arc, ancestors,
is_main, notifier); is_main, notifier);
unsafe { local_set(child, taskgroup_key!(), group); } unsafe { local_set(child, taskgroup_key!(), group); }
// Run the child's body. // Run the child's body.
@ -1173,8 +1178,8 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
// Set up membership in taskgroup and descendantship in all ancestor // Set up membership in taskgroup and descendantship in all ancestor
// groups. If any enlistment fails, some task was already failing, so // groups. If any enlistment fails, some task was already failing, so
// don't let the child task run, and undo every successful enlistment. // don't let the child task run, and undo every successful enlistment.
fn enlist_many(child: *rust_task, child_arc: taskgroup_arc, fn enlist_many(child: *rust_task, child_arc: TaskGroupArc,
ancestors: &mut ancestor_list) -> bool { ancestors: &mut AncestorList) -> bool {
// Join this taskgroup. // Join this taskgroup.
let mut result = let mut result =
do access_group(child_arc) |child_tg| { do access_group(child_arc) |child_tg| {
@ -1203,29 +1208,29 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
} }
} }
fn new_task_in_new_sched(opts: sched_opts) -> *rust_task { fn new_task_in_new_sched(opts: SchedOpts) -> *rust_task {
if opts.foreign_stack_size != none { if opts.foreign_stack_size != none {
fail ~"foreign_stack_size scheduler option unimplemented"; fail ~"foreign_stack_size scheduler option unimplemented";
} }
let num_threads = match opts.mode { let num_threads = match opts.mode {
single_threaded => 1u, SingleThreaded => 1u,
thread_per_core => { ThreadPerCore => {
fail ~"thread_per_core scheduling mode unimplemented" fail ~"thread_per_core scheduling mode unimplemented"
} }
thread_per_task => { ThreadPerTask => {
fail ~"thread_per_task scheduling mode unimplemented" fail ~"thread_per_task scheduling mode unimplemented"
} }
manual_threads(threads) => { ManualThreads(threads) => {
if threads == 0u { if threads == 0u {
fail ~"can not create a scheduler with no threads"; fail ~"can not create a scheduler with no threads";
} }
threads threads
} }
platform_thread => 0u /* Won't be used */ PlatformThread => 0u /* Won't be used */
}; };
let sched_id = if opts.mode != platform_thread { let sched_id = if opts.mode != PlatformThread {
rustrt::rust_new_sched(num_threads) rustrt::rust_new_sched(num_threads)
} else { } else {
rustrt::rust_osmain_sched_id() rustrt::rust_osmain_sched_id()
@ -1262,26 +1267,26 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
* *
* These two cases aside, the interface is safe. * These two cases aside, the interface is safe.
*/ */
type local_data_key<T: owned> = &fn(+@T); type LocalDataKey<T: owned> = &fn(+@T);
trait local_data { } trait LocalData { }
impl<T: owned> @T: local_data { } impl<T: owned> @T: LocalData { }
// We use dvec because it's the best data structure in core. If TLS is used // We use dvec because it's the best data structure in core. If TLS is used
// heavily in future, this could be made more efficient with a proper map. // heavily in future, this could be made more efficient with a proper map.
type task_local_element = (*libc::c_void, *libc::c_void, local_data); type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
// Has to be a pointer at outermost layer; the foreign call returns void *. // Has to be a pointer at outermost layer; the foreign call returns void *.
type task_local_map = @dvec::DVec<option<task_local_element>>; type TaskLocalMap = @dvec::DVec<option<TaskLocalElement>>;
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
assert !map_ptr.is_null(); assert !map_ptr.is_null();
// Get and keep the single reference that was created at the beginning. // Get and keep the single reference that was created at the beginning.
let _map: task_local_map = unsafe::reinterpret_cast(map_ptr); let _map: TaskLocalMap = unsafe::reinterpret_cast(map_ptr);
// All local_data will be destroyed along with the map. // All local_data will be destroyed along with the map.
} }
// Gets the map from the runtime. Lazily initialises if not done so already. // Gets the map from the runtime. Lazily initialises if not done so already.
unsafe fn get_task_local_map(task: *rust_task) -> task_local_map { unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
// Relies on the runtime initialising the pointer to null. // Relies on the runtime initialising the pointer to null.
// NOTE: The map's box lives in TLS invisibly referenced once. Each time // NOTE: The map's box lives in TLS invisibly referenced once. Each time
@ -1289,7 +1294,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> task_local_map {
// drop when they finish. No "re-storing after modifying" is needed. // drop when they finish. No "re-storing after modifying" is needed.
let map_ptr = rustrt::rust_get_task_local_data(task); let map_ptr = rustrt::rust_get_task_local_data(task);
if map_ptr.is_null() { if map_ptr.is_null() {
let map: task_local_map = @dvec::dvec(); let map: TaskLocalMap = @dvec::dvec();
// Use reinterpret_cast -- transmute would take map away from us also. // Use reinterpret_cast -- transmute would take map away from us also.
rustrt::rust_set_task_local_data(task, unsafe::reinterpret_cast(map)); rustrt::rust_set_task_local_data(task, unsafe::reinterpret_cast(map));
rustrt::rust_task_local_data_atexit(task, cleanup_task_local_map); rustrt::rust_task_local_data_atexit(task, cleanup_task_local_map);
@ -1304,7 +1309,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> task_local_map {
} }
unsafe fn key_to_key_value<T: owned>( unsafe fn key_to_key_value<T: owned>(
key: local_data_key<T>) -> *libc::c_void { key: LocalDataKey<T>) -> *libc::c_void {
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
// Use reintepret_cast -- transmute would leak (forget) the closure. // Use reintepret_cast -- transmute would leak (forget) the closure.
@ -1314,7 +1319,7 @@ unsafe fn key_to_key_value<T: owned>(
// If returning some(..), returns with @T with the map's reference. Careful! // If returning some(..), returns with @T with the map's reference. Careful!
unsafe fn local_data_lookup<T: owned>( unsafe fn local_data_lookup<T: owned>(
map: task_local_map, key: local_data_key<T>) map: TaskLocalMap, key: LocalDataKey<T>)
-> option<(uint, *libc::c_void)> { -> option<(uint, *libc::c_void)> {
let key_value = key_to_key_value(key); let key_value = key_to_key_value(key);
@ -1332,7 +1337,7 @@ unsafe fn local_data_lookup<T: owned>(
} }
unsafe fn local_get_helper<T: owned>( unsafe fn local_get_helper<T: owned>(
task: *rust_task, key: local_data_key<T>, task: *rust_task, key: LocalDataKey<T>,
do_pop: bool) -> option<@T> { do_pop: bool) -> option<@T> {
let map = get_task_local_map(task); let map = get_task_local_map(task);
@ -1354,20 +1359,20 @@ unsafe fn local_get_helper<T: owned>(
unsafe fn local_pop<T: owned>( unsafe fn local_pop<T: owned>(
task: *rust_task, task: *rust_task,
key: local_data_key<T>) -> option<@T> { key: LocalDataKey<T>) -> option<@T> {
local_get_helper(task, key, true) local_get_helper(task, key, true)
} }
unsafe fn local_get<T: owned>( unsafe fn local_get<T: owned>(
task: *rust_task, task: *rust_task,
key: local_data_key<T>) -> option<@T> { key: LocalDataKey<T>) -> option<@T> {
local_get_helper(task, key, false) local_get_helper(task, key, false)
} }
unsafe fn local_set<T: owned>( unsafe fn local_set<T: owned>(
task: *rust_task, key: local_data_key<T>, +data: @T) { task: *rust_task, key: LocalDataKey<T>, +data: @T) {
let map = get_task_local_map(task); let map = get_task_local_map(task);
// Store key+data as *voids. Data is invisibly referenced once; key isn't. // Store key+data as *voids. Data is invisibly referenced once; key isn't.
@ -1378,7 +1383,7 @@ unsafe fn local_set<T: owned>(
// does not have a reference associated with it, so it may become invalid // does not have a reference associated with it, so it may become invalid
// when the box is destroyed. // when the box is destroyed.
let data_ptr = unsafe::reinterpret_cast(data); let data_ptr = unsafe::reinterpret_cast(data);
let data_box = data as local_data; let data_box = data as LocalData;
// Construct new entry to store in the map. // Construct new entry to store in the map.
let new_entry = some((keyval, data_ptr, data_box)); let new_entry = some((keyval, data_ptr, data_box));
// Find a place to put it. // Find a place to put it.
@ -1399,7 +1404,7 @@ unsafe fn local_set<T: owned>(
} }
unsafe fn local_modify<T: owned>( unsafe fn local_modify<T: owned>(
task: *rust_task, key: local_data_key<T>, task: *rust_task, key: LocalDataKey<T>,
modify_fn: fn(option<@T>) -> option<@T>) { modify_fn: fn(option<@T>) -> option<@T>) {
// Could be more efficient by doing the lookup work, but this is easy. // Could be more efficient by doing the lookup work, but this is easy.
@ -1415,7 +1420,7 @@ unsafe fn local_modify<T: owned>(
* reference that was originally created to insert it. * reference that was originally created to insert it.
*/ */
unsafe fn local_data_pop<T: owned>( unsafe fn local_data_pop<T: owned>(
key: local_data_key<T>) -> option<@T> { key: LocalDataKey<T>) -> option<@T> {
local_pop(rustrt::rust_get_task(), key) local_pop(rustrt::rust_get_task(), key)
} }
@ -1424,7 +1429,7 @@ unsafe fn local_data_pop<T: owned>(
* table until explicitly removed. * table until explicitly removed.
*/ */
unsafe fn local_data_get<T: owned>( unsafe fn local_data_get<T: owned>(
key: local_data_key<T>) -> option<@T> { key: LocalDataKey<T>) -> option<@T> {
local_get(rustrt::rust_get_task(), key) local_get(rustrt::rust_get_task(), key)
} }
@ -1433,7 +1438,7 @@ unsafe fn local_data_get<T: owned>(
* that value is overwritten (and its destructor is run). * that value is overwritten (and its destructor is run).
*/ */
unsafe fn local_data_set<T: owned>( unsafe fn local_data_set<T: owned>(
key: local_data_key<T>, +data: @T) { key: LocalDataKey<T>, +data: @T) {
local_set(rustrt::rust_get_task(), key, data) local_set(rustrt::rust_get_task(), key, data)
} }
@ -1442,7 +1447,7 @@ unsafe fn local_data_set<T: owned>(
* data is removed (and its reference dropped). * data is removed (and its reference dropped).
*/ */
unsafe fn local_data_modify<T: owned>( unsafe fn local_data_modify<T: owned>(
key: local_data_key<T>, key: LocalDataKey<T>,
modify_fn: fn(option<@T>) -> option<@T>) { modify_fn: fn(option<@T>) -> option<@T>) {
local_modify(rustrt::rust_get_task(), key, modify_fn) local_modify(rustrt::rust_get_task(), key, modify_fn)
@ -1558,7 +1563,7 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
// We have to cheat with opts - the interface doesn't support them because // We have to cheat with opts - the interface doesn't support them because
// they don't make sense (redundant with task().supervised()). // they don't make sense (redundant with task().supervised()).
let b0 = task(); let b0 = task();
let b1 = task_builder({ let b1 = TaskBuilder({
opts: { linked: true, supervised: true with b0.opts }, opts: { linked: true, supervised: true with b0.opts },
can_not_copy: none, can_not_copy: none,
with *b0 with *b0
@ -1571,7 +1576,7 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
// We have to cheat with opts - the interface doesn't support them because // We have to cheat with opts - the interface doesn't support them because
// they don't make sense (redundant with task().supervised()). // they don't make sense (redundant with task().supervised()).
let b0 = task(); let b0 = task();
let b1 = task_builder({ let b1 = TaskBuilder({
opts: { linked: true, supervised: true with b0.opts }, opts: { linked: true, supervised: true with b0.opts },
can_not_copy: none, can_not_copy: none,
with *b0 with *b0
@ -1667,7 +1672,7 @@ fn test_spawn_raw_notify() {
comm::send(task_ch, get_task()); comm::send(task_ch, get_task());
} }
let task_ = comm::recv(task_po); let task_ = comm::recv(task_po);
assert comm::recv(notify_po) == exit(task_, success); assert comm::recv(notify_po) == Exit(task_, Success);
let opts = { let opts = {
linked: false, linked: false,
@ -1679,7 +1684,7 @@ fn test_spawn_raw_notify() {
fail; fail;
} }
let task_ = comm::recv(task_po); let task_ = comm::recv(task_po);
assert comm::recv(notify_po) == exit(task_, failure); assert comm::recv(notify_po) == Exit(task_, Failure);
} }
#[test] #[test]
@ -1712,13 +1717,13 @@ fn test_add_wrapper() {
fn test_future_result() { fn test_future_result() {
let mut result = none; let mut result = none;
do task().future_result(|+r| { result = some(r); }).spawn { } do task().future_result(|+r| { result = some(r); }).spawn { }
assert future::get(&option::unwrap(result)) == success; assert future::get(&option::unwrap(result)) == Success;
result = none; result = none;
do task().future_result(|+r| { result = some(r); }).unlinked().spawn { do task().future_result(|+r| { result = some(r); }).unlinked().spawn {
fail; fail;
} }
assert future::get(&option::unwrap(result)) == failure; assert future::get(&option::unwrap(result)) == Failure;
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
@ -1779,7 +1784,7 @@ fn test_try_fail() {
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_spawn_sched_no_threads() { fn test_spawn_sched_no_threads() {
do spawn_sched(manual_threads(0u)) { } do spawn_sched(ManualThreads(0u)) { }
} }
#[test] #[test]
@ -1787,10 +1792,10 @@ fn test_spawn_sched() {
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
fn f(i: int, ch: comm::chan<()>) { fn f(i: int, ch: comm::Chan<()>) {
let parent_sched_id = rustrt::rust_get_sched_id(); let parent_sched_id = rustrt::rust_get_sched_id();
do spawn_sched(single_threaded) { do spawn_sched(SingleThreaded) {
let child_sched_id = rustrt::rust_get_sched_id(); let child_sched_id = rustrt::rust_get_sched_id();
assert parent_sched_id != child_sched_id; assert parent_sched_id != child_sched_id;
@ -1811,7 +1816,7 @@ fn test_spawn_sched_childs_on_same_sched() {
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
do spawn_sched(single_threaded) { do spawn_sched(SingleThreaded) {
let parent_sched_id = rustrt::rust_get_sched_id(); let parent_sched_id = rustrt::rust_get_sched_id();
do spawn { do spawn {
let child_sched_id = rustrt::rust_get_sched_id(); let child_sched_id = rustrt::rust_get_sched_id();
@ -1849,7 +1854,7 @@ fn test_spawn_sched_blocking() {
let lock = testrt::rust_dbg_lock_create(); let lock = testrt::rust_dbg_lock_create();
do spawn_sched(single_threaded) { do spawn_sched(SingleThreaded) {
testrt::rust_dbg_lock_lock(lock); testrt::rust_dbg_lock_lock(lock);
comm::send(start_ch, ()); comm::send(start_ch, ());
@ -1864,7 +1869,7 @@ fn test_spawn_sched_blocking() {
// Wait until the other task has its lock // Wait until the other task has its lock
comm::recv(start_po); comm::recv(start_po);
fn pingpong(po: comm::port<int>, ch: comm::chan<int>) { fn pingpong(po: comm::Port<int>, ch: comm::Chan<int>) {
let mut val = 20; let mut val = 20;
while val > 0 { while val > 0 {
val = comm::recv(po); val = comm::recv(po);
@ -1918,7 +1923,7 @@ fn test_avoid_copying_the_body_spawn() {
#[test] #[test]
fn test_avoid_copying_the_body_spawn_listener() { fn test_avoid_copying_the_body_spawn_listener() {
do avoid_copying_the_body |f| { do avoid_copying_the_body |f| {
spawn_listener(fn~(move f, _po: comm::port<int>) { spawn_listener(fn~(move f, _po: comm::Port<int>) {
f(); f();
}); });
} }
@ -1936,7 +1941,7 @@ fn test_avoid_copying_the_body_task_spawn() {
#[test] #[test]
fn test_avoid_copying_the_body_spawn_listener_1() { fn test_avoid_copying_the_body_spawn_listener_1() {
do avoid_copying_the_body |f| { do avoid_copying_the_body |f| {
task().spawn_listener(fn~(move f, _po: comm::port<int>) { task().spawn_listener(fn~(move f, _po: comm::Port<int>) {
f(); f();
}); });
} }
@ -1964,7 +1969,7 @@ fn test_avoid_copying_the_body_unlinked() {
fn test_platform_thread() { fn test_platform_thread() {
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
do task().sched_mode(platform_thread).spawn { do task().sched_mode(PlatformThread).spawn {
comm::send(ch, ()); comm::send(ch, ());
} }
comm::recv(po); comm::recv(po);

View file

@ -245,7 +245,7 @@ mod v6 {
} }
type get_addr_data = { type get_addr_data = {
output_ch: comm::chan<result::result<~[ip_addr],ip_get_addr_err>> output_ch: comm::Chan<result::result<~[ip_addr],ip_get_addr_err>>
}; };
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,

View file

@ -292,7 +292,7 @@ fn write(sock: tcp_socket, raw_write_data: ~[u8])
* value as the `err` variant * value as the `err` variant
*/ */
fn write_future(sock: tcp_socket, raw_write_data: ~[u8]) fn write_future(sock: tcp_socket, raw_write_data: ~[u8])
-> future::future<result::result<(), tcp_err_data>> unsafe { -> future::Future<result::result<(), tcp_err_data>> unsafe {
let socket_data_ptr = ptr::addr_of(*(sock.socket_data)); let socket_data_ptr = ptr::addr_of(*(sock.socket_data));
do future_spawn { do future_spawn {
let data_copy = copy(raw_write_data); let data_copy = copy(raw_write_data);
@ -315,7 +315,7 @@ fn write_future(sock: tcp_socket, raw_write_data: ~[u8])
* on) from until `read_stop` is called, or a `tcp_err_data` record * on) from until `read_stop` is called, or a `tcp_err_data` record
*/ */
fn read_start(sock: tcp_socket) fn read_start(sock: tcp_socket)
-> result::result<comm::port< -> result::result<comm::Port<
result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe {
let socket_data = ptr::addr_of(*(sock.socket_data)); let socket_data = ptr::addr_of(*(sock.socket_data));
read_start_common_impl(socket_data) read_start_common_impl(socket_data)
@ -329,7 +329,7 @@ fn read_start(sock: tcp_socket)
* * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on * * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on
*/ */
fn read_stop(sock: tcp_socket, fn read_stop(sock: tcp_socket,
-read_port: comm::port<result::result<~[u8], tcp_err_data>>) -> -read_port: comm::Port<result::result<~[u8], tcp_err_data>>) ->
result::result<(), tcp_err_data> unsafe { result::result<(), tcp_err_data> unsafe {
log(debug, fmt!{"taking the read_port out of commission %?", read_port}); log(debug, fmt!{"taking the read_port out of commission %?", read_port});
let socket_data = ptr::addr_of(*sock.socket_data); let socket_data = ptr::addr_of(*sock.socket_data);
@ -387,7 +387,7 @@ fn read(sock: tcp_socket, timeout_msecs: uint)
* read attempt. Pass `0u` to wait indefinitely * read attempt. Pass `0u` to wait indefinitely
*/ */
fn read_future(sock: tcp_socket, timeout_msecs: uint) fn read_future(sock: tcp_socket, timeout_msecs: uint)
-> future::future<result::result<~[u8],tcp_err_data>> { -> future::Future<result::result<~[u8],tcp_err_data>> {
let socket_data = ptr::addr_of(*(sock.socket_data)); let socket_data = ptr::addr_of(*(sock.socket_data));
do future_spawn { do future_spawn {
read_common_impl(socket_data, timeout_msecs) read_common_impl(socket_data, timeout_msecs)
@ -563,9 +563,9 @@ fn accept(new_conn: tcp_new_connection)
*/ */
fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint, fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint,
iotask: iotask, iotask: iotask,
on_establish_cb: fn~(comm::chan<option<tcp_err_data>>), on_establish_cb: fn~(comm::Chan<option<tcp_err_data>>),
+new_connect_cb: fn~(tcp_new_connection, +new_connect_cb: fn~(tcp_new_connection,
comm::chan<option<tcp_err_data>>)) comm::Chan<option<tcp_err_data>>))
-> result::result<(), tcp_listen_err_data> unsafe { -> result::result<(), tcp_listen_err_data> unsafe {
do listen_common(host_ip, port, backlog, iotask, on_establish_cb) do listen_common(host_ip, port, backlog, iotask, on_establish_cb)
// on_connect_cb // on_connect_cb
@ -580,7 +580,7 @@ fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint,
fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
iotask: iotask, iotask: iotask,
on_establish_cb: fn~(comm::chan<option<tcp_err_data>>), on_establish_cb: fn~(comm::Chan<option<tcp_err_data>>),
-on_connect_cb: fn~(*uv::ll::uv_tcp_t)) -on_connect_cb: fn~(*uv::ll::uv_tcp_t))
-> result::result<(), tcp_listen_err_data> unsafe { -> result::result<(), tcp_listen_err_data> unsafe {
let stream_closed_po = comm::port::<()>(); let stream_closed_po = comm::port::<()>();
@ -724,12 +724,12 @@ fn socket_buf(-sock: tcp_socket) -> tcp_socket_buf {
/// Convenience methods extending `net::tcp::tcp_socket` /// Convenience methods extending `net::tcp::tcp_socket`
impl tcp_socket { impl tcp_socket {
fn read_start() -> result::result<comm::port< fn read_start() -> result::result<comm::Port<
result::result<~[u8], tcp_err_data>>, tcp_err_data> { result::result<~[u8], tcp_err_data>>, tcp_err_data> {
read_start(self) read_start(self)
} }
fn read_stop(-read_port: fn read_stop(-read_port:
comm::port<result::result<~[u8], tcp_err_data>>) -> comm::Port<result::result<~[u8], tcp_err_data>>) ->
result::result<(), tcp_err_data> { result::result<(), tcp_err_data> {
read_stop(self, read_port) read_stop(self, read_port)
} }
@ -738,7 +738,7 @@ impl tcp_socket {
read(self, timeout_msecs) read(self, timeout_msecs)
} }
fn read_future(timeout_msecs: uint) -> fn read_future(timeout_msecs: uint) ->
future::future<result::result<~[u8], tcp_err_data>> { future::Future<result::result<~[u8], tcp_err_data>> {
read_future(self, timeout_msecs) read_future(self, timeout_msecs)
} }
fn write(raw_write_data: ~[u8]) fn write(raw_write_data: ~[u8])
@ -746,7 +746,7 @@ impl tcp_socket {
write(self, raw_write_data) write(self, raw_write_data)
} }
fn write_future(raw_write_data: ~[u8]) fn write_future(raw_write_data: ~[u8])
-> future::future<result::result<(), tcp_err_data>> { -> future::Future<result::result<(), tcp_err_data>> {
write_future(self, raw_write_data) write_future(self, raw_write_data)
} }
} }
@ -922,7 +922,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
// shared impl for read_start // shared impl for read_start
fn read_start_common_impl(socket_data: *tcp_socket_data) fn read_start_common_impl(socket_data: *tcp_socket_data)
-> result::result<comm::port< -> result::result<comm::Port<
result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe {
let stream_handle_ptr = (*socket_data).stream_handle_ptr; let stream_handle_ptr = (*socket_data).stream_handle_ptr;
let start_po = comm::port::<option<uv::ll::uv_err_data>>(); let start_po = comm::port::<option<uv::ll::uv_err_data>>();
@ -1002,8 +1002,8 @@ enum tcp_new_connection {
type tcp_listen_fc_data = { type tcp_listen_fc_data = {
server_stream_ptr: *uv::ll::uv_tcp_t, server_stream_ptr: *uv::ll::uv_tcp_t,
stream_closed_ch: comm::chan<()>, stream_closed_ch: comm::Chan<()>,
kill_ch: comm::chan<option<tcp_err_data>>, kill_ch: comm::Chan<option<tcp_err_data>>,
on_connect_cb: fn~(*uv::ll::uv_tcp_t), on_connect_cb: fn~(*uv::ll::uv_tcp_t),
iotask: iotask, iotask: iotask,
mut active: bool mut active: bool
@ -1050,7 +1050,7 @@ enum tcp_write_result {
} }
enum tcp_read_start_result { enum tcp_read_start_result {
tcp_read_start_success(comm::port<tcp_read_result>), tcp_read_start_success(comm::Port<tcp_read_result>),
tcp_read_start_error(tcp_err_data) tcp_read_start_error(tcp_err_data)
} }
@ -1116,7 +1116,7 @@ extern fn on_alloc_cb(handle: *libc::c_void,
} }
type tcp_socket_close_data = { type tcp_socket_close_data = {
closed_ch: comm::chan<()> closed_ch: comm::Chan<()>
}; };
extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) unsafe { extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
@ -1145,12 +1145,12 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t,
} }
type write_req_data = { type write_req_data = {
result_ch: comm::chan<tcp_write_result> result_ch: comm::Chan<tcp_write_result>
}; };
type connect_req_data = { type connect_req_data = {
result_ch: comm::chan<conn_attempt>, result_ch: comm::Chan<conn_attempt>,
closed_signal_ch: comm::chan<()> closed_signal_ch: comm::Chan<()>
}; };
extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) unsafe { extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
@ -1198,8 +1198,8 @@ enum conn_attempt {
} }
type tcp_socket_data = { type tcp_socket_data = {
reader_po: comm::port<result::result<~[u8], tcp_err_data>>, reader_po: comm::Port<result::result<~[u8], tcp_err_data>>,
reader_ch: comm::chan<result::result<~[u8], tcp_err_data>>, reader_ch: comm::Chan<result::result<~[u8], tcp_err_data>>,
stream_handle_ptr: *uv::ll::uv_tcp_t, stream_handle_ptr: *uv::ll::uv_tcp_t,
connect_req: uv::ll::uv_connect_t, connect_req: uv::ll::uv_connect_t,
write_req: uv::ll::uv_write_t, write_req: uv::ll::uv_write_t,
@ -1285,7 +1285,7 @@ mod test {
let cont_po = comm::port::<()>(); let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po); let cont_ch = comm::chan(cont_po);
// server // server
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| { let actual_req = do comm::listen |server_ch| {
run_tcp_test_server( run_tcp_test_server(
server_ip, server_ip,
@ -1351,7 +1351,7 @@ mod test {
let cont_po = comm::port::<()>(); let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po); let cont_ch = comm::chan(cont_po);
// server // server
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| { let actual_req = do comm::listen |server_ch| {
run_tcp_test_server( run_tcp_test_server(
server_ip, server_ip,
@ -1421,7 +1421,7 @@ mod test {
let cont_po = comm::port::<()>(); let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po); let cont_ch = comm::chan(cont_po);
// server // server
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| { let actual_req = do comm::listen |server_ch| {
run_tcp_test_server( run_tcp_test_server(
server_ip, server_ip,
@ -1475,8 +1475,8 @@ mod test {
} }
fn run_tcp_test_server(server_ip: ~str, server_port: uint, resp: ~str, fn run_tcp_test_server(server_ip: ~str, server_port: uint, resp: ~str,
server_ch: comm::chan<~str>, server_ch: comm::Chan<~str>,
cont_ch: comm::chan<()>, cont_ch: comm::Chan<()>,
iotask: iotask) -> ~str { iotask: iotask) -> ~str {
let server_ip_addr = ip::v4::parse_addr(server_ip); let server_ip_addr = ip::v4::parse_addr(server_ip);
let listen_result = listen(server_ip_addr, server_port, 128u, iotask, let listen_result = listen(server_ip_addr, server_port, 128u, iotask,
@ -1491,7 +1491,7 @@ mod test {
|new_conn, kill_ch| { |new_conn, kill_ch| {
log(debug, ~"SERVER: new connection!"); log(debug, ~"SERVER: new connection!");
do comm::listen |cont_ch| { do comm::listen |cont_ch| {
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
log(debug, ~"SERVER: starting worker for new req"); log(debug, ~"SERVER: starting worker for new req");
let accept_result = accept(new_conn); let accept_result = accept(new_conn);
@ -1582,7 +1582,7 @@ mod test {
} }
fn run_tcp_test_client(server_ip: ~str, server_port: uint, resp: ~str, fn run_tcp_test_client(server_ip: ~str, server_port: uint, resp: ~str,
client_ch: comm::chan<~str>, client_ch: comm::Chan<~str>,
iotask: iotask) -> result::result<~str, iotask: iotask) -> result::result<~str,
tcp_connect_err_data> { tcp_connect_err_data> {
let server_ip_addr = ip::v4::parse_addr(server_ip); let server_ip_addr = ip::v4::parse_addr(server_ip);

View file

@ -720,7 +720,7 @@ mod tests {
fn test_sem_runtime_friendly_blocking() { fn test_sem_runtime_friendly_blocking() {
// Force the runtime to schedule two threads on the same sched_loop. // Force the runtime to schedule two threads on the same sched_loop.
// When one blocks, it should schedule the other one. // When one blocks, it should schedule the other one.
do task::spawn_sched(task::manual_threads(1)) { do task::spawn_sched(task::ManualThreads(1)) {
let s = ~semaphore(1); let s = ~semaphore(1);
let s2 = ~s.clone(); let s2 = ~s.clone();
let (c,p) = pipes::stream(); let (c,p) = pipes::stream();

View file

@ -9,7 +9,7 @@ import either::Either;
import result::{ok, err}; import result::{ok, err};
import io::WriterUtil; import io::WriterUtil;
import libc::size_t; import libc::size_t;
import task::task_builder; import task::TaskBuilder;
export test_name; export test_name;
export test_fn; export test_fn;
@ -379,7 +379,7 @@ fn filter_tests(opts: test_opts,
type test_future = {test: test_desc, wait: fn@() -> test_result}; type test_future = {test: test_desc, wait: fn@() -> test_result};
fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) { fn run_test(+test: test_desc, monitor_ch: comm::Chan<monitor_msg>) {
if test.ignore { if test.ignore {
comm::send(monitor_ch, (copy test, tr_ignored)); comm::send(monitor_ch, (copy test, tr_ignored));
return; return;
@ -392,7 +392,7 @@ fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
result_future = some(r); result_future = some(r);
}).spawn(testfn); }).spawn(testfn);
let task_result = future::get(&option::unwrap(result_future)); let task_result = future::get(&option::unwrap(result_future));
let test_result = calc_result(test, task_result == task::success); let test_result = calc_result(test, task_result == task::Success);
comm::send(monitor_ch, (copy test, test_result)); comm::send(monitor_ch, (copy test, test_result));
}; };
} }

View file

@ -22,7 +22,7 @@ export delayed_send, sleep, recv_timeout;
* * val - a value of type T to send over the provided `ch` * * val - a value of type T to send over the provided `ch`
*/ */
fn delayed_send<T: copy send>(iotask: iotask, fn delayed_send<T: copy send>(iotask: iotask,
msecs: uint, ch: comm::chan<T>, val: T) { msecs: uint, ch: comm::Chan<T>, val: T) {
unsafe { unsafe {
let timer_done_po = comm::port::<()>(); let timer_done_po = comm::port::<()>();
let timer_done_ch = comm::chan(timer_done_po); let timer_done_ch = comm::chan(timer_done_po);
@ -99,7 +99,7 @@ fn sleep(iotask: iotask, msecs: uint) {
*/ */
fn recv_timeout<T: copy send>(iotask: iotask, fn recv_timeout<T: copy send>(iotask: iotask,
msecs: uint, msecs: uint,
wait_po: comm::port<T>) -> option<T> { wait_po: comm::Port<T>) -> option<T> {
let timeout_po = comm::port::<()>(); let timeout_po = comm::port::<()>();
let timeout_ch = comm::chan(timeout_po); let timeout_ch = comm::chan(timeout_po);
delayed_send(iotask, msecs, timeout_ch, ()); delayed_send(iotask, msecs, timeout_ch, ());
@ -120,7 +120,7 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
status: libc::c_int) unsafe { status: libc::c_int) unsafe {
log(debug, fmt!{"delayed_send_cb handle %? status %?", handle, status}); log(debug, fmt!{"delayed_send_cb handle %? status %?", handle, status});
let timer_done_ch = let timer_done_ch =
*(uv::ll::get_data_for_uv_handle(handle) as *comm::chan<()>); *(uv::ll::get_data_for_uv_handle(handle) as *comm::Chan<()>);
let stop_result = uv::ll::timer_stop(handle); let stop_result = uv::ll::timer_stop(handle);
if (stop_result == 0i32) { if (stop_result == 0i32) {
comm::send(timer_done_ch, ()); comm::send(timer_done_ch, ());
@ -136,7 +136,7 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
extern fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) unsafe { extern fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) unsafe {
log(debug, fmt!{"delayed_send_close_cb handle %?", handle}); log(debug, fmt!{"delayed_send_close_cb handle %?", handle});
let timer_done_ch = let timer_done_ch =
*(uv::ll::get_data_for_uv_handle(handle) as *comm::chan<()>); *(uv::ll::get_data_for_uv_handle(handle) as *comm::Chan<()>);
comm::send(timer_done_ch, ()); comm::send(timer_done_ch, ());
} }

View file

@ -7,8 +7,8 @@ import iotask = uv_iotask;
import get_gl = get; import get_gl = get;
import iotask::{iotask, spawn_iotask}; import iotask::{iotask, spawn_iotask};
import priv::{chan_from_global_ptr, weaken_task}; import priv::{chan_from_global_ptr, weaken_task};
import comm::{port, chan, select2, listen}; import comm::{Port, Chan, port, chan, select2, listen};
import task::task_builder; import task::TaskBuilder;
import either::{Left, Right}; import either::{Left, Right};
extern mod rustrt { extern mod rustrt {
@ -40,13 +40,13 @@ fn get_monitor_task_gl() -> iotask unsafe {
monitor_loop_chan_ptr}; monitor_loop_chan_ptr};
debug!{"before priv::chan_from_global_ptr"}; debug!{"before priv::chan_from_global_ptr"};
type monchan = chan<iotask>; type monchan = Chan<iotask>;
let monitor_ch = let monitor_ch =
do chan_from_global_ptr::<monchan>(monitor_loop_chan_ptr, do chan_from_global_ptr::<monchan>(monitor_loop_chan_ptr,
|| { || {
task::task().sched_mode task::task().sched_mode
(task::single_threaded) (task::SingleThreaded)
.unlinked() .unlinked()
}) |msg_po| { }) |msg_po| {
debug!{"global monitor task starting"}; debug!{"global monitor task starting"};
@ -108,7 +108,7 @@ fn spawn_loop() -> iotask unsafe {
mod test { mod test {
extern fn simple_timer_close_cb(timer_ptr: *ll::uv_timer_t) unsafe { extern fn simple_timer_close_cb(timer_ptr: *ll::uv_timer_t) unsafe {
let exit_ch_ptr = ll::get_data_for_uv_handle( let exit_ch_ptr = ll::get_data_for_uv_handle(
timer_ptr as *libc::c_void) as *comm::chan<bool>; timer_ptr as *libc::c_void) as *comm::Chan<bool>;
let exit_ch = *exit_ch_ptr; let exit_ch = *exit_ch_ptr;
comm::send(exit_ch, true); comm::send(exit_ch, true);
log(debug, fmt!{"EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?", log(debug, fmt!{"EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?",
@ -164,7 +164,7 @@ mod test {
let hl_loop = get_gl(); let hl_loop = get_gl();
let exit_po = comm::port::<()>(); let exit_po = comm::port::<()>();
let exit_ch = comm::chan(exit_po); let exit_ch = comm::chan(exit_po);
task::spawn_sched(task::manual_threads(1u), || { task::spawn_sched(task::ManualThreads(1u), || {
impl_uv_hl_simple_timer(hl_loop); impl_uv_hl_simple_timer(hl_loop);
comm::send(exit_ch, ()); comm::send(exit_ch, ());
}); });
@ -182,7 +182,7 @@ mod test {
let exit_ch = comm::chan(exit_po); let exit_ch = comm::chan(exit_po);
let cycles = 5000u; let cycles = 5000u;
for iter::repeat(cycles) { for iter::repeat(cycles) {
task::spawn_sched(task::manual_threads(1u), || { task::spawn_sched(task::ManualThreads(1u), || {
impl_uv_hl_simple_timer(hl_loop); impl_uv_hl_simple_timer(hl_loop);
comm::send(exit_ch, ()); comm::send(exit_ch, ());
}); });

View file

@ -12,23 +12,23 @@ export exit;
import libc::c_void; import libc::c_void;
import ptr::addr_of; import ptr::addr_of;
import comm::{port, chan, listen}; import comm::{Port, port, Chan, chan, listen};
import task::task_builder; import task::TaskBuilder;
import ll = uv_ll; import ll = uv_ll;
/// Used to abstract-away direct interaction with a libuv loop. /// Used to abstract-away direct interaction with a libuv loop.
enum iotask { enum iotask {
iotask_({ iotask_({
async_handle: *ll::uv_async_t, async_handle: *ll::uv_async_t,
op_chan: chan<iotask_msg> op_chan: Chan<iotask_msg>
}) })
} }
fn spawn_iotask(-task: task::task_builder) -> iotask { fn spawn_iotask(-task: task::TaskBuilder) -> iotask {
do listen |iotask_ch| { do listen |iotask_ch| {
do task.sched_mode(task::single_threaded).spawn { do task.sched_mode(task::SingleThreaded).spawn {
debug!{"entering libuv task"}; debug!{"entering libuv task"};
run_loop(iotask_ch); run_loop(iotask_ch);
debug!{"libuv task exiting"}; debug!{"libuv task exiting"};
@ -86,7 +86,7 @@ enum iotask_msg {
} }
/// Run the loop and begin handling messages /// Run the loop and begin handling messages
fn run_loop(iotask_ch: chan<iotask>) unsafe { fn run_loop(iotask_ch: Chan<iotask>) unsafe {
let loop_ptr = ll::loop_new(); let loop_ptr = ll::loop_new();
@ -123,7 +123,7 @@ fn run_loop(iotask_ch: chan<iotask>) unsafe {
// data that lives for the lifetime of the high-evel oo // data that lives for the lifetime of the high-evel oo
type iotask_loop_data = { type iotask_loop_data = {
async_handle: *ll::uv_async_t, async_handle: *ll::uv_async_t,
msg_po: port<iotask_msg> msg_po: Port<iotask_msg>
}; };
fn send_msg(iotask: iotask, fn send_msg(iotask: iotask,
@ -180,7 +180,7 @@ mod test {
} }
type ah_data = { type ah_data = {
iotask: iotask, iotask: iotask,
exit_ch: comm::chan<()> exit_ch: comm::Chan<()>
}; };
fn impl_uv_iotask_async(iotask: iotask) unsafe { fn impl_uv_iotask_async(iotask: iotask) unsafe {
let async_handle = ll::async_t(); let async_handle = ll::async_t();
@ -202,10 +202,10 @@ mod test {
// this fn documents the bear minimum neccesary to roll your own // this fn documents the bear minimum neccesary to roll your own
// high_level_loop // high_level_loop
unsafe fn spawn_test_loop(exit_ch: comm::chan<()>) -> iotask { unsafe fn spawn_test_loop(exit_ch: comm::Chan<()>) -> iotask {
let iotask_port = comm::port::<iotask>(); let iotask_port = comm::port::<iotask>();
let iotask_ch = comm::chan(iotask_port); let iotask_ch = comm::chan(iotask_port);
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
run_loop(iotask_ch); run_loop(iotask_ch);
exit_ch.send(()); exit_ch.send(());
}; };
@ -237,7 +237,7 @@ mod test {
let work_exit_po = comm::port::<()>(); let work_exit_po = comm::port::<()>();
let work_exit_ch = comm::chan(work_exit_po); let work_exit_ch = comm::chan(work_exit_po);
for iter::repeat(7u) { for iter::repeat(7u) {
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
impl_uv_iotask_async(iotask); impl_uv_iotask_async(iotask);
comm::send(work_exit_ch, ()); comm::send(work_exit_ch, ());
}; };

View file

@ -1008,7 +1008,7 @@ mod test {
type request_wrapper = { type request_wrapper = {
write_req: *uv_write_t, write_req: *uv_write_t,
req_buf: *~[uv_buf_t], req_buf: *~[uv_buf_t],
read_chan: *comm::chan<~str> read_chan: *comm::Chan<~str>
}; };
extern fn after_close_cb(handle: *libc::c_void) { extern fn after_close_cb(handle: *libc::c_void) {
@ -1106,7 +1106,7 @@ mod test {
} }
fn impl_uv_tcp_request(ip: ~str, port: int, req_str: ~str, fn impl_uv_tcp_request(ip: ~str, port: int, req_str: ~str,
client_chan: *comm::chan<~str>) unsafe { client_chan: *comm::Chan<~str>) unsafe {
let test_loop = loop_new(); let test_loop = loop_new();
let tcp_handle = tcp_t(); let tcp_handle = tcp_t();
let tcp_handle_ptr = ptr::addr_of(tcp_handle); let tcp_handle_ptr = ptr::addr_of(tcp_handle);
@ -1323,12 +1323,12 @@ mod test {
server: *uv_tcp_t, server: *uv_tcp_t,
server_kill_msg: ~str, server_kill_msg: ~str,
server_resp_buf: *~[uv_buf_t], server_resp_buf: *~[uv_buf_t],
server_chan: *comm::chan<~str>, server_chan: *comm::Chan<~str>,
server_write_req: *uv_write_t server_write_req: *uv_write_t
}; };
type async_handle_data = { type async_handle_data = {
continue_chan: *comm::chan<bool> continue_chan: *comm::Chan<bool>
}; };
extern fn async_close_cb(handle: *libc::c_void) { extern fn async_close_cb(handle: *libc::c_void) {
@ -1354,8 +1354,8 @@ mod test {
server_port: int, server_port: int,
kill_server_msg: ~str, kill_server_msg: ~str,
server_resp_msg: ~str, server_resp_msg: ~str,
server_chan: *comm::chan<~str>, server_chan: *comm::Chan<~str>,
continue_chan: *comm::chan<bool>) unsafe { continue_chan: *comm::Chan<bool>) unsafe {
let test_loop = loop_new(); let test_loop = loop_new();
let tcp_server = tcp_t(); let tcp_server = tcp_t();
let tcp_server_ptr = ptr::addr_of(tcp_server); let tcp_server_ptr = ptr::addr_of(tcp_server);
@ -1469,7 +1469,7 @@ mod test {
let continue_chan = comm::chan::<bool>(continue_port); let continue_chan = comm::chan::<bool>(continue_port);
let continue_chan_ptr = ptr::addr_of(continue_chan); let continue_chan_ptr = ptr::addr_of(continue_chan);
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
impl_uv_tcp_server(bind_ip, port, impl_uv_tcp_server(bind_ip, port,
kill_server_msg, kill_server_msg,
server_resp_msg, server_resp_msg,
@ -1482,7 +1482,7 @@ mod test {
comm::recv(continue_port); comm::recv(continue_port);
log(debug, ~"received on continue port, set up tcp client"); log(debug, ~"received on continue port, set up tcp client");
do task::spawn_sched(task::manual_threads(1u)) { do task::spawn_sched(task::ManualThreads(1u)) {
impl_uv_tcp_request(request_ip, port, impl_uv_tcp_request(request_ip, port,
kill_server_msg, kill_server_msg,
ptr::addr_of(client_chan)); ptr::addr_of(client_chan));

View file

@ -231,8 +231,8 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
}; };
class finally { class finally {
let ch: comm::chan<monitor_msg>; let ch: comm::Chan<monitor_msg>;
new(ch: comm::chan<monitor_msg>) { self.ch = ch; } new(ch: comm::Chan<monitor_msg>) { self.ch = ch; }
drop { comm::send(self.ch, done); } drop { comm::send(self.ch, done); }
} }

View file

@ -43,7 +43,7 @@ enum msg {
} }
enum srv = { enum srv = {
ch: comm::chan<msg> ch: comm::Chan<msg>
}; };
fn from_str<T>(source: ~str, owner: srv_owner<T>) -> T { fn from_str<T>(source: ~str, owner: srv_owner<T>) -> T {
@ -67,7 +67,7 @@ fn run<T>(owner: srv_owner<T>, source: ~str, +parse: parser) -> T {
return res; return res;
} }
fn act(po: comm::port<msg>, source: ~str, parse: parser) { fn act(po: comm::Port<msg>, source: ~str, parse: parser) {
let sess = build_session(); let sess = build_session();
let ctxt = build_ctxt( let ctxt = build_ctxt(

View file

@ -110,14 +110,14 @@ fn pandoc_writer(
let stdout_po = comm::port(); let stdout_po = comm::port();
let stdout_ch = comm::chan(stdout_po); let stdout_ch = comm::chan(stdout_po);
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
comm::send(stdout_ch, readclose(pipe_out.in)); comm::send(stdout_ch, readclose(pipe_out.in));
} }
let stdout = comm::recv(stdout_po); let stdout = comm::recv(stdout_po);
let stderr_po = comm::port(); let stderr_po = comm::port();
let stderr_ch = comm::chan(stderr_po); let stderr_ch = comm::chan(stderr_po);
do task::spawn_sched(task::single_threaded) { do task::spawn_sched(task::SingleThreaded) {
comm::send(stderr_ch, readclose(pipe_err.in)); comm::send(stderr_ch, readclose(pipe_err.in));
} }
let stderr = comm::recv(stderr_po); let stderr = comm::recv(stderr_po);
@ -146,7 +146,7 @@ fn readclose(fd: libc::c_int) -> ~str {
} }
fn generic_writer(+process: fn~(markdown: ~str)) -> writer { fn generic_writer(+process: fn~(markdown: ~str)) -> writer {
let ch = do task::spawn_listener |po: comm::port<writeinstr>| { let ch = do task::spawn_listener |po: comm::Port<writeinstr>| {
let mut markdown = ~""; let mut markdown = ~"";
let mut keep_going = true; let mut keep_going = true;
while keep_going { while keep_going {
@ -265,7 +265,7 @@ fn write_file(path: ~str, s: ~str) {
} }
fn future_writer_factory( fn future_writer_factory(
) -> (writer_factory, comm::port<(doc::page, ~str)>) { ) -> (writer_factory, comm::Port<(doc::page, ~str)>) {
let markdown_po = comm::port(); let markdown_po = comm::port();
let markdown_ch = comm::chan(markdown_po); let markdown_ch = comm::chan(markdown_po);
let writer_factory = fn~(page: doc::page) -> writer { let writer_factory = fn~(page: doc::page) -> writer {
@ -283,7 +283,7 @@ fn future_writer_factory(
(writer_factory, markdown_po) (writer_factory, markdown_po)
} }
fn future_writer() -> (writer, future::future<~str>) { fn future_writer() -> (writer, future::Future<~str>) {
let port = comm::port(); let port = comm::port();
let chan = comm::chan(port); let chan = comm::chan(port);
let writer = fn~(+instr: writeinstr) { let writer = fn~(+instr: writeinstr) {

View file

@ -38,8 +38,8 @@ fn run(
comm::recv(result_port) comm::recv(result_port)
} }
type page_port = comm::port<option<doc::page>>; type page_port = comm::Port<option<doc::page>>;
type page_chan = comm::chan<option<doc::page>>; type page_chan = comm::Chan<option<doc::page>>;
fn make_doc_from_pages(page_port: page_port) -> doc::doc { fn make_doc_from_pages(page_port: page_port) -> doc::doc {
let mut pages = ~[]; let mut pages = ~[];

View file

@ -2,7 +2,7 @@ export foo;
import comm::*; import comm::*;
fn foo<T: send copy>(x: T) -> port<T> { fn foo<T: send copy>(x: T) -> Port<T> {
let p = port(); let p = port();
let c = chan(p); let c = chan(p);
do task::spawn() |copy c, copy x| { do task::spawn() |copy c, copy x| {

View file

@ -12,8 +12,8 @@ import std::time;
fn thread_ring(i: uint, fn thread_ring(i: uint,
count: uint, count: uint,
num_chan: comm::chan<uint>, num_chan: comm::Chan<uint>,
num_port: comm::port<uint>) { num_port: comm::Port<uint>) {
// Send/Receive lots of messages. // Send/Receive lots of messages.
for uint::range(0u, count) |j| { for uint::range(0u, count) |j| {
num_chan.send(i * j); num_chan.send(i * j);

View file

@ -14,7 +14,7 @@ enum request {
stop stop
} }
fn server(requests: comm::port<request>, responses: comm::chan<uint>) { fn server(requests: comm::Port<request>, responses: comm::Chan<uint>) {
let mut count = 0u; let mut count = 0u;
let mut done = false; let mut done = false;
while !done { while !done {

View file

@ -85,9 +85,9 @@ fn transform(aa: color, bb: color) -> color {
fn creature( fn creature(
name: uint, name: uint,
color: color, color: color,
from_rendezvous: comm::port<option<creature_info>>, from_rendezvous: comm::Port<option<creature_info>>,
to_rendezvous: comm::chan<creature_info>, to_rendezvous: comm::Chan<creature_info>,
to_rendezvous_log: comm::chan<~str> to_rendezvous_log: comm::Chan<~str>
) { ) {
let mut color = color; let mut color = color;
let mut creatures_met = 0; let mut creatures_met = 0;
@ -122,17 +122,17 @@ fn creature(
fn rendezvous(nn: uint, set: ~[color]) { fn rendezvous(nn: uint, set: ~[color]) {
// these ports will allow us to hear from the creatures // these ports will allow us to hear from the creatures
let from_creatures: comm::port<creature_info> = comm::port(); let from_creatures: comm::Port<creature_info> = comm::port();
let from_creatures_log: comm::port<~str> = comm::port(); let from_creatures_log: comm::Port<~str> = comm::port();
// these channels will be passed to the creatures so they can talk to us // these channels will be passed to the creatures so they can talk to us
let to_rendezvous = comm::chan(from_creatures); let to_rendezvous = comm::chan(from_creatures);
let to_rendezvous_log = comm::chan(from_creatures_log); let to_rendezvous_log = comm::chan(from_creatures_log);
// these channels will allow us to talk to each creature by 'name'/index // these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[comm::chan<option<creature_info>>] = let to_creature: ~[comm::Chan<option<creature_info>>] =
vec::mapi(set, vec::mapi(set,
fn@(ii: uint, col: color) -> comm::chan<option<creature_info>> { fn@(ii: uint, col: color) -> comm::Chan<option<creature_info>> {
// create each creature as a listener with a port, and // create each creature as a listener with a port, and
// give us a channel to talk to each // give us a channel to talk to each
return do task::spawn_listener |from_rendezvous| { return do task::spawn_listener |from_rendezvous| {

View file

@ -86,8 +86,8 @@ fn windows_with_carry(bb: &[u8], nn: uint,
return vec::slice(bb, len - (nn - 1u), len); return vec::slice(bb, len - (nn - 1u), len);
} }
fn make_sequence_processor(sz: uint, from_parent: comm::port<~[u8]>, fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
to_parent: comm::chan<~str>) { to_parent: comm::Chan<~str>) {
let freqs: hashmap<~[u8], uint> = map::bytes_hash(); let freqs: hashmap<~[u8], uint> = map::bytes_hash();
let mut carry: ~[u8] = ~[]; let mut carry: ~[u8] = ~[];
@ -141,7 +141,7 @@ fn main(args: ~[~str]) {
let sizes = ~[1u,2u,3u,4u,6u,12u,18u]; let sizes = ~[1u,2u,3u,4u,6u,12u,18u];
let from_child = vec::map (sizes, |_sz| comm::port() ); let from_child = vec::map (sizes, |_sz| comm::port() );
let to_parent = vec::mapi(sizes, |ii, _sz| comm::chan(from_child[ii]) ); let to_parent = vec::mapi(sizes, |ii, _sz| comm::chan(from_child[ii]) );
let to_child = vec::mapi(sizes, fn@(ii: uint, sz: uint) -> comm::chan<~[u8]> { let to_child = vec::mapi(sizes, fn@(ii: uint, sz: uint) -> comm::Chan<~[u8]> {
return do task::spawn_listener |from_parent| { return do task::spawn_listener |from_parent| {
make_sequence_processor(sz, from_parent, to_parent[ii]); make_sequence_processor(sz, from_parent, to_parent[ii]);
}; };

View file

@ -75,7 +75,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
rv rv
} }
fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> () fn chanmb(i: uint, size: uint, ch: comm::Chan<line>) -> ()
{ {
let mut crv = ~[]; let mut crv = ~[];
let incr = 2f64/(size as f64); let incr = 2f64/(size as f64);
@ -98,9 +98,9 @@ impl devnull: io::Writer {
fn get_type() -> io::WriterType { io::File } fn get_type() -> io::WriterType { io::File }
} }
fn writer(path: ~str, writech: comm::chan<comm::chan<line>>, size: uint) fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
{ {
let p: comm::port<line> = comm::port(); let p: comm::Port<line> = comm::port();
let ch = comm::chan(p); let ch = comm::chan(p);
comm::send(writech, ch); comm::send(writech, ch);
let cout: io::Writer = match path { let cout: io::Writer = match path {

View file

@ -19,7 +19,7 @@ fn start(+token: int) {
roundtrip(1, p, ch); roundtrip(1, p, ch);
} }
fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) { fn roundtrip(id: int, p: comm::Port<int>, ch: comm::Chan<int>) {
while (true) { while (true) {
match comm::recv(p) { match comm::recv(p) {
1 => { 1 => {

View file

@ -34,7 +34,7 @@ fn spawn_supervised_blocking(myname: &str, +f: fn~()) {
task::task().future_result(|+r| res = some(r)).supervised().spawn(f); task::task().future_result(|+r| res = some(r)).supervised().spawn(f);
#error["%s group waiting", myname]; #error["%s group waiting", myname];
let x = future::get(&option::unwrap(res)); let x = future::get(&option::unwrap(res));
assert x == task::success; assert x == task::Success;
} }
fn main(args: ~[~str]) { fn main(args: ~[~str]) {

View file

@ -1,12 +1,12 @@
// Test for concurrent tasks // Test for concurrent tasks
enum msg { enum msg {
ready(comm::chan<msg>), ready(comm::Chan<msg>),
start, start,
done(int), done(int),
} }
fn calc(children: uint, parent_ch: comm::chan<msg>) { fn calc(children: uint, parent_ch: comm::Chan<msg>) {
let port = comm::port(); let port = comm::port();
let chan = comm::chan(port); let chan = comm::chan(port);
let mut child_chs = ~[]; let mut child_chs = ~[];

View file

@ -27,7 +27,9 @@ import u64;
import task; import task;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::Port;
import comm::port; import comm::port;
import comm::recv; import comm::recv;
import comm::send; import comm::send;
@ -58,7 +60,7 @@ impl ~str: hash_key {
} }
// These used to be in task, but they disappeard. // These used to be in task, but they disappeard.
type joinable_task = port<()>; type joinable_task = Port<()>;
fn spawn_joinable(+f: fn~()) -> joinable_task { fn spawn_joinable(+f: fn~()) -> joinable_task {
let p = port(); let p = port();
let c = chan(p); let c = chan(p);
@ -135,7 +137,7 @@ mod map_reduce {
type reducer<K: copy send, V: copy send> = fn~(K, getter<V>); type reducer<K: copy send, V: copy send> = fn~(K, getter<V>);
enum ctrl_proto<K: copy send, V: copy send> { enum ctrl_proto<K: copy send, V: copy send> {
find_reducer(K, chan<chan<reduce_proto<V>>>), find_reducer(K, Chan<Chan<reduce_proto<V>>>),
mapper_done mapper_done
} }
@ -147,7 +149,7 @@ mod map_reduce {
} }
reducer_response: recv<K: copy send, V: copy send> { reducer_response: recv<K: copy send, V: copy send> {
reducer(chan<reduce_proto<V>>) -> open<K, V> reducer(Chan<reduce_proto<V>>) -> open<K, V>
} }
} }
@ -199,7 +201,7 @@ mod map_reduce {
send(c.get(), emit_val(val)); send(c.get(), emit_val(val));
} }
fn finish<K: copy send, V: copy send>(_k: K, v: chan<reduce_proto<V>>) fn finish<K: copy send, V: copy send>(_k: K, v: Chan<reduce_proto<V>>)
{ {
send(v, release); send(v, release);
} }
@ -210,7 +212,7 @@ mod map_reduce {
fn reduce_task<K: copy send, V: copy send>( fn reduce_task<K: copy send, V: copy send>(
reduce: reducer<K, V>, reduce: reducer<K, V>,
key: K, key: K,
out: chan<chan<reduce_proto<V>>>) out: Chan<Chan<reduce_proto<V>>>)
{ {
let p = port(); let p = port();
@ -219,7 +221,7 @@ mod map_reduce {
let mut ref_count = 0; let mut ref_count = 0;
let mut is_done = false; let mut is_done = false;
fn get<V: copy send>(p: port<reduce_proto<V>>, fn get<V: copy send>(p: Port<reduce_proto<V>>,
&ref_count: int, &is_done: bool) &ref_count: int, &is_done: bool)
-> option<V> { -> option<V> {
while !is_done || ref_count > 0 { while !is_done || ref_count > 0 {

View file

@ -1,10 +1,10 @@
// Test that we use fully-qualified type names in error messages. // Test that we use fully-qualified type names in error messages.
import core::task::task; import core::task::Task;
fn bar(x: uint) -> task { fn bar(x: uint) -> Task {
return x; return x;
//~^ ERROR mismatched types: expected `core::task::task` //~^ ERROR mismatched types: expected `core::task::Task`
} }
fn main() { fn main() {

View file

@ -1,7 +1,7 @@
fn main() { fn main() {
class foo { class foo {
let _x: comm::port<()>; let _x: comm::Port<()>;
new(x: comm::port<()>) { self._x = x; } new(x: comm::Port<()>) { self._x = x; }
drop {} drop {}
} }

View file

@ -1,11 +1,12 @@
// error-pattern:meep // error-pattern:meep
use std; use std;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::port; import comm::port;
import comm::send; import comm::send;
import comm::recv; import comm::recv;
fn echo<T: send>(c: chan<T>, oc: chan<chan<T>>) { fn echo<T: send>(c: Chan<T>, oc: Chan<Chan<T>>) {
// Tests that the type argument in port gets // Tests that the type argument in port gets
// visited // visited
let p = port::<T>(); let p = port::<T>();

View file

@ -1,13 +1,14 @@
// -*- rust -*- // -*- rust -*-
use std; use std;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::port; import comm::port;
import comm::send; import comm::send;
import comm::recv; import comm::recv;
import task; import task;
fn a(c: chan<int>) { send(c, 10); } fn a(c: Chan<int>) { send(c, 10); }
fn main() { fn main() {
let p = port(); let p = port();
@ -20,7 +21,7 @@ fn main() {
// debug!{"Finished."}; // debug!{"Finished."};
} }
fn b(c: chan<int>) { fn b(c: Chan<int>) {
// debug!{"task b0"}; // debug!{"task b0"};
// debug!{"task b1"}; // debug!{"task b1"};
// debug!{"task b2"}; // debug!{"task b2"};

View file

@ -4,11 +4,12 @@ use std;
import comm; import comm;
import comm::port; import comm::port;
import comm::send; import comm::send;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::recv; import comm::recv;
import task; import task;
fn a(c: chan<int>) { debug!{"task a0"}; debug!{"task a1"}; send(c, 10); } fn a(c: Chan<int>) { debug!{"task a0"}; debug!{"task a1"}; send(c, 10); }
fn main() { fn main() {
let p = port(); let p = port();
@ -21,7 +22,7 @@ fn main() {
debug!{"Finished."}; debug!{"Finished."};
} }
fn b(c: chan<int>) { fn b(c: Chan<int>) {
debug!{"task b0"}; debug!{"task b0"};
debug!{"task b1"}; debug!{"task b1"};
debug!{"task b2"}; debug!{"task b2"};

View file

@ -3,11 +3,12 @@
use std; use std;
import comm; import comm;
import comm::send; import comm::send;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::recv; import comm::recv;
import task; import task;
fn a(c: chan<int>) { fn a(c: Chan<int>) {
if true { if true {
debug!{"task a"}; debug!{"task a"};
debug!{"task a"}; debug!{"task a"};
@ -42,7 +43,7 @@ fn main() {
debug!{"children finished, root finishing"}; debug!{"children finished, root finishing"};
} }
fn b(c: chan<int>) { fn b(c: Chan<int>) {
if true { if true {
debug!{"task b"}; debug!{"task b"};
debug!{"task b"}; debug!{"task b"};

View file

@ -68,7 +68,7 @@ fn test_port() {
} }
fn test_chan() { fn test_chan() {
let p: comm::port<int> = comm::port(); let p: comm::Port<int> = comm::port();
let ch1 = comm::chan(p); let ch1 = comm::chan(p);
let ch2 = comm::chan(p); let ch2 = comm::chan(p);

View file

@ -2,17 +2,18 @@
use std; use std;
import task; import task;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::send; import comm::send;
import comm; import comm;
import comm::port; import comm::port;
import comm::recv; import comm::recv;
enum request { quit, close(chan<bool>), } enum request { quit, close(Chan<bool>), }
type ctx = chan<request>; type ctx = Chan<request>;
fn request_task(c: chan<ctx>) { fn request_task(c: Chan<ctx>) {
let p = port(); let p = port();
send(c, chan(p)); send(c, chan(p));
let mut req: request; let mut req: request;

View file

@ -2,6 +2,7 @@
use std; use std;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::send; import comm::send;
import comm::recv; import comm::recv;
@ -17,7 +18,7 @@ fn main() {
assert (y == 10); assert (y == 10);
} }
fn child(c: chan<int>) { fn child(c: Chan<int>) {
error!{"sending"}; error!{"sending"};
send(c, 10); send(c, 10);
error!{"value sent"}; error!{"value sent"};

View file

@ -14,6 +14,7 @@ import vec;
import std::map; import std::map;
import std::map::hashmap; import std::map::hashmap;
import task; import task;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::port; import comm::port;
import comm::send; import comm::send;
@ -31,18 +32,18 @@ mod map_reduce {
type mapper = extern fn(~str, putter); type mapper = extern fn(~str, putter);
enum ctrl_proto { find_reducer(~[u8], chan<int>), mapper_done, } enum ctrl_proto { find_reducer(~[u8], Chan<int>), mapper_done, }
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: ~[~str]) { fn start_mappers(ctrl: Chan<ctrl_proto>, inputs: ~[~str]) {
for inputs.each |i| { for inputs.each |i| {
task::spawn(|| map_task(ctrl, i) ); task::spawn(|| map_task(ctrl, i) );
} }
} }
fn map_task(ctrl: chan<ctrl_proto>, input: ~str) { fn map_task(ctrl: Chan<ctrl_proto>, input: ~str) {
let intermediates = map::str_hash(); let intermediates = map::str_hash();
fn emit(im: map::hashmap<~str, int>, ctrl: chan<ctrl_proto>, key: ~str, fn emit(im: map::hashmap<~str, int>, ctrl: Chan<ctrl_proto>, key: ~str,
val: ~str) { val: ~str) {
let mut c; let mut c;
match im.find(key) { match im.find(key) {

View file

@ -10,14 +10,14 @@ mod pipes {
type packet<T: send> = { type packet<T: send> = {
mut state: state, mut state: state,
mut blocked_task: option<task::task>, mut blocked_task: option<task::Task>,
mut payload: option<T> mut payload: option<T>
}; };
fn packet<T: send>() -> *packet<T> unsafe { fn packet<T: send>() -> *packet<T> unsafe {
let p: *packet<T> = unsafe::transmute(~{ let p: *packet<T> = unsafe::transmute(~{
mut state: empty, mut state: empty,
mut blocked_task: none::<task::task>, mut blocked_task: none::<task::Task>,
mut payload: none::<T> mut payload: none::<T>
}); });
p p

View file

@ -9,14 +9,15 @@ use std;
import task; import task;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::send; import comm::send;
import comm::port; import comm::port;
import comm::recv; import comm::recv;
fn grandchild(c: chan<int>) { send(c, 42); } fn grandchild(c: Chan<int>) { send(c, 42); }
fn child(c: chan<int>) { fn child(c: Chan<int>) {
task::spawn(|| grandchild(c) ) task::spawn(|| grandchild(c) )
} }

View file

@ -2,21 +2,23 @@ use std;
import vec; import vec;
import task; import task;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::Port;
import comm::port; import comm::port;
import comm::recv; import comm::recv;
import comm::send; import comm::send;
enum msg { closed, received(~[u8]), } enum msg { closed, received(~[u8]), }
fn producer(c: chan<~[u8]>) { fn producer(c: Chan<~[u8]>) {
send(c, ~[1u8, 2u8, 3u8, 4u8]); send(c, ~[1u8, 2u8, 3u8, 4u8]);
let empty: ~[u8] = ~[]; let empty: ~[u8] = ~[];
send(c, empty); send(c, empty);
} }
fn packager(cb: chan<chan<~[u8]>>, msg: chan<msg>) { fn packager(cb: Chan<Chan<~[u8]>>, msg: Chan<msg>) {
let p: port<~[u8]> = port(); let p: Port<~[u8]> = port();
send(cb, chan(p)); send(cb, chan(p));
loop { loop {
debug!{"waiting for bytes"}; debug!{"waiting for bytes"};
@ -37,13 +39,13 @@ fn packager(cb: chan<chan<~[u8]>>, msg: chan<msg>) {
} }
fn main() { fn main() {
let p: port<msg> = port(); let p: Port<msg> = port();
let ch = chan(p); let ch = chan(p);
let recv_reader: port<chan<~[u8]>> = port(); let recv_reader: Port<Chan<~[u8]>> = port();
let recv_reader_chan = chan(recv_reader); let recv_reader_chan = chan(recv_reader);
let pack = task::spawn(|| packager(recv_reader_chan, ch) ); let pack = task::spawn(|| packager(recv_reader_chan, ch) );
let source_chan: chan<~[u8]> = recv(recv_reader); let source_chan: Chan<~[u8]> = recv(recv_reader);
let prod = task::spawn(|| producer(source_chan) ); let prod = task::spawn(|| producer(source_chan) );
loop { loop {

View file

@ -4,7 +4,7 @@ import task::*;
fn a() { fn a() {
fn doit() { fn doit() {
fn b(c: chan<chan<int>>) { fn b(c: Chan<Chan<int>>) {
let p = port(); let p = port();
send(c, chan(p)); send(c, chan(p));
} }

View file

@ -2,19 +2,21 @@ use std;
import task; import task;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::Port;
import comm::port; import comm::port;
import comm::send; import comm::send;
import comm::recv; import comm::recv;
fn producer(c: chan<~[u8]>) { fn producer(c: Chan<~[u8]>) {
send(c, send(c,
~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, ~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
13u8]); 13u8]);
} }
fn main() { fn main() {
let p: port<~[u8]> = port(); let p: Port<~[u8]> = port();
let ch = chan(p); let ch = chan(p);
let prod = task::spawn(|| producer(ch) ); let prod = task::spawn(|| producer(ch) );

View file

@ -22,4 +22,4 @@ fn main() {
assert (y == 10); assert (y == 10);
} }
fn child(c: chan<int>) { send(c, 10); } fn child(c: Chan<int>) { send(c, 10); }

View file

@ -4,7 +4,7 @@ use std;
import task; import task;
import comm; import comm;
fn sub(parent: comm::chan<int>, id: int) { fn sub(parent: comm::Chan<int>, id: int) {
if id == 0 { if id == 0 {
comm::send(parent, 0); comm::send(parent, 0);
} else { } else {

View file

@ -14,9 +14,9 @@ fn run(i: int) {
return; return;
} }
do task::task().sched_mode(task::platform_thread).unlinked().spawn { do task::task().sched_mode(task::PlatformThread).unlinked().spawn {
task::yield(); task::yield();
do task::task().sched_mode(task::single_threaded).unlinked().spawn { do task::task().sched_mode(task::SingleThreaded).unlinked().spawn {
task::yield(); task::yield();
run(i - 1); run(i - 1);
task::yield(); task::yield();

View file

@ -1,4 +1,5 @@
use std; use std;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::send; import comm::send;
import comm::port; import comm::port;
@ -6,7 +7,7 @@ import comm::port;
// tests that ctrl's type gets inferred properly // tests that ctrl's type gets inferred properly
type command<K: send, V: send> = {key: K, val: V}; type command<K: send, V: send> = {key: K, val: V};
fn cache_server<K: send, V: send>(c: chan<chan<command<K, V>>>) { fn cache_server<K: send, V: send>(c: Chan<Chan<command<K, V>>>) {
let ctrl = port(); let ctrl = port();
send(c, chan(ctrl)); send(c, chan(ctrl));
} }

View file

@ -10,7 +10,7 @@ import str;
import comm; import comm;
import task; import task;
type ctx = comm::chan<int>; type ctx = comm::Chan<int>;
fn iotask(cx: ctx, ip: ~str) { fn iotask(cx: ctx, ip: ~str) {
assert (ip == ~"localhost"); assert (ip == ~"localhost");

View file

@ -6,7 +6,7 @@ import task;
// We're trying to trigger a race between send and port destruction that // We're trying to trigger a race between send and port destruction that
// results in the string not being freed // results in the string not being freed
fn starship(&&ch: comm::chan<~str>) { fn starship(&&ch: comm::Chan<~str>) {
for int::range(0, 10) |_i| { for int::range(0, 10) |_i| {
comm::send(ch, ~"pew pew"); comm::send(ch, ~"pew pew");
} }

View file

@ -3,6 +3,7 @@ use std;
import task; import task;
import task::task; import task::task;
import comm; import comm;
import comm::Chan;
import comm::chan; import comm::chan;
import comm::port; import comm::port;
import comm::send; import comm::send;
@ -17,7 +18,7 @@ fn main() {
test06(); test06();
} }
fn test00_start(ch: chan<int>, message: int, count: int) { fn test00_start(ch: Chan<int>, message: int, count: int) {
debug!{"Starting test00_start"}; debug!{"Starting test00_start"};
let mut i: int = 0; let mut i: int = 0;
while i < count { while i < count {
@ -93,7 +94,7 @@ fn test04() {
debug!{"Finishing up."}; debug!{"Finishing up."};
} }
fn test05_start(ch: chan<int>) { fn test05_start(ch: Chan<int>) {
send(ch, 10); send(ch, 10);
send(ch, 20); send(ch, 20);
send(ch, 30); send(ch, 30);

View file

@ -7,8 +7,8 @@ use std;
import task; import task;
class notify { class notify {
let ch: comm::chan<bool>; let v: @mut bool; let ch: comm::Chan<bool>; let v: @mut bool;
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; } new(ch: comm::Chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
drop { drop {
error!{"notify: task=%? v=%x unwinding=%b b=%b", error!{"notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(), task::get_task(),
@ -20,8 +20,8 @@ class notify {
} }
} }
fn joinable(+f: fn~()) -> comm::port<bool> { fn joinable(+f: fn~()) -> comm::Port<bool> {
fn wrapper(+c: comm::chan<bool>, +f: fn()) { fn wrapper(+c: comm::Chan<bool>, +f: fn()) {
let b = @mut false; let b = @mut false;
error!{"wrapper: task=%? allocated v=%x", error!{"wrapper: task=%? allocated v=%x",
task::get_task(), task::get_task(),
@ -36,7 +36,7 @@ fn joinable(+f: fn~()) -> comm::port<bool> {
p p
} }
fn join(port: comm::port<bool>) -> bool { fn join(port: comm::Port<bool>) -> bool {
comm::recv(port) comm::recv(port)
} }

View file

@ -3,7 +3,7 @@ import comm;
import task; import task;
import uint; import uint;
fn child(c: comm::chan<~uint>, i: uint) { fn child(c: comm::Chan<~uint>, i: uint) {
comm::send(c, ~i); comm::send(c, ~i);
} }

View file

@ -4,8 +4,8 @@ import task;
import comm; import comm;
class complainer { class complainer {
let c: comm::chan<bool>; let c: comm::Chan<bool>;
new(c: comm::chan<bool>) { new(c: comm::Chan<bool>) {
error!{"Hello!"}; error!{"Hello!"};
self.c = c; } self.c = c; }
drop { error!{"About to send!"}; drop { error!{"About to send!"};
@ -13,7 +13,7 @@ class complainer {
error!{"Sent!"}; } error!{"Sent!"}; }
} }
fn f(c: comm::chan<bool>) { fn f(c: comm::Chan<bool>) {
let _c <- complainer(c); let _c <- complainer(c);
fail; fail;
} }