]> git.lizzy.rs Git - rust.git/commitdiff
Remove rt::bookkeeping
authorAaron Turon <aturon@mozilla.com>
Tue, 25 Nov 2014 01:33:37 +0000 (17:33 -0800)
committerAaron Turon <aturon@mozilla.com>
Fri, 19 Dec 2014 07:31:35 +0000 (23:31 -0800)
This commit removes the runtime bookkeeping previously used to ensure
that all Rust tasks were joined before the runtime was shut down.

This functionality will be replaced by an RAII style `Thread` API, that
will also offer a detached mode.

Since this changes the semantics of shutdown, it is a:

[breaking-change]

src/libstd/rt/bookkeeping.rs [deleted file]
src/libstd/rt/mod.rs
src/libstd/rt/task.rs
src/libstd/sys/common/helper_thread.rs

diff --git a/src/libstd/rt/bookkeeping.rs b/src/libstd/rt/bookkeeping.rs
deleted file mode 100644 (file)
index aca520f..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2013-2014 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.
-
-//! Task bookkeeping
-//!
-//! This module keeps track of the number of running tasks so that entry points
-//! with libnative know when it's possible to exit the program (once all tasks
-//! have exited).
-//!
-//! The green counterpart for this is bookkeeping on sched pools, and it's up to
-//! each respective runtime to make sure that they call increment() and
-//! decrement() manually.
-
-use sync::atomic;
-use ops::Drop;
-
-use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
-
-static TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
-static TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
-
-#[allow(missing_copy_implementations)]
-pub struct Token { _private: () }
-
-impl Drop for Token {
-    fn drop(&mut self) { decrement() }
-}
-
-/// Increment the number of live tasks, returning a token which will decrement
-/// the count when dropped.
-pub fn increment() -> Token {
-    let _ = TASK_COUNT.fetch_add(1, atomic::SeqCst);
-    Token { _private: () }
-}
-
-pub fn decrement() {
-    unsafe {
-        if TASK_COUNT.fetch_sub(1, atomic::SeqCst) == 1 {
-            let guard = TASK_LOCK.lock();
-            guard.signal();
-        }
-    }
-}
-
-/// Waits for all other native tasks in the system to exit. This is only used by
-/// the entry points of native programs
-pub fn wait_for_other_tasks() {
-    unsafe {
-        let guard = TASK_LOCK.lock();
-        while TASK_COUNT.load(atomic::SeqCst) > 0 {
-            guard.wait();
-        }
-    }
-}
index 5d5ccefda5dc25acf689f97c4bfad7d42917156f..676dbb0b498a678bcba7d3c85e17da5cf21b60c2 100644 (file)
@@ -73,7 +73,6 @@
 pub mod thread;
 pub mod exclusive;
 pub mod util;
-pub mod bookkeeping;
 pub mod local;
 pub mod task;
 pub mod unwind;
@@ -207,7 +206,6 @@ pub fn at_exit(f: proc():Send) {
 /// Invoking cleanup while portions of the runtime are still in use may cause
 /// undefined behavior.
 pub unsafe fn cleanup() {
-    bookkeeping::wait_for_other_tasks();
     args::cleanup();
     thread::cleanup();
     local_ptr::cleanup();
index babd111b3c221463364c5ec82e3a3c12bd8dfd96..98940a2b381c7b40600920d4ab9391be0e30e9d9 100644 (file)
@@ -29,7 +29,6 @@
 use thunk::Thunk;
 
 use rt;
-use rt::bookkeeping;
 use rt::mutex::NativeMutex;
 use rt::local::Local;
 use rt::thread::{mod, Thread};
@@ -132,11 +131,6 @@ fn spawn_thunk(opts: TaskOpts, f: Thunk) {
 
         let stack = stack_size.unwrap_or(rt::min_stack());
 
-        // Note that this increment must happen *before* the spawn in order to
-        // guarantee that if this task exits it will always end up waiting for
-        // the spawned task to exit.
-        let token = bookkeeping::increment();
-
         // Spawning a new OS thread guarantees that __morestack will never get
         // triggered, but we must manually set up the actual stack bounds once
         // this function starts executing. This raises the lower limit by a bit
@@ -156,7 +150,6 @@ fn spawn_thunk(opts: TaskOpts, f: Thunk) {
 
             let mut f = Some(f);
             drop(task.run(|| { f.take().unwrap().invoke(()) }).destroy());
-            drop(token);
         })
     }
 
index ffb053e852efc6228f4bf0f4f19e3ca39c965a02..ef0181b72b0b7d88300c71f8e1173ee6b0a09f3a 100644 (file)
@@ -25,7 +25,7 @@
 use cell::UnsafeCell;
 use mem;
 use sync::{StaticMutex, StaticCondvar};
-use rt::{mod, bookkeeping};
+use rt;
 use sys::helper_signal;
 
 use task;
@@ -83,7 +83,6 @@ pub fn boot<T, F>(&'static self, f: F, helper: fn(helper_signal::signal, Receive
 
                 let t = f();
                 task::spawn(move |:| {
-                    bookkeeping::decrement();
                     helper(receive, rx, t);
                     let _g = self.lock.lock();
                     *self.shutdown.get() = true;