From f8c4d99df67d411d5f7b48823bc082d81cdfaa37 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Jul 2013 18:04:10 -0700 Subject: std: Remove weak_task API. Unused --- src/libstd/unstable/mod.rs | 1 - src/libstd/unstable/weak_task.rs | 211 --------------------------------------- 2 files changed, 212 deletions(-) delete mode 100644 src/libstd/unstable/weak_task.rs (limited to 'src/libstd') diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index 0a46ef619af..c7e88b7e161 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -22,7 +22,6 @@ pub mod dynamic_lib; 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 index f5dfa1feb9b..00000000000 --- a/src/libstd/unstable/weak_task.rs +++ /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 or the MIT license -// , 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)) { - let service = global_data_clone_create(global_data_key, - create_global_service); - let (shutdown_port, shutdown_chan) = stream::(); - 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; -type TaskHandle = task_id; - -fn global_data_key(_v: WeakTaskService) { } - -enum ServiceMsg { - RegisterWeakTask(TaskHandle, Chan), - UnregisterWeakTask(TaskHandle), - Shutdown -} - -fn create_global_service() -> ~WeakTaskService { - - debug!("creating global weak task service"); - let (port, chan) = stream::(); - 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) { - - 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(); -} -- cgit 1.4.1-3-g733a5 From 4beda4e582e4fe008aaf866a5f3ad6a20dec9876 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Jul 2013 18:38:12 -0700 Subject: std::rt: Stop using unstable::global in change_dir_locked --- src/libstd/os.rs | 40 ++++++++++++++++++++++++++-------------- src/rt/rust_builtin.cpp | 12 ++++++++++++ src/rt/rustrt.def.in | 2 ++ 3 files changed, 40 insertions(+), 14 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 4bfd3bbcd3f..fb5be0494ef 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -869,26 +869,38 @@ pub fn change_dir(p: &Path) -> bool { /// CWD to what it was before, returning true. /// Returns false if the directory doesn't exist or if the directory change /// is otherwise unsuccessful. +/// FIXME #7870 This probably shouldn't be part of the public API pub fn change_dir_locked(p: &Path, action: &fn()) -> bool { - use unstable::global::global_data_clone_create; - use unstable::sync::{Exclusive, exclusive}; - - fn key(_: Exclusive<()>) { } + use task; + use unstable::finally::Finally; unsafe { - let result = global_data_clone_create(key, || { ~exclusive(()) }); - - do result.with_imm() |_| { - let old_dir = os::getcwd(); - if change_dir(p) { - action(); - change_dir(&old_dir) - } - else { - false + // This is really sketchy. Using a pthread mutex so descheduling + // in the `action` callback can cause deadlock. Doing it in + // `task::atomically` to try to avoid that, but ... I don't know + // this is all bogus. + return do task::atomically { + rust_take_change_dir_lock(); + + do (||{ + let old_dir = os::getcwd(); + if change_dir(p) { + action(); + change_dir(&old_dir) + } + else { + false + } + }).finally { + rust_drop_change_dir_lock(); } } } + + extern { + fn rust_take_change_dir_lock(); + fn rust_drop_change_dir_lock(); + } } /// Copies a file from one location to another diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 863e0a3a99e..4dde01d5f00 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -947,6 +947,18 @@ rust_get_exit_status_newrt() { return exit_status; } +static lock_and_signal change_dir_lock; + +extern "C" CDECL void +rust_take_change_dir_lock() { + global_args_lock.lock(); +} + +extern "C" CDECL void +rust_drop_change_dir_lock() { + global_args_lock.unlock(); +} + // // Local Variables: // mode: C++ diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 215673be120..e9e0f3b6949 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -268,3 +268,5 @@ rust_take_global_args_lock rust_drop_global_args_lock rust_set_exit_status_newrt rust_get_exit_status_newrt +rust_take_change_dir_lock +rust_drop_change_dir_lock \ No newline at end of file -- cgit 1.4.1-3-g733a5 From 6174f9a4d9dc48f9988cd252f4fea8b319020298 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Jul 2013 18:59:29 -0700 Subject: std: Move change_dir_locked to unstable. #7870 --- src/libextra/tempfile.rs | 6 ++++-- src/librustpkg/tests.rs | 4 +++- src/libstd/os.rs | 40 ------------------------------------- src/libstd/unstable/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 43 deletions(-) (limited to 'src/libstd') diff --git a/src/libextra/tempfile.rs b/src/libextra/tempfile.rs index f8948f41101..c5fb4b9292e 100644 --- a/src/libextra/tempfile.rs +++ b/src/libextra/tempfile.rs @@ -48,10 +48,11 @@ mod tests { fn recursive_mkdir_rel() { use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::os; + use std::unstable::change_dir_locked; let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel"). expect("recursive_mkdir_rel"); - assert!(do os::change_dir_locked(&root) { + assert!(do change_dir_locked(&root) { let path = Path("frob"); debug!("recursive_mkdir_rel: Making: %s in cwd %s [%?]", path.to_str(), os::getcwd().to_str(), @@ -78,10 +79,11 @@ mod tests { fn recursive_mkdir_rel_2() { use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::os; + use std::unstable::change_dir_locked; let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel_2"). expect("recursive_mkdir_rel_2"); - assert!(do os::change_dir_locked(&root) { + assert!(do change_dir_locked(&root) { let path = Path("./frob/baz"); debug!("recursive_mkdir_rel_2: Making: %s in cwd %s [%?]", path.to_str(), os::getcwd().to_str(), os::path_exists(&path)); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index e6cda8286aa..286b1f84802 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -791,12 +791,14 @@ fn rust_path_test() { #[test] fn rust_path_contents() { + use std::unstable::change_dir_locked; + let dir = mkdtemp(&os::tmpdir(), "rust_path").expect("rust_path_contents failed"); let abc = &dir.push("A").push("B").push("C"); assert!(os::mkdir_recursive(&abc.push(".rust"), U_RWX)); assert!(os::mkdir_recursive(&abc.pop().push(".rust"), U_RWX)); assert!(os::mkdir_recursive(&abc.pop().pop().push(".rust"), U_RWX)); - assert!(do os::change_dir_locked(&dir.push("A").push("B").push("C")) { + assert!(do change_dir_locked(&dir.push("A").push("B").push("C")) { let p = rust_path(); let cwd = os::getcwd().push(".rust"); let parent = cwd.pop().pop().push(".rust"); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index fb5be0494ef..5981926fce3 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -863,46 +863,6 @@ pub fn change_dir(p: &Path) -> bool { } } -/// Changes the current working directory to the specified -/// path while acquiring a global lock, then calls `action`. -/// If the change is successful, releases the lock and restores the -/// CWD to what it was before, returning true. -/// Returns false if the directory doesn't exist or if the directory change -/// is otherwise unsuccessful. -/// FIXME #7870 This probably shouldn't be part of the public API -pub fn change_dir_locked(p: &Path, action: &fn()) -> bool { - use task; - use unstable::finally::Finally; - - unsafe { - // This is really sketchy. Using a pthread mutex so descheduling - // in the `action` callback can cause deadlock. Doing it in - // `task::atomically` to try to avoid that, but ... I don't know - // this is all bogus. - return do task::atomically { - rust_take_change_dir_lock(); - - do (||{ - let old_dir = os::getcwd(); - if change_dir(p) { - action(); - change_dir(&old_dir) - } - else { - false - } - }).finally { - rust_drop_change_dir_lock(); - } - } - } - - extern { - fn rust_take_change_dir_lock(); - fn rust_drop_change_dir_lock(); - } -} - /// Copies a file from one location to another pub fn copy_file(from: &Path, to: &Path) -> bool { return do_copy_file(from, to); diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index c7e88b7e161..e6313a10db1 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -79,3 +79,53 @@ extern { fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; fn rust_raw_thread_join_delete(thread: *raw_thread); } + + +/// Changes the current working directory to the specified +/// path while acquiring a global lock, then calls `action`. +/// If the change is successful, releases the lock and restores the +/// CWD to what it was before, returning true. +/// Returns false if the directory doesn't exist or if the directory change +/// is otherwise unsuccessful. +/// +/// This is used by test cases to avoid cwd races. +/// +/// # Safety Note +/// +/// This uses a pthread mutex so descheduling in the action callback +/// can lead to deadlock. Calling change_dir_locked recursively will +/// also deadlock. +pub fn change_dir_locked(p: &Path, action: &fn()) -> bool { + use os; + use os::change_dir; + use task; + use unstable::finally::Finally; + + unsafe { + // This is really sketchy. Using a pthread mutex so descheduling + // in the `action` callback can cause deadlock. Doing it in + // `task::atomically` to try to avoid that, but ... I don't know + // this is all bogus. + return do task::atomically { + rust_take_change_dir_lock(); + + do (||{ + let old_dir = os::getcwd(); + if change_dir(p) { + action(); + change_dir(&old_dir) + } + else { + false + } + }).finally { + rust_drop_change_dir_lock(); + } + } + } + + extern { + fn rust_take_change_dir_lock(); + fn rust_drop_change_dir_lock(); + } +} -- cgit 1.4.1-3-g733a5 From 23b7ee2bda12f6518d480c29e9673ed2c592c5f3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Jul 2013 19:14:58 -0700 Subject: std: Remove unstable::global. Unused --- src/libstd/unstable/global.rs | 281 ------------------------------------------ src/libstd/unstable/mod.rs | 1 - src/rt/rust_builtin.cpp | 6 - src/rt/rust_kernel.cpp | 3 +- src/rt/rust_kernel.h | 1 - src/rt/rustrt.def.in | 1 - 6 files changed, 1 insertion(+), 292 deletions(-) delete mode 100644 src/libstd/unstable/global.rs (limited to 'src/libstd') diff --git a/src/libstd/unstable/global.rs b/src/libstd/unstable/global.rs deleted file mode 100644 index af28879f739..00000000000 --- a/src/libstd/unstable/global.rs +++ /dev/null @@ -1,281 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! -Global data - -An interface for creating and retrieving values with global -(per-runtime) scope. - -Global values are stored in a map and protected by a single global -mutex. Operations are provided for accessing and cloning the value -under the mutex. - -Because all globals go through a single mutex, they should be used -sparingly. The interface is intended to be used with clonable, -atomically reference counted synchronization types, like ARCs, in -which case the value should be cached locally whenever possible to -avoid hitting the mutex. -*/ - -use cast::{transmute}; -use clone::Clone; -use kinds::Send; -use libc::{c_void, intptr_t}; -use option::{Option, Some, None}; -use ops::Drop; -use unstable::sync::{Exclusive, exclusive}; -use unstable::at_exit::at_exit; -use unstable::intrinsics::atomic_cxchg; -use hashmap::HashMap; -use sys::Closure; - -#[cfg(test)] use unstable::sync::{UnsafeAtomicRcBox}; -#[cfg(test)] use task::spawn; -#[cfg(test)] use uint; - -pub type GlobalDataKey<'self,T> = &'self fn(v: T); - -pub unsafe fn global_data_clone_create( - key: GlobalDataKey, create: &fn() -> ~T) -> T { - /*! - * Clone a global value or, if it has not been created, - * first construct the value then return a clone. - * - * # Safety note - * - * Both the clone operation and the constructor are - * called while the global lock is held. Recursive - * use of the global interface in either of these - * operations will result in deadlock. - */ - global_data_clone_create_(key_ptr(key), create) -} - -unsafe fn global_data_clone_create_( - key: uint, create: &fn() -> ~T) -> T { - - let mut clone_value: Option = None; - do global_data_modify_(key) |value: Option<~T>| { - match value { - None => { - let value = create(); - clone_value = Some((*value).clone()); - Some(value) - } - Some(value) => { - clone_value = Some((*value).clone()); - Some(value) - } - } - } - return clone_value.unwrap(); -} - -unsafe fn global_data_modify( - key: GlobalDataKey, op: &fn(Option<~T>) -> Option<~T>) { - - global_data_modify_(key_ptr(key), op) -} - -unsafe fn global_data_modify_( - key: uint, op: &fn(Option<~T>) -> Option<~T>) { - - let mut old_dtor = None; - do get_global_state().with |gs| { - let (maybe_new_value, maybe_dtor) = match gs.map.pop(&key) { - Some((ptr, dtor)) => { - let value: ~T = transmute(ptr); - (op(Some(value)), Some(dtor)) - } - None => { - (op(None), None) - } - }; - match maybe_new_value { - Some(value) => { - let data: *c_void = transmute(value); - let dtor: ~fn() = match maybe_dtor { - Some(dtor) => dtor, - None => { - let dtor: ~fn() = || { - let _destroy_value: ~T = transmute(data); - }; - dtor - } - }; - let value = (data, dtor); - gs.map.insert(key, value); - } - None => { - match maybe_dtor { - Some(dtor) => old_dtor = Some(dtor), - None => () - } - } - } - } -} - -pub unsafe fn global_data_clone( - key: GlobalDataKey) -> Option { - let mut maybe_clone: Option = None; - do global_data_modify(key) |current| { - match ¤t { - &Some(~ref value) => { - maybe_clone = Some(value.clone()); - } - &None => () - } - current - } - return maybe_clone; -} - -// GlobalState is a map from keys to unique pointers and a -// destructor. Keys are pointers derived from the type of the -// global value. There is a single GlobalState instance per runtime. -struct GlobalState { - map: HashMap -} - -impl Drop for GlobalState { - fn drop(&self) { - for self.map.each_value |v| { - match v { - &(_, ref dtor) => (*dtor)() - } - } - } -} - -fn get_global_state() -> Exclusive { - - static POISON: int = -1; - - // FIXME #4728: Doing atomic_cxchg to initialize the global state - // lazily, which wouldn't be necessary with a runtime written - // in Rust - let global_ptr = unsafe { rust_get_global_data_ptr() }; - - if unsafe { *global_ptr } == 0 { - // Global state doesn't exist yet, probably - - // The global state object - let state = GlobalState { - map: HashMap::new() - }; - - // It's under a reference-counted mutex - let state = ~exclusive(state); - - // Convert it to an integer - let state_i: int = unsafe { - let state_ptr: &Exclusive = state; - transmute(state_ptr) - }; - - // Swap our structure into the global pointer - let prev_i = unsafe { atomic_cxchg(&mut *global_ptr, 0, state_i) }; - - // Sanity check that we're not trying to reinitialize after shutdown - assert!(prev_i != POISON); - - if prev_i == 0 { - // Successfully installed the global pointer - - // Take a handle to return - let clone = (*state).clone(); - - // Install a runtime exit function to destroy the global object - do at_exit { - // Poison the global pointer - let prev_i = unsafe { - atomic_cxchg(&mut *global_ptr, state_i, POISON) - }; - assert_eq!(prev_i, state_i); - - // Capture the global state object in the at_exit closure - // so that it is destroyed at the right time - let _capture_global_state = &state; - }; - return clone; - } else { - // Somebody else initialized the globals first - let state: &Exclusive = unsafe { transmute(prev_i) }; - return state.clone(); - } - } else { - let state: &Exclusive = unsafe { - transmute(*global_ptr) - }; - return state.clone(); - } -} - -fn key_ptr(key: GlobalDataKey) -> uint { - unsafe { - let closure: Closure = transmute(key); - return transmute(closure.code); - } -} - -extern { - fn rust_get_global_data_ptr() -> *mut intptr_t; -} - -#[test] -fn test_clone_rc() { - fn key(_v: UnsafeAtomicRcBox) { } - - for uint::range(0, 100) |_| { - do spawn { - unsafe { - let val = do global_data_clone_create(key) { - ~UnsafeAtomicRcBox::new(10) - }; - - assert!(val.get() == &10); - } - } - } -} - -#[test] -fn test_modify() { - fn key(_v: UnsafeAtomicRcBox) { } - - unsafe { - do global_data_modify(key) |v| { - match v { - None => { Some(~UnsafeAtomicRcBox::new(10)) } - _ => fail!() - } - } - - do global_data_modify(key) |v| { - match v { - Some(sms) => { - let v = sms.get(); - assert!(*v == 10); - None - }, - _ => fail!() - } - } - - do global_data_modify(key) |v| { - match v { - None => { Some(~UnsafeAtomicRcBox::new(10)) } - _ => fail!() - } - } - } -} diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index e6313a10db1..3c1da46cf02 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -20,7 +20,6 @@ pub mod at_exit; pub mod dynamic_lib; -pub mod global; pub mod finally; pub mod intrinsics; pub mod simd; diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 4dde01d5f00..860f20e7308 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -763,12 +763,6 @@ rust_register_exit_function(spawn_fn runner, fn_env_pair *f) { task->kernel->register_exit_function(runner, f); } -extern "C" intptr_t* -rust_get_global_data_ptr() { - rust_task *task = rust_get_current_task(); - return &task->kernel->global_data; -} - #ifndef _WIN32 #include #include diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 583f836c0d6..20ac5384a3c 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -33,8 +33,7 @@ rust_kernel::rust_kernel(rust_env *env) : non_weak_tasks(0), at_exit_runner(NULL), at_exit_started(false), - env(env), - global_data(0) + env(env) { // Create the single threaded scheduler that will run on the platform's // main thread diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 09f73f9b7d8..91f49662f46 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -124,7 +124,6 @@ class rust_kernel { public: struct rust_env *env; - intptr_t global_data; rust_kernel(rust_env *env); diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index e9e0f3b6949..c07868aede1 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -215,7 +215,6 @@ linenoiseHistoryLoad rust_raw_thread_start rust_raw_thread_join_delete rust_register_exit_function -rust_get_global_data_ptr rust_get_rt_tls_key swap_registers rust_readdir -- cgit 1.4.1-3-g733a5 From 407bffb33e59db9c2ed0c0c5a6533f2ab88743e0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Jul 2013 19:51:40 -0700 Subject: std: Remove at_exit API. Unused --- src/libstd/unstable/at_exit.rs | 100 ----------------------------------------- src/libstd/unstable/mod.rs | 2 - src/rt/rust_builtin.cpp | 6 --- src/rt/rust_kernel.cpp | 47 ------------------- src/rt/rust_kernel.h | 16 ------- src/rt/rustrt.def.in | 1 - 6 files changed, 172 deletions(-) delete mode 100644 src/libstd/unstable/at_exit.rs (limited to 'src/libstd') diff --git a/src/libstd/unstable/at_exit.rs b/src/libstd/unstable/at_exit.rs deleted file mode 100644 index 20ddf941a7b..00000000000 --- a/src/libstd/unstable/at_exit.rs +++ /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 or the MIT license -// , 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); - } - } -} diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index 3c1da46cf02..d6fd2cbcd1e 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -16,8 +16,6 @@ use libc; use prelude::*; use task; -pub mod at_exit; - pub mod dynamic_lib; pub mod finally; diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 860f20e7308..06b09bcedd2 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -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 #include diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 20ac5384a3c..814cfbb310a 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -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++ diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 91f49662f46..0fe3f761040 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -63,13 +63,6 @@ typedef intptr_t rust_task_id; typedef std::map 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 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 struct kernel_owned { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index c07868aede1..db9fe247952 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -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 -- cgit 1.4.1-3-g733a5