about summary refs log tree commit diff
path: root/src/libstd/sync/task_pool.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-11-26 10:10:52 -0500
committerNiko Matsakis <niko@alum.mit.edu>2014-12-14 04:21:56 -0500
commitd61338172fa110fcf9e5f2df0e1e83635d0fde3f (patch)
tree5a022b681067ce30acf73e06aef9896f3cfd4be2 /src/libstd/sync/task_pool.rs
parent10ac5b72f1974775bed499105c2a3cf18da98f32 (diff)
downloadrust-d61338172fa110fcf9e5f2df0e1e83635d0fde3f.tar.gz
rust-d61338172fa110fcf9e5f2df0e1e83635d0fde3f.zip
Rewrite threading infrastructure, introducing `Thunk` to represent
boxed `FnOnce` closures.
Diffstat (limited to 'src/libstd/sync/task_pool.rs')
-rw-r--r--src/libstd/sync/task_pool.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs
index 4ae5cd054f6..a684c6502ae 100644
--- a/src/libstd/sync/task_pool.rs
+++ b/src/libstd/sync/task_pool.rs
@@ -72,7 +72,7 @@ pub struct TaskPool {
     //
     // This is the only such Sender, so when it is dropped all subtasks will
     // quit.
-    jobs: Sender<proc(): Send>
+    jobs: Sender<Thunk>
 }
 
 impl TaskPool {
@@ -84,7 +84,7 @@ impl TaskPool {
     pub fn new(tasks: uint) -> TaskPool {
         assert!(tasks >= 1);
 
-        let (tx, rx) = channel::<proc(): Send>();
+        let (tx, rx) = channel::<Thunk>();
         let rx = Arc::new(Mutex::new(rx));
 
         // Taskpool tasks.
@@ -96,13 +96,15 @@ impl TaskPool {
     }
 
     /// Executes the function `job` on a task in the pool.
-    pub fn execute(&self, job: proc():Send) {
-        self.jobs.send(job);
+    pub fn execute<F>(&self, job: F)
+        where F : FnOnce(), F : Send
+    {
+        self.jobs.send(Thunk::new(job));
     }
 }
 
-fn spawn_in_pool(jobs: Arc<Mutex<Receiver<proc(): Send>>>) {
-    spawn(proc() {
+fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) {
+    spawn(move |:| {
         // Will spawn a new task on panic unless it is cancelled.
         let sentinel = Sentinel::new(&jobs);
 
@@ -115,7 +117,7 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<proc(): Send>>>) {
             };
 
             match message {
-                Ok(job) => job(),
+                Ok(job) => job.invoke(()),
 
                 // The Taskpool was dropped.
                 Err(..) => break