about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-26 19:46:25 +0000
committerbors <bors@rust-lang.org>2014-06-26 19:46:25 +0000
commit4c33a14cc546ddacd5398cebf57aa5ac574cfea7 (patch)
tree21d47ac21cd9785976f1551a459df6e033f37712 /src/libnative
parentb20f968ed2a4808f98ffce52ce95398009565ece (diff)
parent7d756e44a96c1e28f63cab1ea328d01984ac07d2 (diff)
downloadrust-4c33a14cc546ddacd5398cebf57aa5ac574cfea7.tar.gz
rust-4c33a14cc546ddacd5398cebf57aa5ac574cfea7.zip
auto merge of #14886 : alexcrichton/rust/rt-improvements, r=brson
Most of the comments are available on the Task structure itself, but this commit
is aimed at making FFI-style usage of Rust tasks a little nicer.

Primarily, this commit enables re-use of tasks across multiple invocations. The
method `run` will no longer unconditionally destroy the task itself. Rather, the
task will be internally re-usable if the closure specified did not fail. Once a
task has failed once it is considered poisoned and it can never be used again.

Along the way I tried to document shortcomings of the current method of tearing
down a task, opening a few issues as well. For now none of the behavior is a
showstopper, but it's useful to acknowledge it. Also along the way I attempted
to remove as much `unsafe` code as possible, opting for safer abstractions.
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/lib.rs5
-rw-r--r--src/libnative/task.rs3
2 files changed, 3 insertions, 5 deletions
diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs
index 3438661ffb3..9b2bcbbdb0e 100644
--- a/src/libnative/lib.rs
+++ b/src/libnative/lib.rs
@@ -134,13 +134,12 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
     let mut main = Some(main);
     let mut task = task::new((my_stack_bottom, my_stack_top));
     task.name = Some(str::Slice("<main>"));
-    let t = task.run(|| {
+    drop(task.run(|| {
         unsafe {
             rt::stack::record_stack_bounds(my_stack_bottom, my_stack_top);
         }
         exit_code = Some(run(main.take_unwrap()));
-    });
-    drop(t);
+    }).destroy());
     unsafe { rt::cleanup(); }
     // If the exit code wasn't set, then the task block must have failed.
     return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
diff --git a/src/libnative/task.rs b/src/libnative/task.rs
index 8b7c8e61bc3..0b863d9f694 100644
--- a/src/libnative/task.rs
+++ b/src/libnative/task.rs
@@ -92,8 +92,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
         let mut f = Some(f);
         let mut task = task;
         task.put_runtime(ops);
-        let t = task.run(|| { f.take_unwrap()() });
-        drop(t);
+        drop(task.run(|| { f.take_unwrap()() }).destroy());
         bookkeeping::decrement();
     })
 }