]> git.lizzy.rs Git - rust.git/commitdiff
std: Remove weak_task API. Unused
authorBrian Anderson <banderson@mozilla.com>
Thu, 18 Jul 2013 01:04:10 +0000 (18:04 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 22 Jul 2013 21:16:52 +0000 (14:16 -0700)
src/libstd/unstable/mod.rs
src/libstd/unstable/weak_task.rs [deleted file]
src/rt/rust_builtin.cpp
src/rt/rustrt.def.in

index 0a46ef619afd9d9381a9d11d5b3fda994cfa0f95..c7e88b7e161225e68e970965e386630f723d36b2 100644 (file)
@@ -22,7 +22,6 @@
 
 pub mod global;
 pub mod finally;
-pub mod weak_task;
 pub mod intrinsics;
 pub mod simd;
 pub mod extfmt;
diff --git a/src/libstd/unstable/weak_task.rs b/src/libstd/unstable/weak_task.rs
deleted file mode 100644 (file)
index f5dfa1f..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-/*!
-Weak tasks
-
-Weak tasks are a runtime feature for building global services that
-do not keep the runtime alive. Normally the runtime exits when all
-tasks exits, but if a task is weak then the runtime may exit while
-it is running, sending a notification to the task that the runtime
-is trying to shut down.
-*/
-
-use cell::Cell;
-use comm::{GenericSmartChan, stream};
-use comm::{Port, Chan, SharedChan, GenericChan, GenericPort};
-use hashmap::HashMap;
-use option::{Some, None};
-use unstable::at_exit::at_exit;
-use unstable::finally::Finally;
-use unstable::global::global_data_clone_create;
-use task::rt::{task_id, get_task_id};
-use task::task;
-
-#[cfg(test)] use task::spawn;
-
-type ShutdownMsg = ();
-
-// FIXME #4729: This could be a PortOne but I've experienced bugginess
-// with oneshot pipes and try_send
-pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
-    let service = global_data_clone_create(global_data_key,
-                                           create_global_service);
-    let (shutdown_port, shutdown_chan) = stream::<ShutdownMsg>();
-    let shutdown_port = Cell::new(shutdown_port);
-    let task = get_task_id();
-    // Expect the weak task service to be alive
-    assert!(service.try_send(RegisterWeakTask(task, shutdown_chan)));
-    rust_dec_kernel_live_count();
-    do (|| {
-        f(shutdown_port.take())
-    }).finally || {
-        rust_inc_kernel_live_count();
-        // Service my have already exited
-        service.send(UnregisterWeakTask(task));
-    }
-}
-
-type WeakTaskService = SharedChan<ServiceMsg>;
-type TaskHandle = task_id;
-
-fn global_data_key(_v: WeakTaskService) { }
-
-enum ServiceMsg {
-    RegisterWeakTask(TaskHandle, Chan<ShutdownMsg>),
-    UnregisterWeakTask(TaskHandle),
-    Shutdown
-}
-
-fn create_global_service() -> ~WeakTaskService {
-
-    debug!("creating global weak task service");
-    let (port, chan) = stream::<ServiceMsg>();
-    let port = Cell::new(port);
-    let chan = SharedChan::new(chan);
-    let chan_clone = chan.clone();
-
-    let mut task = task();
-    task.unlinked();
-    do task.spawn {
-        debug!("running global weak task service");
-        let port = Cell::new(port.take());
-        do (|| {
-            let port = port.take();
-            // The weak task service is itself a weak task
-            debug!("weakening the weak service task");
-            unsafe { rust_dec_kernel_live_count(); }
-            run_weak_task_service(port);
-        }).finally {
-            debug!("unweakening the weak service task");
-            unsafe { rust_inc_kernel_live_count(); }
-        }
-    }
-
-    do at_exit {
-        debug!("shutting down weak task service");
-        chan.send(Shutdown);
-    }
-
-    return ~chan_clone;
-}
-
-fn run_weak_task_service(port: Port<ServiceMsg>) {
-
-    let mut shutdown_map = HashMap::new();
-
-    loop {
-        match port.recv() {
-            RegisterWeakTask(task, shutdown_chan) => {
-                let previously_unregistered =
-                    shutdown_map.insert(task, shutdown_chan);
-                assert!(previously_unregistered);
-            }
-            UnregisterWeakTask(task) => {
-                match shutdown_map.pop(&task) {
-                    Some(shutdown_chan) => {
-                        // Oneshot pipes must send, even though
-                        // nobody will receive this
-                        shutdown_chan.send(());
-                    }
-                    None => fail!()
-                }
-            }
-            Shutdown => break
-        }
-    }
-
-    for shutdown_map.consume().advance |(_, shutdown_chan)| {
-        // Weak task may have already exited
-        shutdown_chan.send(());
-    }
-}
-
-extern {
-    unsafe fn rust_inc_kernel_live_count();
-    unsafe fn rust_dec_kernel_live_count();
-}
-
-#[test]
-fn test_simple() {
-    let (port, chan) = stream();
-    do spawn {
-        unsafe {
-            do weaken_task |_signal| {
-            }
-        }
-        chan.send(());
-    }
-    port.recv();
-}
-
-#[test]
-fn test_weak_weak() {
-    let (port, chan) = stream();
-    do spawn {
-        unsafe {
-            do weaken_task |_signal| {
-            }
-            do weaken_task |_signal| {
-            }
-        }
-        chan.send(());
-    }
-    port.recv();
-}
-
-#[test]
-fn test_wait_for_signal() {
-    do spawn {
-        unsafe {
-            do weaken_task |signal| {
-                signal.recv();
-            }
-        }
-    }
-}
-
-#[test]
-fn test_wait_for_signal_many() {
-    use uint;
-    for uint::range(0, 100) |_| {
-        do spawn {
-            unsafe {
-                do weaken_task |signal| {
-                    signal.recv();
-                }
-            }
-        }
-    }
-}
-
-#[test]
-fn test_select_stream_and_oneshot() {
-    use comm::select2i;
-    use either::{Left, Right};
-
-    let (port, chan) = stream();
-    let port = Cell::new(port);
-    let (waitport, waitchan) = stream();
-    do spawn {
-        unsafe {
-            do weaken_task |mut signal| {
-                let mut port = port.take();
-                match select2i(&mut port, &mut signal) {
-                    Left(*) => (),
-                    Right(*) => fail!()
-                }
-            }
-        }
-        waitchan.send(());
-    }
-    chan.send(());
-    waitport.recv();
-}
index 7e69e2e4ccb9958fcb1c9d65905e2c971377c63c..863e0a3a99e17d9049db0f4affdeb004a6cdd781 100644 (file)
@@ -769,18 +769,6 @@ rust_get_global_data_ptr() {
     return &task->kernel->global_data;
 }
 
-extern "C" void
-rust_inc_kernel_live_count() {
-    rust_task *task = rust_get_current_task();
-    task->kernel->inc_live_count();
-}
-
-extern "C" void
-rust_dec_kernel_live_count() {
-    rust_task *task = rust_get_current_task();
-    task->kernel->dec_live_count();
-}
-
 #ifndef _WIN32
 #include <sys/types.h>
 #include <dirent.h>
index 3c3e9a56827b33c996217279e9d84f5e47d8ee94..215673be1203ed27116bd2784f4a20d71bf6ffa3 100644 (file)
@@ -216,8 +216,6 @@ rust_raw_thread_start
 rust_raw_thread_join_delete
 rust_register_exit_function
 rust_get_global_data_ptr
-rust_inc_kernel_live_count
-rust_dec_kernel_live_count
 rust_get_rt_tls_key
 swap_registers
 rust_readdir