about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-18 23:06:29 -0800
committerbors <bors@rust-lang.org>2013-11-18 23:06:29 -0800
commitf4c22f75d46e94985d2fe45c896bde65e991b13d (patch)
treeb811656373ff40c6840da947869871c80eeda43f /src/libstd/rt
parentf5f5d5aac762a554850d291165536ba752260303 (diff)
parentf977bedafd657b52fb618cc788cc31f35336270d (diff)
downloadrust-f4c22f75d46e94985d2fe45c896bde65e991b13d.tar.gz
rust-f4c22f75d46e94985d2fe45c896bde65e991b13d.zip
auto merge of #10561 : pcwalton/rust/procify, r=alexcrichton
r? @alexcrichton
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/context.rs16
-rw-r--r--src/libstd/rt/kill.rs9
-rw-r--r--src/libstd/rt/mod.rs12
-rw-r--r--src/libstd/rt/sched.rs4
-rw-r--r--src/libstd/rt/task.rs31
-rw-r--r--src/libstd/rt/test.rs30
-rw-r--r--src/libstd/rt/thread.rs8
7 files changed, 64 insertions, 46 deletions
diff --git a/src/libstd/rt/context.rs b/src/libstd/rt/context.rs
index 6fcc8e32111..e59704a6435 100644
--- a/src/libstd/rt/context.rs
+++ b/src/libstd/rt/context.rs
@@ -25,7 +25,7 @@ pub static RED_ZONE: uint = 20 * 1024;
 // then misalign the regs again.
 pub struct Context {
     /// The context entry point, saved here for later destruction
-    priv start: Option<~~fn()>,
+    priv start: Option<~proc()>,
     /// Hold the registers while the task or scheduler is suspended
     priv regs: ~Registers,
     /// Lower bound and upper bound for the stack
@@ -41,18 +41,24 @@ impl Context {
         }
     }
 
-    /// Create a new context that will resume execution by running ~fn()
-    pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context {
+    /// Create a new context that will resume execution by running proc()
+    pub fn new(start: proc(), stack: &mut StackSegment) -> Context {
         // FIXME #7767: Putting main into a ~ so it's a thin pointer and can
         // be passed to the spawn function.  Another unfortunate
         // allocation
         let start = ~start;
 
         // The C-ABI function that is the task entry point
-        extern fn task_start_wrapper(f: &~fn()) { (*f)() }
+        extern fn task_start_wrapper(f: &proc()) {
+            // XXX(pcwalton): This may be sketchy.
+            unsafe {
+                let f: &|| = transmute(f);
+                (*f)()
+            }
+        }
 
         let fp: *c_void = task_start_wrapper as *c_void;
-        let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
+        let argp: *c_void = unsafe { transmute::<&proc(), *c_void>(&*start) };
         let sp: *uint = stack.end();
         let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
         // Save and then immediately load the current context,
diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs
index 2709c118191..f7abc33ce14 100644
--- a/src/libstd/rt/kill.rs
+++ b/src/libstd/rt/kill.rs
@@ -110,7 +110,7 @@ see a failure from the grandchild task. While we could achieve this by having
 each intermediate task block on its handle, this keeps around the other resources
 the task was using. To be more efficient, this is accomplished via "tombstones".
 
-A tombstone is a closure, ~fn() -> bool, which will perform any waiting necessary
+A tombstone is a closure, proc() -> bool, which will perform any waiting necessary
 to collect the exit code of descendant tasks. In its environment is captured
 the KillHandle of whichever task created the tombstone, and perhaps also any
 tombstones that that task itself had, and finally also another tombstone,
@@ -205,7 +205,7 @@ struct KillHandleInner {
     // Locklessly accessed; protected by the enclosing refcount's barriers.
     any_child_failed: bool,
     // A lazy list, consuming which may unwrap() many child tombstones.
-    child_tombstones: Option<~fn() -> bool>,
+    child_tombstones: Option<proc() -> bool>,
     // Protects multiple children simultaneously creating tombstones.
     graveyard_lock: LittleLock,
 }
@@ -223,7 +223,7 @@ pub struct Death {
     priv watching_parent: Option<KillHandle>,
     // Action to be done with the exit code. If set, also makes the task wait
     // until all its watched children exit before collecting the status.
-    on_exit:         Option<~fn(UnwindResult)>,
+    on_exit:         Option<proc(UnwindResult)>,
     // nesting level counter for task::unkillable calls (0 == killable).
     priv unkillable:      int,
     // nesting level counter for unstable::atomically calls (0 == can deschedule).
@@ -525,7 +525,8 @@ impl KillHandle {
         // NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
         #[inline]
         fn add_lazy_tombstone(parent: &mut KillHandle,
-                              blk: &fn(Option<~fn() -> bool>) -> ~fn() -> bool) {
+                              blk: &fn(Option<proc() -> bool>)
+                              -> proc() -> bool) {
 
             let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
             unsafe {
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs
index c90aafff20c..72e1f6a6e8f 100644
--- a/src/libstd/rt/mod.rs
+++ b/src/libstd/rt/mod.rs
@@ -207,7 +207,7 @@ pub mod borrowck;
 /// # Return value
 ///
 /// The return value is used as the process return code. 0 on success, 101 on error.
-pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
+pub fn start(argc: int, argv: **u8, main: proc()) -> int {
 
     init(argc, argv);
     let exit_code = run(main);
@@ -221,7 +221,7 @@ pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
 ///
 /// This is appropriate for running code that must execute on the main thread,
 /// such as the platform event loop and GUI.
-pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int {
+pub fn start_on_main_thread(argc: int, argv: **u8, main: proc()) -> int {
     init(argc, argv);
     let exit_code = run_on_main_thread(main);
     cleanup();
@@ -254,15 +254,15 @@ pub fn cleanup() {
 /// Configures the runtime according to the environment, by default
 /// using a task scheduler with the same number of threads as cores.
 /// Returns a process exit code.
-pub fn run(main: ~fn()) -> int {
+pub fn run(main: proc()) -> int {
     run_(main, false)
 }
 
-pub fn run_on_main_thread(main: ~fn()) -> int {
+pub fn run_on_main_thread(main: proc()) -> int {
     run_(main, true)
 }
 
-fn run_(main: ~fn(), use_main_sched: bool) -> int {
+fn run_(main: proc(), use_main_sched: bool) -> int {
     static DEFAULT_ERROR_CODE: int = 101;
 
     let nscheds = util::default_sched_threads();
@@ -341,7 +341,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
     // When the main task exits, after all the tasks in the main
     // task tree, shut down the schedulers and set the exit code.
     let handles = Cell::new(handles);
-    let on_exit: ~fn(UnwindResult) = |exit_success| {
+    let on_exit: proc(UnwindResult) = |exit_success| {
         unsafe {
             assert!(!(*exited_already.get()).swap(true, SeqCst),
                     "the runtime already exited");
diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs
index 26cd405efe2..00895289b6a 100644
--- a/src/libstd/rt/sched.rs
+++ b/src/libstd/rt/sched.rs
@@ -990,7 +990,9 @@ mod test {
                 assert!(Task::on_appropriate_sched());
             };
 
-            let on_exit: ~fn(UnwindResult) = |exit_status| rtassert!(exit_status.is_success());
+            let on_exit: proc(UnwindResult) = |exit_status| {
+                rtassert!(exit_status.is_success())
+            };
             task.death.on_exit = Some(on_exit);
 
             sched.bootstrap(task);
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index e73d15abb6c..6d3eec9a921 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -139,7 +139,10 @@ impl Task {
 
     // A helper to build a new task using the dynamically found
     // scheduler and task. Only works in GreenTask context.
-    pub fn build_homed_child(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
+    pub fn build_homed_child(stack_size: Option<uint>,
+                             f: proc(),
+                             home: SchedHome)
+                             -> ~Task {
         let f = Cell::new(f);
         let home = Cell::new(home);
         do Local::borrow |running_task: &mut Task| {
@@ -153,11 +156,14 @@ impl Task {
         }
     }
 
-    pub fn build_child(stack_size: Option<uint>, f: ~fn()) -> ~Task {
+    pub fn build_child(stack_size: Option<uint>, f: proc()) -> ~Task {
         Task::build_homed_child(stack_size, f, AnySched)
     }
 
-    pub fn build_homed_root(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
+    pub fn build_homed_root(stack_size: Option<uint>,
+                            f: proc(),
+                            home: SchedHome)
+                            -> ~Task {
         let f = Cell::new(f);
         let home = Cell::new(home);
         do Local::borrow |running_task: &mut Task| {
@@ -171,7 +177,7 @@ impl Task {
         }
     }
 
-    pub fn build_root(stack_size: Option<uint>, f: ~fn()) -> ~Task {
+    pub fn build_root(stack_size: Option<uint>, f: proc()) -> ~Task {
         Task::build_homed_root(stack_size, f, AnySched)
     }
 
@@ -196,21 +202,21 @@ impl Task {
 
     pub fn new_root(stack_pool: &mut StackPool,
                     stack_size: Option<uint>,
-                    start: ~fn()) -> Task {
+                    start: proc()) -> Task {
         Task::new_root_homed(stack_pool, stack_size, AnySched, start)
     }
 
     pub fn new_child(&mut self,
                      stack_pool: &mut StackPool,
                      stack_size: Option<uint>,
-                     start: ~fn()) -> Task {
+                     start: proc()) -> Task {
         self.new_child_homed(stack_pool, stack_size, AnySched, start)
     }
 
     pub fn new_root_homed(stack_pool: &mut StackPool,
                           stack_size: Option<uint>,
                           home: SchedHome,
-                          start: ~fn()) -> Task {
+                          start: proc()) -> Task {
         Task {
             heap: LocalHeap::new(),
             gc: GarbageCollector,
@@ -233,7 +239,7 @@ impl Task {
                            stack_pool: &mut StackPool,
                            stack_size: Option<uint>,
                            home: SchedHome,
-                           start: ~fn()) -> Task {
+                           start: proc()) -> Task {
         Task {
             heap: LocalHeap::new(),
             gc: GarbageCollector,
@@ -404,7 +410,10 @@ impl Drop for Task {
 
 impl Coroutine {
 
-    pub fn new(stack_pool: &mut StackPool, stack_size: Option<uint>, start: ~fn()) -> Coroutine {
+    pub fn new(stack_pool: &mut StackPool,
+               stack_size: Option<uint>,
+               start: proc())
+               -> Coroutine {
         let stack_size = match stack_size {
             Some(size) => size,
             None => env::min_stack()
@@ -425,9 +434,9 @@ impl Coroutine {
         }
     }
 
-    fn build_start_wrapper(start: ~fn()) -> ~fn() {
+    fn build_start_wrapper(start: proc()) -> proc() {
         let start_cell = Cell::new(start);
-        let wrapper: ~fn() = || {
+        let wrapper: proc() = || {
             // First code after swap to this new context. Run our
             // cleanup job.
             unsafe {
diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs
index c1a7893f5a5..d87eb56a650 100644
--- a/src/libstd/rt/test.rs
+++ b/src/libstd/rt/test.rs
@@ -64,28 +64,28 @@ pub fn new_test_sched() -> Scheduler {
     return sched;
 }
 
-pub fn run_in_uv_task(f: ~fn()) {
+pub fn run_in_uv_task(f: proc()) {
     let f = Cell::new(f);
     do run_in_bare_thread {
         run_in_uv_task_core(f.take());
     }
 }
 
-pub fn run_in_newsched_task(f: ~fn()) {
+pub fn run_in_newsched_task(f: proc()) {
     let f = Cell::new(f);
     do run_in_bare_thread {
         run_in_newsched_task_core(f.take());
     }
 }
 
-pub fn run_in_uv_task_core(f: ~fn()) {
+pub fn run_in_uv_task_core(f: proc()) {
 
     use rt::sched::Shutdown;
 
     let mut sched = ~new_test_uv_sched();
     let exit_handle = Cell::new(sched.make_handle());
 
-    let on_exit: ~fn(UnwindResult) = |exit_status| {
+    let on_exit: proc(UnwindResult) = |exit_status| {
         exit_handle.take().send(Shutdown);
         rtassert!(exit_status.is_success());
     };
@@ -95,13 +95,13 @@ pub fn run_in_uv_task_core(f: ~fn()) {
     sched.bootstrap(task);
 }
 
-pub fn run_in_newsched_task_core(f: ~fn()) {
+pub fn run_in_newsched_task_core(f: proc()) {
     use rt::sched::Shutdown;
 
     let mut sched = ~new_test_sched();
     let exit_handle = Cell::new(sched.make_handle());
 
-    let on_exit: ~fn(UnwindResult) = |exit_status| {
+    let on_exit: proc(UnwindResult) = |exit_status| {
         exit_handle.take().send(Shutdown);
         rtassert!(exit_status.is_success());
     };
@@ -195,7 +195,7 @@ pub fn prepare_for_lots_of_tests() {
 /// Create more than one scheduler and run a function in a task
 /// in one of the schedulers. The schedulers will stay alive
 /// until the function `f` returns.
-pub fn run_in_mt_newsched_task(f: ~fn()) {
+pub fn run_in_mt_newsched_task(f: proc()) {
     use os;
     use from_str::FromStr;
     use rt::sched::Shutdown;
@@ -245,7 +245,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
         }
 
         let handles = Cell::new(handles);
-        let on_exit: ~fn(UnwindResult) = |exit_status| {
+        let on_exit: proc(UnwindResult) = |exit_status| {
             let mut handles = handles.take();
             // Tell schedulers to exit
             for handle in handles.mut_iter() {
@@ -294,16 +294,16 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
 }
 
 /// Test tasks will abort on failure instead of unwinding
-pub fn spawntask(f: ~fn()) {
+pub fn spawntask(f: proc()) {
     Scheduler::run_task(Task::build_child(None, f));
 }
 
 /// Create a new task and run it right now. Aborts on failure
-pub fn spawntask_later(f: ~fn()) {
+pub fn spawntask_later(f: proc()) {
     Scheduler::run_task_later(Task::build_child(None, f));
 }
 
-pub fn spawntask_random(f: ~fn()) {
+pub fn spawntask_random(f: proc()) {
     use rand::{Rand, rng};
 
     let mut rng = rng();
@@ -316,11 +316,11 @@ pub fn spawntask_random(f: ~fn()) {
     }
 }
 
-pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
+pub fn spawntask_try(f: proc()) -> Result<(),()> {
 
     let (port, chan) = oneshot();
     let chan = Cell::new(chan);
-    let on_exit: ~fn(UnwindResult) = |exit_status| chan.take().send(exit_status);
+    let on_exit: proc(UnwindResult) = |exit_status| chan.take().send(exit_status);
 
     let mut new_task = Task::build_root(None, f);
     new_task.death.on_exit = Some(on_exit);
@@ -333,7 +333,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
 }
 
 /// Spawn a new task in a new scheduler and return a thread handle.
-pub fn spawntask_thread(f: ~fn()) -> Thread {
+pub fn spawntask_thread(f: proc()) -> Thread {
 
     let f = Cell::new(f);
 
@@ -345,7 +345,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
 }
 
 /// Get a ~Task for testing purposes other than actually scheduling it.
-pub fn with_test_task(blk: ~fn(~Task) -> ~Task) {
+pub fn with_test_task(blk: proc(~Task) -> ~Task) {
     do run_in_bare_thread {
         let mut sched = ~new_test_sched();
         let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{}));
diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs
index 5e535d994f9..e364e5a6603 100644
--- a/src/libstd/rt/thread.rs
+++ b/src/libstd/rt/thread.rs
@@ -35,7 +35,7 @@ static DEFAULT_STACK_SIZE: libc::size_t = 1024*1024;
 
 impl Thread {
 
-    pub fn start(main: ~fn()) -> Thread {
+    pub fn start(main: proc()) -> Thread {
         // This is the starting point of rust os threads. The first thing we do
         // is make sure that we don't trigger __morestack (also why this has a
         // no_split_stack annotation), and then we extract the main function
@@ -45,7 +45,7 @@ impl Thread {
             use rt::context;
             unsafe {
                 context::record_stack_bounds(0, uint::max_value);
-                let f: ~~fn() = cast::transmute(trampoline);
+                let f: ~proc() = cast::transmute(trampoline);
                 (*f)();
             }
             unsafe { cast::transmute(0) }
@@ -67,7 +67,7 @@ impl Thread {
 
 #[cfg(windows)]
 fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return,
-                        tramp: ~~fn()) -> rust_thread {
+                        tramp: ~proc()) -> rust_thread {
     unsafe {
         let ptr: *mut libc::c_void = cast::transmute(tramp);
         CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, thread_start, ptr, 0, ptr::mut_null())
@@ -82,7 +82,7 @@ fn native_thread_join(native: rust_thread) {
 
 #[cfg(unix)]
 fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return,
-                        tramp: ~~fn()) -> rust_thread {
+                        tramp: ~proc()) -> rust_thread {
     use unstable::intrinsics;
     let mut native: libc::pthread_t = unsafe { intrinsics::uninit() };