]> git.lizzy.rs Git - rust.git/commitdiff
std: Remove at_exit API. Unused
authorBrian Anderson <banderson@mozilla.com>
Thu, 18 Jul 2013 02:51:40 +0000 (19:51 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 22 Jul 2013 21:17:09 +0000 (14:17 -0700)
src/libstd/unstable/at_exit.rs [deleted file]
src/libstd/unstable/mod.rs
src/rt/rust_builtin.cpp
src/rt/rust_kernel.cpp
src/rt/rust_kernel.h
src/rt/rustrt.def.in

diff --git a/src/libstd/unstable/at_exit.rs b/src/libstd/unstable/at_exit.rs
deleted file mode 100644 (file)
index 20ddf94..0000000
+++ /dev/null
@@ -1,100 +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.
-
-use cast;
-use libc::size_t;
-use rand::RngUtil;
-use rand;
-use sys;
-use task;
-use vec;
-
-#[cfg(test)] use uint;
-
-/**
-Register a function to be run during runtime shutdown.
-
-After all non-weak tasks have exited, registered exit functions will
-execute, in random order, on the primary scheduler. Each function runs
-in its own unsupervised task.
-*/
-pub fn at_exit(f: ~fn()) {
-    unsafe {
-        let runner: &fn(*ExitFunctions) = exit_runner;
-        let runner_pair: sys::Closure = cast::transmute(runner);
-        let runner_ptr = runner_pair.code;
-        let runner_ptr = cast::transmute(runner_ptr);
-        rustrt::rust_register_exit_function(runner_ptr, ~f);
-    }
-}
-
-// NB: The double pointer indirection here is because ~fn() is a fat
-// pointer and due to FFI problems I am more comfortable making the
-// interface use a normal pointer
-mod rustrt {
-    use libc::c_void;
-
-    extern {
-        pub fn rust_register_exit_function(runner: *c_void, f: ~~fn());
-    }
-}
-
-struct ExitFunctions {
-    // The number of exit functions
-    count: size_t,
-    // The buffer of exit functions
-    start: *~~fn()
-}
-
-fn exit_runner(exit_fns: *ExitFunctions) {
-    let exit_fns = unsafe { &*exit_fns };
-    let count = (*exit_fns).count;
-    let start = (*exit_fns).start;
-
-    // NB: from_buf memcpys from the source, which will
-    // give us ownership of the array of functions
-    let mut exit_fns_vec = unsafe { vec::from_buf(start, count as uint) };
-    // Let's not make any promises about execution order
-    let mut rng = rand::rng();
-    rng.shuffle_mut(exit_fns_vec);
-
-    debug!("running %u exit functions", exit_fns_vec.len());
-
-    while !exit_fns_vec.is_empty() {
-        match exit_fns_vec.pop() {
-            ~f => {
-                let mut task = task::task();
-                task.supervised();
-                task.spawn(f);
-            }
-        }
-    }
-}
-
-#[test]
-fn test_at_exit() {
-    let i = 10;
-    do at_exit {
-        debug!("at_exit1");
-        assert_eq!(i, 10);
-    }
-}
-
-#[test]
-fn test_at_exit_many() {
-    let i = 10;
-    for uint::range(20, 100) |j| {
-        do at_exit {
-            debug!("at_exit2");
-            assert_eq!(i, 10);
-            assert!(j > i);
-        }
-    }
-}
index 3c1da46cf020d241cee9ba744a841c7bd1bbe6eb..d6fd2cbcd1e4d7ec175e086c59ee8bf0679bd0f6 100644 (file)
@@ -16,8 +16,6 @@
 use prelude::*;
 use task;
 
-pub mod at_exit;
-
 pub mod dynamic_lib;
 
 pub mod finally;
index 860f20e73084d2caef3170337adb312aa8639fce..06b09bcedd2d06ff4ead09ef9a08b73c74f8db0a 100644 (file)
@@ -757,12 +757,6 @@ rust_raw_thread_join_delete(raw_thread *thread) {
     delete thread;
 }
 
-extern "C" void
-rust_register_exit_function(spawn_fn runner, fn_env_pair *f) {
-    rust_task *task = rust_get_current_task();
-    task->kernel->register_exit_function(runner, f);
-}
-
 #ifndef _WIN32
 #include <sys/types.h>
 #include <dirent.h>
index 20ac5384a3c7e17639a03b1a6e03fc56306e6f56..814cfbb310a79aa3d2c608411d436fab953d3814 100644 (file)
@@ -31,8 +31,6 @@ rust_kernel::rust_kernel(rust_env *env) :
     sched_reaper(this),
     osmain_driver(NULL),
     non_weak_tasks(0),
-    at_exit_runner(NULL),
-    at_exit_started(false),
     env(env)
 {
     // Create the single threaded scheduler that will run on the platform's
@@ -310,54 +308,9 @@ rust_kernel::begin_shutdown() {
         }
     }
 
-    run_exit_functions();
     allow_scheduler_exit();
 }
 
-void
-rust_kernel::register_exit_function(spawn_fn runner, fn_env_pair *f) {
-    scoped_lock with(at_exit_lock);
-
-    assert(!at_exit_started && "registering at_exit function after exit");
-
-    if (at_exit_runner) {
-        // FIXME #2912 Would be very nice to assert this but we can't because
-        // of the way coretest works (the test case ends up using its own
-        // function)
-        //assert(runner == at_exit_runner
-        //       && "there can be only one at_exit_runner");
-    }
-
-    at_exit_runner = runner;
-    at_exit_fns.push_back(f);
-}
-
-void
-rust_kernel::run_exit_functions() {
-    rust_task *task;
-
-    {
-        scoped_lock with(at_exit_lock);
-
-        assert(!at_exit_started && "running exit functions twice?");
-
-        at_exit_started = true;
-
-        if (at_exit_runner == NULL) {
-            return;
-        }
-
-        rust_scheduler *sched = get_scheduler_by_id(main_sched_id());
-        assert(sched);
-        task = sched->create_task(NULL, "at_exit");
-
-        final_exit_fns.count = at_exit_fns.size();
-        final_exit_fns.start = at_exit_fns.data();
-    }
-
-    task->start(at_exit_runner, NULL, &final_exit_fns);
-}
-
 //
 // Local Variables:
 // mode: C++
index 91f49662f46f07101e4fe6846d3b812aa179c33b..0fe3f7610403f776c7da2af200e8b5ffd82164c3 100644 (file)
@@ -63,13 +63,6 @@ typedef intptr_t rust_task_id;
 
 typedef std::map<rust_sched_id, rust_scheduler*> sched_map;
 
-// This is defined as a struct only because we need a single pointer to pass
-// to the Rust function that runs the at_exit functions
-struct exit_functions {
-    size_t count;
-    fn_env_pair **start;
-};
-
 class rust_kernel {
     rust_exchange_alloc exchange_alloc;
     rust_log _log;
@@ -114,14 +107,6 @@ class rust_kernel {
     void allow_scheduler_exit();
     void begin_shutdown();
 
-    lock_and_signal at_exit_lock;
-    spawn_fn at_exit_runner;
-    bool at_exit_started;
-    std::vector<fn_env_pair*> at_exit_fns;
-    exit_functions final_exit_fns;
-
-    void run_exit_functions();
-
 public:
     struct rust_env *env;
 
@@ -156,7 +141,6 @@ public:
     void inc_live_count();
     void dec_live_count();
 
-    void register_exit_function(spawn_fn runner, fn_env_pair *f);
 };
 
 template <typename T> struct kernel_owned {
index c07868aede1478fd02180b06212f9d05f009f818..db9fe2479526c88fe6181013b73e2fc70bb4ce08 100644 (file)
@@ -214,7 +214,6 @@ linenoiseHistorySave
 linenoiseHistoryLoad
 rust_raw_thread_start
 rust_raw_thread_join_delete
-rust_register_exit_function
 rust_get_rt_tls_key
 swap_registers
 rust_readdir