diff --git a/src/libcore/os.rs b/src/libcore/os.rs index a1d562926e2..bb22c2137dc 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -24,6 +24,7 @@ import option::{some, none}; import getcwd = rustrt::rust_getcwd; import consts::*; +import task::task_builder; export close, fclose, fsync_fd, waitpid; export env, getenv, setenv, fdopen, pipe; @@ -160,19 +161,14 @@ mod global_env { fn get_global_env_chan() -> comm::chan { let global_ptr = rustrt::rust_global_env_chan_ptr(); - let builder_fn = || { - let builder = task::builder(); - task::unsupervise(builder); - + let task_build_fn = || { // FIXME (#2621): This would be a good place to use a very small // foreign stack - task::set_sched_mode(builder, task::single_threaded); - - builder + task::task().sched_mode(task::single_threaded).unlinked() }; unsafe { priv::chan_from_global_ptr( - global_ptr, builder_fn, global_env_task) + global_ptr, task_build_fn, global_env_task) } } diff --git a/src/libcore/priv.rs b/src/libcore/priv.rs index 010717c3445..b126ac64bdd 100644 --- a/src/libcore/priv.rs +++ b/src/libcore/priv.rs @@ -3,6 +3,7 @@ export chan_from_global_ptr, weaken_task; import compare_and_swap = rustrt::rust_compare_and_swap_ptr; +import task::task_builder; type rust_port_id = uint; @@ -23,7 +24,7 @@ type global_ptr = *libc::uintptr_t; */ unsafe fn chan_from_global_ptr( global: global_ptr, - builder: fn() -> task::builder, + task_fn: fn() -> task::task_builder, +f: fn~(comm::port) ) -> comm::chan { @@ -41,7 +42,7 @@ unsafe fn chan_from_global_ptr( let setup_po = comm::port(); let setup_ch = comm::chan(setup_po); - let setup_ch = do task::run_listener(builder()) |setup_po| { + let setup_ch = do task_fn().spawn_listener |setup_po| { let po = comm::port::(); let ch = comm::chan(po); comm::send(setup_ch, ch); @@ -92,7 +93,7 @@ fn test_from_global_chan1() { // Create the global channel, attached to a new task let ch = unsafe { - do chan_from_global_ptr(globchanp, task::builder) |po| { + do chan_from_global_ptr(globchanp, task::task) |po| { let ch = comm::recv(po); comm::send(ch, true); let ch = comm::recv(po); @@ -106,7 +107,7 @@ fn test_from_global_chan1() { // This one just reuses the previous channel let ch = unsafe { - do chan_from_global_ptr(globchanp, task::builder) |po| { + do chan_from_global_ptr(globchanp, task::task) |po| { let ch = comm::recv(po); comm::send(ch, false); } @@ -135,7 +136,7 @@ fn test_from_global_chan2() { do task::spawn { let ch = unsafe { do chan_from_global_ptr( - globchanp, task::builder) |po| { + globchanp, task::task) |po| { for uint::range(0u, 10u) |_j| { let ch = comm::recv(po); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 4a7962a977f..08096135952 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -8,6 +8,7 @@ import get_gl = get; import iotask::{iotask, spawn_iotask}; import priv::{chan_from_global_ptr, weaken_task}; import comm::{port, chan, methods, select2, listen}; +import task::task_builder; import either::{left, right}; extern mod rustrt { @@ -39,10 +40,7 @@ fn get_monitor_task_gl() -> iotask unsafe { monitor_loop_chan_ptr); let builder_fn = || { - let builder = task::builder(); - task::unsupervise(builder); - task::set_sched_mode(builder, task::single_threaded); - builder + task::task().sched_mode(task::single_threaded).unlinked() }; #debug("before priv::chan_from_global_ptr"); @@ -86,8 +84,7 @@ fn get_monitor_task_gl() -> iotask unsafe { } fn spawn_loop() -> iotask unsafe { - let builder = task::builder(); - do task::add_wrapper(builder) |task_body| { + let builder = do task::task().add_wrapper |task_body| { fn~(move task_body) { // The I/O loop task also needs to be weak so it doesn't keep // the runtime alive @@ -102,7 +99,7 @@ fn spawn_loop() -> iotask unsafe { #debug("global libuv task is leaving weakened state"); } } - } + }; spawn_iotask(builder) } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index d049c6f7c7b..5566c0c8f0f 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -13,6 +13,7 @@ export exit; import libc::c_void; import ptr::addr_of; import comm::{port, chan, methods, listen}; +import task::task_builder; import ll = uv_ll; /// Used to abstract-away direct interaction with a libuv loop. @@ -23,13 +24,11 @@ enum iotask { }) } -fn spawn_iotask(-builder: task::builder) -> iotask { - - task::set_sched_mode(builder, task::single_threaded); +fn spawn_iotask(-task: task::task_builder) -> iotask { do listen |iotask_ch| { - do task::run(copy(builder)) { + do task.sched_mode(task::single_threaded).spawn { #debug("entering libuv task"); run_loop(iotask_ch); #debug("libuv task exiting");