about summary refs log tree commit diff
path: root/src/libnative/task.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-14 23:05:01 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-19 12:59:40 -0700
commit9d5d97b55d6487ee23b805bc1acbaa0669b82116 (patch)
treeb72dcf7045e331e94ea0f8658d088ab42d917935 /src/libnative/task.rs
parentfb169d5543c84e11038ba2d07b538ec88fb49ca6 (diff)
downloadrust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.tar.gz
rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.zip
Remove a large amount of deprecated functionality
Spring cleaning is here! In the Fall! This commit removes quite a large amount
of deprecated functionality from the standard libraries. I tried to ensure that
only old deprecated functionality was removed.

This is removing lots and lots of deprecated features, so this is a breaking
change. Please consult the deprecation messages of the deleted code to see how
to migrate code forward if it still needs migration.

[breaking-change]
Diffstat (limited to 'src/libnative/task.rs')
-rw-r--r--src/libnative/task.rs100
1 files changed, 44 insertions, 56 deletions
diff --git a/src/libnative/task.rs b/src/libnative/task.rs
index ba3f101720f..48e2c440dfc 100644
--- a/src/libnative/task.rs
+++ b/src/libnative/task.rs
@@ -26,7 +26,6 @@ use std::rt::thread::Thread;
 use std::rt;
 
 use io;
-use task;
 use std::task::{TaskBuilder, Spawner};
 
 /// Creates a new Task which is ready to execute as a 1:1 task.
@@ -48,61 +47,49 @@ fn ops() -> Box<Ops> {
     }
 }
 
-/// Spawns a function with the default configuration
-#[deprecated = "use the native method of NativeTaskBuilder instead"]
-pub fn spawn(f: proc():Send) {
-    spawn_opts(TaskOpts { name: None, stack_size: None, on_exit: None }, f)
-}
-
-/// Spawns a new task given the configuration options and a procedure to run
-/// inside the task.
-#[deprecated = "use the native method of NativeTaskBuilder instead"]
-pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
-    let TaskOpts { name, stack_size, on_exit } = opts;
-
-    let mut task = box Task::new();
-    task.name = name;
-    task.death.on_exit = on_exit;
-
-    let stack = stack_size.unwrap_or(rt::min_stack());
-    let task = task;
-    let ops = ops();
-
-    // Note that this increment must happen *before* the spawn in order to
-    // guarantee that if this task exits it will always end up waiting for the
-    // spawned task to exit.
-    let token = bookkeeping::increment();
-
-    // Spawning a new OS thread guarantees that __morestack will never get
-    // triggered, but we must manually set up the actual stack bounds once this
-    // function starts executing. This raises the lower limit by a bit because
-    // by the time that this function is executing we've already consumed at
-    // least a little bit of stack (we don't know the exact byte address at
-    // which our stack started).
-    Thread::spawn_stack(stack, proc() {
-        let something_around_the_top_of_the_stack = 1;
-        let addr = &something_around_the_top_of_the_stack as *const int;
-        let my_stack = addr as uint;
-        unsafe {
-            stack::record_os_managed_stack_bounds(my_stack - stack + 1024, my_stack);
-        }
-        let mut ops = ops;
-        ops.stack_bounds = (my_stack - stack + 1024, my_stack);
-
-        let mut f = Some(f);
-        let mut task = task;
-        task.put_runtime(ops);
-        drop(task.run(|| { f.take().unwrap()() }).destroy());
-        drop(token);
-    })
-}
-
 /// A spawner for native tasks
 pub struct NativeSpawner;
 
 impl Spawner for NativeSpawner {
     fn spawn(self, opts: TaskOpts, f: proc():Send) {
-        spawn_opts(opts, f)
+        let TaskOpts { name, stack_size, on_exit } = opts;
+
+        let mut task = box Task::new();
+        task.name = name;
+        task.death.on_exit = on_exit;
+
+        let stack = stack_size.unwrap_or(rt::min_stack());
+        let task = task;
+        let ops = ops();
+
+        // Note that this increment must happen *before* the spawn in order to
+        // guarantee that if this task exits it will always end up waiting for
+        // the spawned task to exit.
+        let token = bookkeeping::increment();
+
+        // Spawning a new OS thread guarantees that __morestack will never get
+        // triggered, but we must manually set up the actual stack bounds once
+        // this function starts executing. This raises the lower limit by a bit
+        // because by the time that this function is executing we've already
+        // consumed at least a little bit of stack (we don't know the exact byte
+        // address at which our stack started).
+        Thread::spawn_stack(stack, proc() {
+            let something_around_the_top_of_the_stack = 1;
+            let addr = &something_around_the_top_of_the_stack as *const int;
+            let my_stack = addr as uint;
+            unsafe {
+                stack::record_os_managed_stack_bounds(my_stack - stack + 1024,
+                                                      my_stack);
+            }
+            let mut ops = ops;
+            ops.stack_bounds = (my_stack - stack + 1024, my_stack);
+
+            let mut f = Some(f);
+            let mut task = task;
+            task.put_runtime(ops);
+            drop(task.run(|| { f.take().unwrap()() }).destroy());
+            drop(token);
+        })
     }
 }
 
@@ -270,7 +257,7 @@ impl rt::Runtime for Ops {
         cur_task.put_runtime(self);
         Local::put(cur_task);
 
-        task::spawn_opts(opts, f);
+        NativeSpawner.spawn(opts, f);
     }
 
     fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
@@ -283,8 +270,9 @@ mod tests {
     use std::rt::local::Local;
     use std::rt::task::{Task, TaskOpts};
     use std::task;
-    use std::task::TaskBuilder;
-    use super::{spawn, spawn_opts, Ops, NativeTaskBuilder};
+    use std::task::{TaskBuilder, Spawner};
+
+    use super::{Ops, NativeTaskBuilder, NativeSpawner};
 
     #[test]
     fn smoke() {
@@ -312,7 +300,7 @@ mod tests {
         opts.stack_size = Some(20 * 4096);
         let (tx, rx) = channel();
         opts.on_exit = Some(proc(r) tx.send(r));
-        spawn_opts(opts, proc() {});
+        NativeSpawner.spawn(opts, proc() {});
         assert!(rx.recv().is_ok());
     }
 
@@ -321,7 +309,7 @@ mod tests {
         let mut opts = TaskOpts::new();
         let (tx, rx) = channel();
         opts.on_exit = Some(proc(r) tx.send(r));
-        spawn_opts(opts, proc() { fail!() });
+        NativeSpawner.spawn(opts, proc() { fail!() });
         assert!(rx.recv().is_err());
     }