diff --git a/src/libcore/private.rs b/src/libcore/private.rs index c3068d6f61b0..03207330f31c 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -39,8 +39,6 @@ pub mod weak_task; extern mod rustrt { #[legacy_exports]; - unsafe fn rust_task_weaken(ch: rust_port_id); - unsafe fn rust_task_unweaken(ch: rust_port_id); unsafe fn rust_create_little_lock() -> rust_little_lock; unsafe fn rust_destroy_little_lock(lock: rust_little_lock); @@ -92,111 +90,11 @@ fn test_run_in_bare_thread() unsafe { } } -#[allow(non_camel_case_types)] // runtime type -type rust_port_id = uint; - fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool { let old = rusti::atomic_cxchg(address, oldval, newval); old == oldval } -/** - * Convert the current task to a 'weak' task temporarily - * - * As a weak task it will not be counted towards the runtime's set - * of live tasks. When there are no more outstanding live (non-weak) tasks - * the runtime will send an exit message on the provided channel. - * - * This function is super-unsafe. Do not use. - * - * # Safety notes - * - * * Weak tasks must either die on their own or exit upon receipt of - * the exit message. Failure to do so will cause the runtime to never - * exit - * * Tasks must not call `weaken_task` multiple times. This will - * break the kernel's accounting of live tasks. - * * Weak tasks must not be supervised. A supervised task keeps - * a reference to its parent, so the parent will not die. - */ -pub unsafe fn weaken_task(f: fn(oldcomm::Port<()>)) { - let po = oldcomm::Port(); - let ch = oldcomm::Chan(&po); - unsafe { - rustrt::rust_task_weaken(cast::reinterpret_cast(&ch)); - } - let _unweaken = Unweaken(ch); - f(po); - - struct Unweaken { - ch: oldcomm::Chan<()>, - drop unsafe { - rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch)); - } - } - - fn Unweaken(ch: oldcomm::Chan<()>) -> Unweaken { - Unweaken { - ch: ch - } - } -} - -#[test] -pub fn test_weaken_task_then_unweaken() { - do task::try { - unsafe { - do weaken_task |_po| { - } - } - }; -} - -#[test] -pub fn test_weaken_task_wait() { - do task::spawn_unlinked { - unsafe { - do weaken_task |po| { - oldcomm::recv(po); - } - } - } -} - -#[test] -pub fn test_weaken_task_stress() { - // Create a bunch of weak tasks - for iter::repeat(100u) { - do task::spawn { - unsafe { - do weaken_task |_po| { - } - } - } - do task::spawn_unlinked { - unsafe { - do weaken_task |po| { - // Wait for it to tell us to die - oldcomm::recv(po); - } - } - } - } -} - -#[test] -#[ignore(cfg(windows))] -pub fn test_weaken_task_fail() { - let res = do task::try { - unsafe { - do weaken_task |_po| { - fail; - } - } - }; - assert result::is_err(&res); -} - /**************************************************************************** * Shared state & exclusive ARC ****************************************************************************/ diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 327337f441d8..4fcfc11b3256 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -858,18 +858,6 @@ rust_compare_and_swap_ptr(intptr_t *address, return sync::compare_and_swap(address, oldval, newval); } -extern "C" CDECL void -rust_task_weaken(rust_port_id chan) { - rust_task *task = rust_get_current_task(); - task->kernel->weaken_task(chan); -} - -extern "C" CDECL void -rust_task_unweaken(rust_port_id chan) { - rust_task *task = rust_get_current_task(); - task->kernel->unweaken_task(chan); -} - extern "C" void rust_task_inhibit_kill(rust_task *task) { task->inhibit_kill(); diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 8ca49ea6a57c..c365f3cca1ef 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -368,30 +368,6 @@ rust_kernel::unregister_task() { } } -void -rust_kernel::weaken_task(rust_port_id chan) { - { - scoped_lock with(weak_task_lock); - KLOG_("Weakening task with channel %" PRIdPTR, chan); - weak_task_chans.push_back(chan); - } - inc_weak_task_count(); -} - -void -rust_kernel::unweaken_task(rust_port_id chan) { - dec_weak_task_count(); - { - scoped_lock with(weak_task_lock); - KLOG_("Unweakening task with channel %" PRIdPTR, chan); - std::vector::iterator iter = - std::find(weak_task_chans.begin(), weak_task_chans.end(), chan); - if (iter != weak_task_chans.end()) { - weak_task_chans.erase(iter); - } - } -} - void rust_kernel::inc_weak_task_count() { uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks); @@ -407,23 +383,6 @@ rust_kernel::dec_weak_task_count() { KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks); } -void -rust_kernel::end_weak_tasks() { - std::vector chancopies; - { - scoped_lock with(weak_task_lock); - chancopies = weak_task_chans; - weak_task_chans.clear(); - } - while (!chancopies.empty()) { - rust_port_id chan = chancopies.back(); - chancopies.pop_back(); - KLOG_("Notifying weak task " PRIdPTR, chan); - uintptr_t token = 0; - send_to_port(chan, &token); - } -} - void rust_kernel::begin_shutdown() { { @@ -439,7 +398,6 @@ rust_kernel::begin_shutdown() { run_exit_functions(); allow_scheduler_exit(); - end_weak_tasks(); } bool diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 8ba0405b86e0..c25cef9fef98 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -119,14 +119,9 @@ class rust_kernel { // An atomically updated count of the live, 'non-weak' tasks uintptr_t non_weak_tasks; - // Protects weak_task_chans - lock_and_signal weak_task_lock; - // A list of weak tasks that need to be told when to exit - std::vector weak_task_chans; rust_scheduler* get_scheduler_by_id_nolock(rust_sched_id id); void allow_scheduler_exit(); - void end_weak_tasks(); void begin_shutdown(); lock_and_signal at_exit_lock; @@ -180,8 +175,6 @@ public: void register_task(); void unregister_task(); - void weaken_task(rust_port_id chan); - void unweaken_task(rust_port_id chan); void inc_weak_task_count(); void dec_weak_task_count(); diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 8e8ce9ee509e..eb9db6c1d575 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -61,8 +61,6 @@ rust_task_yield rust_task_is_unwinding rust_get_task rust_get_stack_segment -rust_task_weaken -rust_task_unweaken rust_log_str start_task vec_reserve_shared_actual