about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-03-05 10:35:30 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-03-05 21:48:08 -0800
commit9668ab58f338b27d8f53357c7fd4ea3d3f06305e (patch)
treea51174739f9ed9c1910d9676a29a818d49a15009 /src/libnative
parente6acff828787b9b6c65ef66942f45e58b2f22ad6 (diff)
downloadrust-9668ab58f338b27d8f53357c7fd4ea3d3f06305e.tar.gz
rust-9668ab58f338b27d8f53357c7fd4ea3d3f06305e.zip
std: Move libnative task count bookkeeping to std
When using tasks in Rust, the expectation is that the runtime does not exit
before all tasks have exited. This is enforced in libgreen through the
`SchedPool` type, and it is enforced in libnative through a `bookkeeping` module
and a global count/mutex pair. Unfortunately, this means that a process which
originates with libgreen will not wait for spawned native tasks.

In order to fix this problem, the bookkeeping module was moved from libnative to
libstd so the runtime itself can wait for native tasks to exit. Green tasks do
not manage themselves through this bookkeeping module, but native tasks will
continue to manage themselves through this module.

Closes #12684
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/bookkeeping.rs47
-rw-r--r--src/libnative/io/timer_helper.rs2
-rw-r--r--src/libnative/lib.rs2
-rw-r--r--src/libnative/task.rs4
4 files changed, 3 insertions, 52 deletions
diff --git a/src/libnative/bookkeeping.rs b/src/libnative/bookkeeping.rs
deleted file mode 100644
index 76e58ce753f..00000000000
--- a/src/libnative/bookkeeping.rs
+++ /dev/null
@@ -1,47 +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.
-
-//! 1:1 Task bookkeeping
-//!
-//! This module keeps track of the number of running 1:1 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.
-
-use std::sync::atomics;
-use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
-
-static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
-static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
-
-pub fn increment() {
-    let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
-}
-
-pub fn decrement() {
-    unsafe {
-        if TASK_COUNT.fetch_sub(1, atomics::SeqCst) == 1 {
-            let mut 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 mut guard = TASK_LOCK.lock();
-        while TASK_COUNT.load(atomics::SeqCst) > 0 {
-            guard.wait();
-        }
-    }
-}
diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs
index 45bd0f8b67c..62e41771423 100644
--- a/src/libnative/io/timer_helper.rs
+++ b/src/libnative/io/timer_helper.rs
@@ -21,10 +21,10 @@
 //! time.
 
 use std::cast;
+use std::rt::bookkeeping;
 use std::rt;
 use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
 
-use bookkeeping;
 use io::timer::{Req, Shutdown};
 use task;
 
diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs
index 378283973db..4b6942a1083 100644
--- a/src/libnative/lib.rs
+++ b/src/libnative/lib.rs
@@ -58,7 +58,6 @@
 use std::os;
 use std::rt;
 
-mod bookkeeping;
 pub mod io;
 pub mod task;
 
@@ -105,6 +104,5 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
 /// number of arguments.
 pub fn run(main: proc()) -> int {
     main();
-    bookkeeping::wait_for_other_tasks();
     os::get_exit_status()
 }
diff --git a/src/libnative/task.rs b/src/libnative/task.rs
index aa3afd4c1a5..793e4d48e13 100644
--- a/src/libnative/task.rs
+++ b/src/libnative/task.rs
@@ -16,19 +16,19 @@
 
 use std::any::Any;
 use std::cast;
+use std::rt::bookkeeping;
 use std::rt::env;
 use std::rt::local::Local;
 use std::rt::rtio;
+use std::rt::stack;
 use std::rt::task::{Task, BlockedTask, SendMessage};
 use std::rt::thread::Thread;
 use std::rt;
 use std::task::TaskOpts;
 use std::unstable::mutex::NativeMutex;
-use std::rt::stack;
 
 use io;
 use task;
-use bookkeeping;
 
 /// Creates a new Task which is ready to execute as a 1:1 task.
 pub fn new(stack_bounds: (uint, uint)) -> ~Task {