Permalink
Browse files

Convert more core types to camel case

  • Loading branch information...
1 parent af43613 commit 9c6890f4884b1294dd13ad883162ab98e2dd27e5 @brson brson committed Aug 15, 2012
Showing with 415 additions and 390 deletions.
  1. +6 −6 doc/tutorial.md
  2. +2 −2 src/compiletest/procsrv.rs
  3. +29 −28 src/libcore/comm.rs
  4. +3 −0 src/libcore/core.rc
  5. +11 −11 src/libcore/future.rs
  6. +7 −7 src/libcore/os.rs
  7. +7 −7 src/libcore/priv.rs
  8. +2 −2 src/libcore/ptr.rs
  9. +2 −2 src/libcore/run.rs
  10. +177 −172 src/libcore/task.rs
  11. +1 −1 src/libstd/net_ip.rs
  12. +28 −28 src/libstd/net_tcp.rs
  13. +1 −1 src/libstd/sync.rs
  14. +3 −3 src/libstd/test.rs
  15. +4 −4 src/libstd/timer.rs
  16. +7 −7 src/libstd/uv_global_loop.rs
  17. +11 −11 src/libstd/uv_iotask.rs
  18. +8 −8 src/libstd/uv_ll.rs
  19. +2 −2 src/rustc/driver/rustc.rs
  20. +2 −2 src/rustdoc/astsrv.rs
  21. +5 −5 src/rustdoc/markdown_writer.rs
  22. +2 −2 src/rustdoc/page_pass.rs
  23. +1 −1 src/test/auxiliary/cci_capture_clause.rs
  24. +2 −2 src/test/bench/msgsend-ring.rs
  25. +1 −1 src/test/bench/msgsend.rs
  26. +7 −7 src/test/bench/shootout-chameneos-redux.rs
  27. +3 −3 src/test/bench/shootout-k-nucleotide.rs
  28. +3 −3 src/test/bench/shootout-mandelbrot.rs
  29. +1 −1 src/test/bench/shootout-threadring.rs
  30. +1 −1 src/test/bench/task-perf-linked-failure.rs
  31. +2 −2 src/test/bench/task-perf-one-million.rs
  32. +8 −6 src/test/bench/task-perf-word-count-generic.rs
  33. +3 −3 src/test/compile-fail/fully-qualified-type-name4.rs
  34. +2 −2 src/test/compile-fail/no-send-res-ports.rs
  35. +2 −1 src/test/run-fail/port-type.rs
  36. +3 −2 src/test/run-pass/basic-1.rs
  37. +3 −2 src/test/run-pass/basic-2.rs
  38. +3 −2 src/test/run-pass/basic.rs
  39. +1 −1 src/test/run-pass/binops.rs
  40. +4 −3 src/test/run-pass/chan-leak.rs
  41. +2 −1 src/test/run-pass/comm.rs
  42. +5 −4 src/test/run-pass/hashmap-memory.rs
  43. +2 −2 src/test/run-pass/issue-2718.rs
  44. +3 −2 src/test/run-pass/issue-507.rs
  45. +8 −6 src/test/run-pass/issue-687.rs
  46. +1 −1 src/test/run-pass/issue-783.rs
  47. +4 −2 src/test/run-pass/ivec-tag.rs
  48. +1 −1 src/test/run-pass/lazychan.rs
  49. +1 −1 src/test/run-pass/many.rs
  50. +2 −2 src/test/run-pass/platform_thread.rs
  51. +2 −1 src/test/run-pass/send-type-inference.rs
  52. +1 −1 src/test/run-pass/spawn-types.rs
  53. +1 −1 src/test/run-pass/task-comm-chan-cleanup4.rs
  54. +3 −2 src/test/run-pass/task-comm.rs
  55. +5 −5 src/test/run-pass/task-killjoin-rsrc.rs
  56. +1 −1 src/test/run-pass/unique-send-2.rs
  57. +3 −3 src/test/run-pass/unwind-resource.rs
View
12 doc/tutorial.md
@@ -2975,9 +2975,9 @@ the string in response. The child terminates when `0` is received.
Here is the function that implements the child task:
~~~~
-# import comm::{port, chan};
-fn stringifier(from_parent: port<uint>,
- to_parent: chan<~str>) {
+# import comm::{Port, port, Chan, chan};
+fn stringifier(from_parent: Port<uint>,
+ to_parent: Chan<~str>) {
let mut value: uint;
loop {
value = from_parent.recv();
@@ -2999,9 +2999,9 @@ Here is the code for the parent task:
~~~~
# import task::{spawn_conversation};
-# import comm::{chan, port};
-# fn stringifier(from_parent: comm::port<uint>,
-# to_parent: comm::chan<~str>) {
+# import comm::{Chan, chan, Port, port};
+# fn stringifier(from_parent: comm::Port<uint>,
+# to_parent: comm::Chan<~str>) {
# comm::send(to_parent, ~"22");
# comm::send(to_parent, ~"23");
# comm::send(to_parent, ~"0");
View
4 src/compiletest/procsrv.rs
@@ -62,12 +62,12 @@ fn run(lib_path: ~str,
writeclose(pipe_in.out, input);
let p = pipes::port_set();
let ch = p.chan();
- do task::spawn_sched(task::single_threaded) {
+ do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in);
ch.send((2, errput));
}
let ch = p.chan();
- do task::spawn_sched(task::single_threaded) {
+ do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in);
ch.send((1, output));
}
View
57 src/libcore/comm.rs
@@ -30,8 +30,8 @@
import either::Either;
import libc::size_t;
-export port;
-export chan;
+export Port, port;
+export Chan, chan;
export send;
export recv;
export peek;
@@ -48,8 +48,8 @@ export listen;
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
-enum port<T: send> {
- port_t(@port_ptr<T>)
+enum Port<T: send> {
+ Port_(@PortPtr<T>)
}
// It's critical that this only have one variant, so it has a record
@@ -64,40 +64,40 @@ enum port<T: send> {
* data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels.
*/
-enum chan<T: send> {
- chan_t(port_id)
+enum Chan<T: send> {
+ Chan_(port_id)
}
/// Constructs a port
-fn port<T: send>() -> port<T> {
- port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
+fn port<T: send>() -> Port<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 recv() -> T { recv(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 recv() -> T { recv_chan(self) }
fn peek() -> bool { peek_chan(self) }
}
/// 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();
f(po.chan())
}
-class port_ptr<T:send> {
+class PortPtr<T:send> {
let po: *rust_port;
new(po: *rust_port) { self.po = po; }
drop unsafe {
@@ -130,9 +130,9 @@ class port_ptr<T:send> {
* Fails if the port is detached or dead. Fails if the port
* 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;
new(p: *rust_port) { self.p = p; }
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) {
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
* construct it.
*/
-fn chan<T: send>(p: port<T>) -> chan<T> {
- chan_t(rustrt::get_port_id((**p).po))
+fn chan<T: send>(p: Port<T>) -> Chan<T> {
+ Chan_(rustrt::get_port_id((**p).po))
}
/**
* Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it.
*/
-fn send<T: send>(ch: chan<T>, +data: T) {
- let chan_t(p) = ch;
+fn send<T: send>(ch: Chan<T>, +data: T) {
+ let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
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
* 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
-fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) }
+fn peek<T: send>(p: Port<T>) -> bool { peek_((**p).po) }
#[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))
}
-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))
}
@@ -221,7 +221,7 @@ fn peek_(p: *rust_port) -> bool {
}
/// 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> {
let ports = ~[(**p_a).po, (**p_b).po];
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 */
-
+#[allow(non_camel_case_types)] // runtime type
enum rust_port {}
+#[allow(non_camel_case_types)] // runtime type
type port_id = int;
#[abi = "cdecl"]
@@ -329,7 +330,7 @@ fn chan_chan_infer() {
#[test]
fn chan_chan() {
- let p = port::<chan<int>>(), p2 = port::<int>();
+ let p = port::<Chan<int>>(), p2 = port::<int>();
let c = chan(p);
send(c, chan(p2));
recv(p);
View
3 src/libcore/core.rc
@@ -235,8 +235,11 @@ mod dlist_iter {
mod send_map;
// Concurrency
+#[warn(non_camel_case_types)]
mod comm;
+#[warn(non_camel_case_types)]
mod task;
+//#[warn(non_camel_ase_types)] pipec code continues to trip this warning
mod future;
mod pipes;
View
22 src/libcore/future.rs
@@ -18,7 +18,7 @@
import either::Either;
import pipes::recv;
-export future;
+export Future;
export extensions;
export from_value;
export from_port;
@@ -31,12 +31,12 @@ export spawn;
export future_pipe;
#[doc = "The future type"]
-enum future<A> = {
+enum Future<A> = {
mut v: Either<@A, fn@() -> A>
};
/// Methods on the `future` type
-impl<A:copy send> future<A> {
+impl<A:copy send> Future<A> {
fn get() -> A {
//! Get the value of the future
@@ -51,15 +51,15 @@ 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
*
* The value is immediately available and calling `get` later will
* not block.
*/
- future({
+ Future({
mut v: either::Left(@val)
})
}
@@ -68,7 +68,7 @@ macro_rules! move_it {
{$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 = "
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.
*
@@ -96,12 +96,12 @@ fn from_fn<A>(f: fn@() -> A) -> future<A> {
* function. It is not spawned into another task.
*/
- future({
+ Future({
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.
*
@@ -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
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
let v = match copy future.v {
View
14 src/libcore/os.rs
@@ -24,7 +24,7 @@ import option::{some, none};
import getcwd = rustrt::rust_getcwd;
import consts::*;
-import task::task_builder;
+import task::TaskBuilder;
export close, fclose, fsync_fd, waitpid;
export env, getenv, setenv, fdopen, pipe;
@@ -135,9 +135,9 @@ mod global_env {
}
enum Msg {
- MsgGetEnv(~str, comm::chan<option<~str>>),
- MsgSetEnv(~str, ~str, comm::chan<()>),
- MsgEnv(comm::chan<~[(~str,~str)]>)
+ MsgGetEnv(~str, comm::Chan<option<~str>>),
+ MsgSetEnv(~str, ~str, comm::Chan<()>),
+ MsgEnv(comm::Chan<~[(~str,~str)]>)
}
fn getenv(n: ~str) -> option<~str> {
@@ -161,18 +161,18 @@ mod global_env {
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();
unsafe {
priv::chan_from_global_ptr(global_ptr, || {
// FIXME (#2621): This would be a good place to use a very
// small foreign stack
- task::task().sched_mode(task::single_threaded).unlinked()
+ task::task().sched_mode(task::SingleThreaded).unlinked()
}, global_env_task)
}
}
- fn global_env_task(msg_po: comm::port<Msg>) {
+ fn global_env_task(msg_po: comm::Port<Msg>) {
unsafe {
do priv::weaken_task |weak_po| {
loop {
View
14 src/libcore/priv.rs
@@ -7,7 +7,7 @@
export chan_from_global_ptr, weaken_task;
import compare_and_swap = rustrt::rust_compare_and_swap_ptr;
-import task::task_builder;
+import task::TaskBuilder;
#[allow(non_camel_case_types)] // runtime type
type rust_port_id = uint;
@@ -29,9 +29,9 @@ type GlobalPtr = *libc::uintptr_t;
*/
unsafe fn chan_from_global_ptr<T: send>(
global: GlobalPtr,
- task_fn: fn() -> task::task_builder,
- +f: fn~(comm::port<T>)
-) -> comm::chan<T> {
+ task_fn: fn() -> task::TaskBuilder,
+ +f: fn~(comm::Port<T>)
+) -> comm::Chan<T> {
enum Msg {
Proceed,
@@ -185,7 +185,7 @@ fn test_from_global_chan2() {
* * Weak tasks must not be supervised. A supervised task keeps
* 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 ch = comm::chan(po);
unsafe {
@@ -195,8 +195,8 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
f(po);
class Unweaken {
- let ch: comm::chan<()>;
- new(ch: comm::chan<()>) { self.ch = ch; }
+ let ch: comm::Chan<()>;
+ new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe {
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
}
View
4 src/libcore/ptr.rs
@@ -173,9 +173,9 @@ impl<T> *T: Ptr {
#[test]
fn test() {
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 pptr: *mut pair = mut_addr_of(p);
+ let pptr: *mut Pair = mut_addr_of(p);
let iptr: *mut int = unsafe::reinterpret_cast(pptr);
assert (*iptr == 10);;
*iptr = 30;
View
4 src/libcore/run.rs
@@ -298,11 +298,11 @@ fn program_output(prog: &str, args: &[~str]) ->
// clever way to do this.
let p = comm::port();
let ch = comm::chan(p);
- do task::spawn_sched(task::single_threaded) {
+ do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in);
comm::send(ch, (2, errput));
};
- do task::spawn_sched(task::single_threaded) {
+ do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in);
comm::send(ch, (1, output));
};
View
349 src/libcore/task.rs
@@ -29,14 +29,15 @@
import result::result;
-export task;
-export task_result;
-export notification;
-export sched_mode;
-export sched_opts;
-export task_opts;
-export task_builder;
+export Task;
+export TaskResult;
+export Notification;
+export SchedMode;
+export SchedOpts;
+export TaskOpts;
+export TaskBuilder;
+export task;
export default_task_opts;
export get_opts;
export set_opts;
@@ -69,16 +70,16 @@ export local_data_get;
export local_data_set;
export local_data_modify;
-export single_threaded;
-export thread_per_core;
-export thread_per_task;
-export manual_threads;
-export platform_thread;
+export SingleThreaded;
+export ThreadPerCore;
+export ThreadPerTask;
+export ManualThreads;
+export PlatformThread;
/* Data types */
/// A handle to a task
-enum task { task_handle(task_id) }
+enum Task { TaskHandle(task_id) }
/**
* 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
* children tasks complete, recommend using a result future.
*/
-enum task_result {
- success,
- failure,
+enum TaskResult {
+ Success,
+ Failure,
}
/// A message type for notifying of task lifecycle events
-enum notification {
+enum Notification {
/// Sent when a task exits with the task handle and result
- exit(task, task_result)
+ Exit(Task, TaskResult)
}
/// Scheduler modes
-enum sched_mode {
+enum SchedMode {
/// All tasks run in the same OS thread
- single_threaded,
+ SingleThreaded,
/// Tasks are distributed among available CPUs
- thread_per_core,
+ ThreadPerCore,
/// Each task runs in its own OS thread
- thread_per_task,
+ ThreadPerTask,
/// Tasks are distributed among a fixed number of OS threads
- manual_threads(uint),
+ ManualThreads(uint),
/**
* Tasks are scheduled on the main OS thread
*
* 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.
*/
- platform_thread
+ PlatformThread
}
/**
@@ -136,8 +137,8 @@ enum sched_mode {
* default these foreign stacks have unspecified size, but with this
* option their size can be precisely specified.
*/
-type sched_opts = {
- mode: sched_mode,
+type SchedOpts = {
+ mode: SchedMode,
foreign_stack_size: option<uint>
};
@@ -168,11 +169,11 @@ type sched_opts = {
* into foreign code that blocks. Without doing so in a different
* scheduler other tasks will be impeded or even blocked indefinitely.
*/
-type task_opts = {
+type TaskOpts = {
linked: bool,
supervised: bool,
- notify_chan: option<comm::chan<notification>>,
- sched: option<sched_opts>,
+ notify_chan: option<comm::Chan<Notification>>,
+ sched: option<SchedOpts>,
};
/**
@@ -189,8 +190,8 @@ type task_opts = {
// the run function move them in.
// FIXME (#2585): Replace the 'consumed' bit with move mode on self
-enum task_builder = {
- opts: task_opts,
+enum TaskBuilder = {
+ opts: TaskOpts,
gen_body: fn@(+fn~()) -> fn~(),
can_not_copy: option<util::NonCopyable>,
mut consumed: bool,
@@ -201,32 +202,32 @@ enum task_builder = {
* configuration methods can be chained.
* For example, task().unlinked().spawn is equivalent to spawn_unlinked.
*/
-fn task() -> task_builder {
- task_builder({
+fn task() -> TaskBuilder {
+ TaskBuilder({
opts: default_task_opts(),
gen_body: |body| body, // Identity function
can_not_copy: none,
mut consumed: false,
})
}
-priv impl task_builder {
- fn consume() -> task_builder {
+priv impl TaskBuilder {
+ fn consume() -> TaskBuilder {
if self.consumed {
fail ~"Cannot copy a task_builder"; // Fake move mode on self
}
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,
* the other will not be killed.
*/
- fn unlinked() -> task_builder {
- task_builder({
+ fn unlinked() -> TaskBuilder {
+ TaskBuilder({
opts: { linked: false with self.opts },
can_not_copy: none,
with *self.consume()
@@ -237,8 +238,8 @@ impl task_builder {
* child's failure will not kill the parent, but the parent's will kill
* the child.
*/
- fn supervised() -> task_builder {
- task_builder({
+ fn supervised() -> TaskBuilder {
+ TaskBuilder({
opts: { linked: false, supervised: true with self.opts },
can_not_copy: none,
with *self.consume()
@@ -248,8 +249,8 @@ impl task_builder {
* Link the child task's and parent task's failures. If either fails, the
* other will be killed.
*/
- fn linked() -> task_builder {
- task_builder({
+ fn linked() -> TaskBuilder {
+ TaskBuilder({
opts: { linked: true, supervised: false with self.opts },
can_not_copy: none,
with *self.consume()
@@ -273,7 +274,7 @@ impl task_builder {
* # Failure
* 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
// handled in the library, I can imagine implementing this by just
// 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.
- let po = comm::port::<notification>();
+ let po = comm::port::<Notification>();
let ch = comm::chan(po);
blk(do future::from_fn {
match comm::recv(po) {
- exit(_, result) => result
+ Exit(_, result) => result
}
});
// Reconfigure self to use a notify channel.
- task_builder({
+ TaskBuilder({
opts: { notify_chan: some(ch) with self.opts },
can_not_copy: none,
with *self.consume()
})
}
/// Configure a custom scheduler mode for the task.
- fn sched_mode(mode: sched_mode) -> task_builder {
- task_builder({
+ fn sched_mode(mode: SchedMode) -> TaskBuilder {
+ TaskBuilder({
opts: { sched: some({ mode: mode, foreign_stack_size: none})
with self.opts },
can_not_copy: none,
@@ -322,9 +323,9 @@ impl task_builder {
* generator by applying the task body which results from the
* 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;
- task_builder({
+ TaskBuilder({
gen_body: |body| { wrapper(prev_gen_body(body)) },
can_not_copy: none,
with *self.consume()
@@ -366,7 +367,7 @@ impl task_builder {
* otherwise be required to establish communication from the parent
* 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_ch = comm::chan(setup_po);
do self.spawn {
@@ -382,8 +383,8 @@ impl task_builder {
* Runs a new task, setting up communication in both directions
*/
fn spawn_conversation<A: send, B: send>
- (+f: fn~(comm::port<A>, comm::chan<B>))
- -> (comm::port<B>, comm::chan<A>) {
+ (+f: fn~(comm::Port<A>, comm::Chan<B>))
+ -> (comm::Port<B>, comm::Chan<A>) {
let from_child = comm::port();
let to_parent = comm::chan(from_child);
let to_child = do self.spawn_listener |from_parent| {
@@ -414,16 +415,16 @@ impl task_builder {
comm::send(ch, f());
}
match future::get(&option::unwrap(result)) {
- success => result::ok(comm::recv(po)),
- failure => result::err(())
+ Success => result::ok(comm::recv(po)),
+ Failure => result::err(())
}
}
}
/* Task construction */
-fn default_task_opts() -> task_opts {
+fn default_task_opts() -> TaskOpts {
/*!
* The default task options
*
@@ -486,7 +487,7 @@ fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
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
*
@@ -497,8 +498,8 @@ fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> {
}
fn spawn_conversation<A: send, B: send>
- (+f: fn~(comm::port<A>, comm::chan<B>))
- -> (comm::port<B>, comm::chan<A>) {
+ (+f: fn~(comm::Port<A>, comm::Chan<B>))
+ -> (comm::Port<B>, comm::Chan<A>) {
/*!
* 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)
}
-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
*
@@ -555,10 +556,10 @@ fn failing() -> bool {
rustrt::rust_task_is_unwinding(rustrt::rust_get_task())
}
-fn get_task() -> task {
+fn get_task() -> 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 {
- class allow_failure {
+ class AllowFailure {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_allow_kill(self.t); }
}
let t = rustrt::rust_get_task();
- let _allow_failure = allow_failure(t);
+ let _allow_failure = AllowFailure(t);
rustrt::rust_task_inhibit_kill(t);
f()
}
/// The inverse of unkillable. Only ever to be used nested in unkillable().
unsafe fn rekillable<U>(f: fn() -> U) -> U {
- class disallow_failure {
+ class DisallowFailure {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_inhibit_kill(self.t); }
}
let t = rustrt::rust_get_task();
- let _allow_failure = disallow_failure(t);
+ let _allow_failure = DisallowFailure(t);
rustrt::rust_task_allow_kill(t);
f()
}
@@ -608,7 +609,7 @@ unsafe fn rekillable<U>(f: fn() -> U) -> U {
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
unsafe fn atomically<U>(f: fn() -> U) -> U {
- class defer_interrupts {
+ class DeferInterrupts {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop {
@@ -617,7 +618,7 @@ unsafe fn atomically<U>(f: fn() -> U) -> U {
}
}
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_yield(t);
f()
@@ -685,17 +686,21 @@ unsafe fn atomically<U>(f: fn() -> U) -> U {
*
****************************************************************************/
+#[allow(non_camel_case_types)] // runtime type
type sched_id = int;
+#[allow(non_camel_case_types)] // runtime type
type task_id = int;
// These are both opaque runtime/compiler types that we don't know the
// structure of and should only deal with via unsafe pointer
+#[allow(non_camel_case_types)] // runtime type
type rust_task = libc::c_void;
+#[allow(non_camel_case_types)] // runtime type
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 {
let task: *rust_task = *t;
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)
}
-fn taskset_insert(tasks: &mut taskset, task: *rust_task) {
+fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
let didnt_overwrite = tasks.insert(task, ());
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);
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)
}
// 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
// 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)
// 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.
-pure fn taskgroup_is_dead(tg: &taskgroup_data) -> bool {
+pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
(&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
// 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.
-type ancestor_node = {
+type AncestorNode = {
// Since the ancestor list is recursive, we end up with references to
// exclusives within other exclusives. This is dangerous business (if
// 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)].
generation: uint,
// 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.
- 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.
#[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) }
}
#[inline(always)]
-fn access_ancestors<U>(x: unsafe::Exclusive<ancestor_node>,
- blk: fn(x: &mut ancestor_node) -> U) -> U {
+fn access_ancestors<U>(x: unsafe::Exclusive<AncestorNode>,
+ blk: fn(x: &mut AncestorNode) -> U) -> U {
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.
// FIXME(#2190): Change option<fn@(...)> to option<fn&(...)>, to save on
// allocations. Once that bug is fixed, changing the sigil should suffice.
-fn each_ancestor(list: &mut ancestor_list,
- bail_opt: option<fn@(taskgroup_inner)>,
- forward_blk: fn(taskgroup_inner) -> bool)
+fn each_ancestor(list: &mut AncestorList,
+ bail_opt: option<fn@(TaskGroupInner)>,
+ forward_blk: fn(TaskGroupInner) -> bool)
-> bool {
// "Kickoff" call - there was no last generation.
return !coalesce(list, bail_opt, forward_blk, uint::max_value);
// Recursively iterates, and coalesces afterwards if needed. Returns
// whether or not unwinding is needed (i.e., !successful iteration).
- fn coalesce(list: &mut ancestor_list,
- bail_opt: option<fn@(taskgroup_inner)>,
- forward_blk: fn(taskgroup_inner) -> bool,
+ fn coalesce(list: &mut AncestorList,
+ bail_opt: option<fn@(TaskGroupInner)>,
+ forward_blk: fn(TaskGroupInner) -> bool,
last_generation: uint) -> bool {
// 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) =
iterate(tmp_list, bail_opt, forward_blk, last_generation);
// What should our next ancestor end up being?
@@ -816,10 +821,10 @@ fn each_ancestor(list: &mut ancestor_list,
// bool:
// True if the supplied block did 'break', here or in any recursive
// calls. If so, must call the unwinder on all previous nodes.
- fn iterate(ancestors: ancestor_list,
- bail_opt: option<fn@(taskgroup_inner)>,
- forward_blk: fn(taskgroup_inner) -> bool,
- last_generation: uint) -> (option<ancestor_list>, bool) {
+ fn iterate(ancestors: AncestorList,
+ bail_opt: option<fn@(TaskGroupInner)>,
+ forward_blk: fn(TaskGroupInner) -> bool,
+ last_generation: uint) -> (option<AncestorList>, bool) {
// At each step of iteration, three booleans are at play which govern
// how the iteration should behave.
// '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 {
// Swap the list out here; the caller replaces us with it.
let rest = util::replace(&mut nobe.ancestors,
- ancestor_list(none));
+ AncestorList(none));
(some(rest), need_unwind)
} else {
(none, need_unwind)
@@ -894,8 +899,8 @@ fn each_ancestor(list: &mut ancestor_list,
};
// Wrapper around exclusive::with that appeases borrowck.
- fn with_parent_tg<U>(parent_group: &mut option<taskgroup_arc>,
- blk: fn(taskgroup_inner) -> U) -> U {
+ fn with_parent_tg<U>(parent_group: &mut option<TaskGroupArc>,
+ blk: fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside.
let tmp_arc = option::swap_unwrap(parent_group);
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.
-class tcb {
+class Tcb {
let me: *rust_task;
// 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.
- let mut ancestors: ancestor_list;
+ let mut ancestors: AncestorList;
let is_main: bool;
- let notifier: option<auto_notify>;
- new(me: *rust_task, -tasks: taskgroup_arc, -ancestors: ancestor_list,
- is_main: bool, -notifier: option<auto_notify>) {
+ let notifier: option<AutoNotify>;
+ new(me: *rust_task, -tasks: TaskGroupArc, -ancestors: AncestorList,
+ is_main: bool, -notifier: option<AutoNotify>) {
self.me = me;
self.tasks = tasks;
self.ancestors = ancestors;
@@ -947,20 +952,20 @@ class tcb {
}
}
-class auto_notify {
- let notify_chan: comm::chan<notification>;
+class AutoNotify {
+ let notify_chan: comm::Chan<Notification>;
let mut failed: bool;
- new(chan: comm::chan<notification>) {
+ new(chan: comm::Chan<Notification>) {
self.notify_chan = chan;
self.failed = true; // Un-set above when taskgroup successfully made.
}
drop {
- let result = if self.failed { failure } else { success };
- comm::send(self.notify_chan, exit(get_task(), result));
+ let result = if self.failed { Failure } else { Success };
+ 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 {
let newstate = util::replace(state, none);
// 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'.
-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);
// If 'none', already failing and we've already gotten a kill signal.
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'.
-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
// having "let mut newstate" here, swapping inside, and iterating after.
// 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)
- -> (taskgroup_arc, ancestor_list, bool) {
+ -> (TaskGroupArc, AncestorList, bool) {
let spawner = rustrt::rust_get_task();
/*######################################################################*
* Step 1. Get spawner's taskgroup info.
@@ -1047,7 +1052,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
mut descendants: new_taskset() }));
// Main task/group has no ancestors, no notifier, etc.
let group =
- @tcb(spawner, tasks, ancestor_list(none), true, none);
+ @Tcb(spawner, tasks, AncestorList(none), true, none);
unsafe { local_set(spawner, taskgroup_key!(), group); }
group
}
@@ -1080,18 +1085,18 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
};
assert new_generation < uint::max_value;
// Build a new node in the ancestor list.
- ancestor_list(some(unsafe::exclusive(
+ AncestorList(some(unsafe::exclusive(
{ generation: new_generation,
mut parent_group: some(spawner_group.tasks.clone()),
mut ancestors: old_ancestors })))
} else {
// Child has no ancestors.
- ancestor_list(none)
+ AncestorList(none)
};
(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:
// match ancestors
// 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 result = ancestor_arc.clone();
**ancestors <- some(ancestor_arc);
- ancestor_list(some(result))
+ AncestorList(some(result))
} 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) =
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.
// (3b) Otherwise it builds a task control structure and puts it in TLS,
// (4) ...and runs the provided body function.
- fn make_child_wrapper(child: *rust_task, +child_arc: taskgroup_arc,
- +ancestors: ancestor_list, is_main: bool,
- notify_chan: option<comm::chan<notification>>,
+ fn make_child_wrapper(child: *rust_task, +child_arc: TaskGroupArc,
+ +ancestors: AncestorList, is_main: bool,
+ notify_chan: option<comm::Chan<Notification>>,
+f: fn~()) -> fn~() {
let child_data = ~mut some((child_arc, ancestors));
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
// 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) {
- let group = @tcb(child, child_arc, ancestors,
+ let group = @Tcb(child, child_arc, ancestors,
is_main, notifier);
unsafe { local_set(child, taskgroup_key!(), group); }
// 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
// groups. If any enlistment fails, some task was already failing, so
// don't let the child task run, and undo every successful enlistment.
- fn enlist_many(child: *rust_task, child_arc: taskgroup_arc,
- ancestors: &mut ancestor_list) -> bool {
+ fn enlist_many(child: *rust_task, child_arc: TaskGroupArc,
+ ancestors: &mut AncestorList) -> bool {
// Join this taskgroup.
let mut result =
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 {
fail ~"foreign_stack_size scheduler option unimplemented";
}
let num_threads = match opts.mode {
- single_threaded => 1u,
- thread_per_core => {
+ SingleThreaded => 1u,
+ ThreadPerCore => {
fail ~"thread_per_core scheduling mode unimplemented"
}
- thread_per_task => {
+ ThreadPerTask => {
fail ~"thread_per_task scheduling mode unimplemented"
}
- manual_threads(threads) => {
+ ManualThreads(threads) => {
if threads == 0u {
fail ~"can not create a scheduler with no 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)
} else {
rustrt::rust_osmain_sched_id()
@@ -1262,34 +1267,34 @@ fn spawn_raw(+opts: task_opts, +f: fn~()) {
*
* 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 { }
-impl<T: owned> @T: local_data { }
+trait LocalData { }
+impl<T: owned> @T: LocalData { }
// 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.
-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 *.
-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 {
assert !map_ptr.is_null();
// 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.
}
// 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.
// NOTE: The map's box lives in TLS invisibly referenced once. Each time
// we retrieve it for get/set, we make another reference, which get/set
// drop when they finish. No "re-storing after modifying" is needed.
let map_ptr = rustrt::rust_get_task_local_data(task);
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.
rustrt::rust_set_task_local_data(task, unsafe::reinterpret_cast(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>(
- key: local_data_key<T>) -> *libc::c_void {
+ key: LocalDataKey<T>) -> *libc::c_void {
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
// 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!
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)> {
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>(
- task: *rust_task, key: local_data_key<T>,
+ task: *rust_task, key: LocalDataKey<T>,
do_pop: bool) -> option<@T> {
let map = get_task_local_map(task);
@@ -1354,20 +1359,20 @@ unsafe fn local_get_helper<T: owned>(
unsafe fn local_pop<T: owned>(
task: *rust_task,
- key: local_data_key<T>) -> option<@T> {
+ key: LocalDataKey<T>) -> option<@T> {
local_get_helper(task, key, true)
}
unsafe fn local_get<T: owned>(
task: *rust_task,
- key: local_data_key<T>) -> option<@T> {
+ key: LocalDataKey<T>) -> option<@T> {
local_get_helper(task, key, false)
}
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);
// 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
// when the box is destroyed.
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.
let new_entry = some((keyval, data_ptr, data_box));
// Find a place to put it.
@@ -1399,7 +1404,7 @@ unsafe fn local_set<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>) {
// 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.
*/
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)
}
@@ -1424,7 +1429,7 @@ unsafe fn local_data_pop<T: owned>(
* table until explicitly removed.
*/
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)
}
@@ -1433,7 +1438,7 @@ unsafe fn local_data_get<T: owned>(
* that value is overwritten (and its destructor is run).
*/
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)
}
@@ -1442,7 +1447,7 @@ unsafe fn local_data_set<T: owned>(
* data is removed (and its reference dropped).
*/
unsafe fn local_data_modify<T: owned>(
- key: local_data_key<T>,
+ key: LocalDataKey<T>,
modify_fn: fn(option<@T>) -> option<@T>) {
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
// they don't make sense (redundant with task().supervised()).
let b0 = task();
- let b1 = task_builder({
+ let b1 = TaskBuilder({
opts: { linked: true, supervised: true with b0.opts },
can_not_copy: none,
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
// they don't make sense (redundant with task().supervised()).
let b0 = task();
- let b1 = task_builder({
+ let b1 = TaskBuilder({
opts: { linked: true, supervised: true with b0.opts },
can_not_copy: none,
with *b0
@@ -1667,7 +1672,7 @@ fn test_spawn_raw_notify() {
comm::send(task_ch, get_task());
}
let task_ = comm::recv(task_po);
- assert comm::recv(notify_po) == exit(task_, success);
+ assert comm::recv(notify_po) == Exit(task_, Success);
let opts = {
linked: false,
@@ -1679,7 +1684,7 @@ fn test_spawn_raw_notify() {
fail;
}
let task_ = comm::recv(task_po);
- assert comm::recv(notify_po) == exit(task_, failure);
+ assert comm::recv(notify_po) == Exit(task_, Failure);
}
#[test]
@@ -1712,13 +1717,13 @@ fn test_add_wrapper() {
fn test_future_result() {
let mut result = none;
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;
do task().future_result(|+r| { result = some(r); }).unlinked().spawn {
fail;
}
- assert future::get(&option::unwrap(result)) == failure;
+ assert future::get(&option::unwrap(result)) == Failure;
}
#[test] #[should_fail] #[ignore(cfg(windows))]
@@ -1779,18 +1784,18 @@ fn test_try_fail() {
#[should_fail]
#[ignore(cfg(windows))]
fn test_spawn_sched_no_threads() {
- do spawn_sched(manual_threads(0u)) { }
+ do spawn_sched(ManualThreads(0u)) { }
}
#[test]
fn test_spawn_sched() {
let po = comm::port();
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();
- do spawn_sched(single_threaded) {
+ do spawn_sched(SingleThreaded) {
let child_sched_id = rustrt::rust_get_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 ch = comm::chan(po);
- do spawn_sched(single_threaded) {
+ do spawn_sched(SingleThreaded) {
let parent_sched_id = rustrt::rust_get_sched_id();
do spawn {
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();
- do spawn_sched(single_threaded) {
+ do spawn_sched(SingleThreaded) {
testrt::rust_dbg_lock_lock(lock);
comm::send(start_ch, ());
@@ -1864,7 +1869,7 @@ fn test_spawn_sched_blocking() {
// Wait until the other task has its lock
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;
while val > 0 {
val = comm::recv(po);
@@ -1918,7 +1923,7 @@ fn test_avoid_copying_the_body_spawn() {
#[test]
fn test_avoid_copying_the_body_spawn_listener() {
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();
});
}
@@ -1936,7 +1941,7 @@ fn test_avoid_copying_the_body_task_spawn() {
#[test]
fn test_avoid_copying_the_body_spawn_listener_1() {
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();
});
}
@@ -1964,7 +1969,7 @@ fn test_avoid_copying_the_body_unlinked() {
fn test_platform_thread() {
let po = comm::port();
let ch = comm::chan(po);
- do task().sched_mode(platform_thread).spawn {
+ do task().sched_mode(PlatformThread).spawn {
comm::send(ch, ());
}
comm::recv(po);
View
2 src/libstd/net_ip.rs
@@ -245,7 +245,7 @@ mod v6 {
}
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,
View
56 src/libstd/net_tcp.rs
@@ -292,7 +292,7 @@ fn write(sock: tcp_socket, raw_write_data: ~[u8])
* value as the `err` variant
*/
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));
do future_spawn {
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
*/
fn read_start(sock: tcp_socket)
- -> result::result<comm::port<
+ -> result::result<comm::Port<
result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe {
let socket_data = ptr::addr_of(*(sock.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
*/
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 {
log(debug, fmt!{"taking the read_port out of commission %?", read_port});
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
*/
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));
do future_spawn {
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,
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,
- comm::chan<option<tcp_err_data>>))
+ comm::Chan<option<tcp_err_data>>))
-> result::result<(), tcp_listen_err_data> unsafe {
do listen_common(host_ip, port, backlog, iotask, on_establish_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,
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))
-> result::result<(), tcp_listen_err_data> unsafe {
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`
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> {
read_start(self)
}
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> {
read_stop(self, read_port)
}
@@ -738,15 +738,15 @@ impl tcp_socket {
read(self, timeout_msecs)
}
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)
}
fn write(raw_write_data: ~[u8])
-> result::result<(), tcp_err_data> {
write(self, raw_write_data)
}
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)
}
}
@@ -922,7 +922,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
// shared impl for read_start
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 {
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
let start_po = comm::port::<option<uv::ll::uv_err_data>>();
@@ -1002,8 +1002,8 @@ enum tcp_new_connection {
type tcp_listen_fc_data = {
server_stream_ptr: *uv::ll::uv_tcp_t,
- stream_closed_ch: comm::chan<()>,
- kill_ch: comm::chan<option<tcp_err_data>>,
+ stream_closed_ch: comm::Chan<()>,
+ kill_ch: comm::Chan<option<tcp_err_data>>,
on_connect_cb: fn~(*uv::ll::uv_tcp_t),
iotask: iotask,
mut active: bool
@@ -1050,7 +1050,7 @@ enum tcp_write_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)
}
@@ -1116,7 +1116,7 @@ extern fn on_alloc_cb(handle: *libc::c_void,
}
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 {
@@ -1145,12 +1145,12 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t,
}
type write_req_data = {
- result_ch: comm::chan<tcp_write_result>
+ result_ch: comm::Chan<tcp_write_result>
};
type connect_req_data = {
- result_ch: comm::chan<conn_attempt>,
- closed_signal_ch: comm::chan<()>
+ result_ch: comm::Chan<conn_attempt>,
+ closed_signal_ch: comm::Chan<()>
};
extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
@@ -1198,8 +1198,8 @@ enum conn_attempt {
}
type tcp_socket_data = {
- reader_po: comm::port<result::result<~[u8], tcp_err_data>>,
- reader_ch: comm::chan<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>>,
stream_handle_ptr: *uv::ll::uv_tcp_t,
connect_req: uv::ll::uv_connect_t,
write_req: uv::ll::uv_write_t,
@@ -1285,7 +1285,7 @@ mod test {
let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po);
// server
- do task::spawn_sched(task::manual_threads(1u)) {
+ do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
run_tcp_test_server(
server_ip,
@@ -1351,7 +1351,7 @@ mod test {
let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po);
// server
- do task::spawn_sched(task::manual_threads(1u)) {
+ do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
run_tcp_test_server(
server_ip,
@@ -1421,7 +1421,7 @@ mod test {
let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po);
// server
- do task::spawn_sched(task::manual_threads(1u)) {
+ do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
run_tcp_test_server(
server_ip,
@@ -1475,8 +1475,8 @@ mod test {
}
fn run_tcp_test_server(server_ip: ~str, server_port: uint, resp: ~str,
- server_ch: comm::chan<~str>,
- cont_ch: comm::chan<()>,
+ server_ch: comm::Chan<~str>,
+ cont_ch: comm::Chan<()>,
iotask: iotask) -> ~str {
let server_ip_addr = ip::v4::parse_addr(server_ip);
let listen_result = listen(server_ip_addr, server_port, 128u, iotask,
@@ -1491,7 +1491,7 @@ mod test {
|new_conn, kill_ch| {
log(debug, ~"SERVER: new connection!");
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");
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,
- client_ch: comm::chan<~str>,
+ client_ch: comm::Chan<~str>,
iotask: iotask) -> result::result<~str,
tcp_connect_err_data> {
let server_ip_addr = ip::v4::parse_addr(server_ip);
View
2 src/libstd/sync.rs