Make some more rt components public
Primarily this makes the Scheduler and all of its related interfaces public. The reason for doing this is that currently any extern event loops had no access to the scheduler at all. This allows third-party event loops to manipulate the scheduler, along with allowing the uv event loop to live inside of its own crate.
This commit is contained in:
parent
2ab4a6fab0
commit
5dd1583c57
|
@ -87,15 +87,13 @@ pub use self::util::set_exit_status;
|
||||||
// method...
|
// method...
|
||||||
pub use self::util::default_sched_threads;
|
pub use self::util::default_sched_threads;
|
||||||
|
|
||||||
|
// Re-export of the functionality in the kill module
|
||||||
|
pub use self::kill::{KillHandle, BlockedTask};
|
||||||
|
|
||||||
// XXX: these probably shouldn't be public...
|
// XXX: these probably shouldn't be public...
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod shouldnt_be_public {
|
pub mod shouldnt_be_public {
|
||||||
pub use super::sched::Scheduler;
|
|
||||||
pub use super::kill::KillHandle;
|
|
||||||
pub use super::thread::Thread;
|
|
||||||
pub use super::work_queue::WorkQueue;
|
|
||||||
pub use super::select::SelectInner;
|
pub use super::select::SelectInner;
|
||||||
pub use super::rtio::EventLoop;
|
|
||||||
pub use super::select::{SelectInner, SelectPortInner};
|
pub use super::select::{SelectInner, SelectPortInner};
|
||||||
pub use super::local_ptr::maybe_tls_key;
|
pub use super::local_ptr::maybe_tls_key;
|
||||||
}
|
}
|
||||||
|
@ -116,13 +114,13 @@ pub mod task;
|
||||||
mod kill;
|
mod kill;
|
||||||
|
|
||||||
/// The coroutine task scheduler, built on the `io` event loop.
|
/// The coroutine task scheduler, built on the `io` event loop.
|
||||||
mod sched;
|
pub mod sched;
|
||||||
|
|
||||||
/// Synchronous I/O.
|
/// Synchronous I/O.
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
|
||||||
/// The EventLoop and internal synchronous I/O interface.
|
/// The EventLoop and internal synchronous I/O interface.
|
||||||
mod rtio;
|
pub mod rtio;
|
||||||
|
|
||||||
/// libuv and default rtio implementation.
|
/// libuv and default rtio implementation.
|
||||||
pub mod uv;
|
pub mod uv;
|
||||||
|
@ -132,10 +130,10 @@ pub mod uv;
|
||||||
pub mod local;
|
pub mod local;
|
||||||
|
|
||||||
/// A parallel work-stealing deque.
|
/// A parallel work-stealing deque.
|
||||||
mod work_queue;
|
pub mod work_queue;
|
||||||
|
|
||||||
/// A parallel queue.
|
/// A parallel queue.
|
||||||
mod message_queue;
|
pub mod message_queue;
|
||||||
|
|
||||||
/// A mostly lock-free multi-producer, single consumer queue.
|
/// A mostly lock-free multi-producer, single consumer queue.
|
||||||
mod mpsc_queue;
|
mod mpsc_queue;
|
||||||
|
@ -144,7 +142,7 @@ mod mpsc_queue;
|
||||||
mod mpmc_bounded_queue;
|
mod mpmc_bounded_queue;
|
||||||
|
|
||||||
/// A parallel data structure for tracking sleeping schedulers.
|
/// A parallel data structure for tracking sleeping schedulers.
|
||||||
mod sleeper_list;
|
pub mod sleeper_list;
|
||||||
|
|
||||||
/// Stack segments and caching.
|
/// Stack segments and caching.
|
||||||
pub mod stack;
|
pub mod stack;
|
||||||
|
@ -153,7 +151,7 @@ pub mod stack;
|
||||||
mod context;
|
mod context;
|
||||||
|
|
||||||
/// Bindings to system threading libraries.
|
/// Bindings to system threading libraries.
|
||||||
mod thread;
|
pub mod thread;
|
||||||
|
|
||||||
/// The runtime configuration, read from environment variables.
|
/// The runtime configuration, read from environment variables.
|
||||||
pub mod env;
|
pub mod env;
|
||||||
|
@ -327,7 +325,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
|
||||||
// waking up schedulers for work stealing; since this is a
|
// waking up schedulers for work stealing; since this is a
|
||||||
// non-work-stealing scheduler it should not be adding itself
|
// non-work-stealing scheduler it should not be adding itself
|
||||||
// to the list.
|
// to the list.
|
||||||
main_handle.send_shutdown();
|
main_handle.send(Shutdown);
|
||||||
Some(main_sched)
|
Some(main_sched)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -542,7 +542,7 @@ impl Scheduler {
|
||||||
|
|
||||||
match this.sleeper_list.casual_pop() {
|
match this.sleeper_list.casual_pop() {
|
||||||
Some(handle) => {
|
Some(handle) => {
|
||||||
let mut handle = handle;
|
let mut handle = handle;
|
||||||
handle.send(Wake)
|
handle.send(Wake)
|
||||||
}
|
}
|
||||||
None => { (/* pass */) }
|
None => { (/* pass */) }
|
||||||
|
@ -818,12 +818,6 @@ impl SchedHandle {
|
||||||
self.queue.push(msg);
|
self.queue.push(msg);
|
||||||
self.remote.fire();
|
self.remote.fire();
|
||||||
}
|
}
|
||||||
pub fn send_task_from_friend(&mut self, friend: ~Task) {
|
|
||||||
self.send(TaskFromFriend(friend));
|
|
||||||
}
|
|
||||||
pub fn send_shutdown(&mut self) {
|
|
||||||
self.send(Shutdown);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CleanupJob {
|
struct CleanupJob {
|
||||||
|
@ -1266,15 +1260,15 @@ mod test {
|
||||||
use comm::{GenericPort, GenericChan};
|
use comm::{GenericPort, GenericChan};
|
||||||
|
|
||||||
do run_in_mt_newsched_task {
|
do run_in_mt_newsched_task {
|
||||||
let (end_port, end_chan) = oneshot();
|
let (end_port, end_chan) = oneshot();
|
||||||
|
|
||||||
let n_tasks = 10;
|
let n_tasks = 10;
|
||||||
let token = 2000;
|
let token = 2000;
|
||||||
|
|
||||||
let (p, ch1) = stream();
|
let (p, ch1) = stream();
|
||||||
let mut p = p;
|
let mut p = p;
|
||||||
ch1.send((token, end_chan));
|
ch1.send((token, end_chan));
|
||||||
let mut i = 2;
|
let mut i = 2;
|
||||||
while i <= n_tasks {
|
while i <= n_tasks {
|
||||||
let (next_p, ch) = stream();
|
let (next_p, ch) = stream();
|
||||||
let imm_i = i;
|
let imm_i = i;
|
||||||
|
|
|
@ -18,7 +18,9 @@ use option::*;
|
||||||
// use either::{Either, Left, Right};
|
// use either::{Either, Left, Right};
|
||||||
// use rt::kill::BlockedTask;
|
// use rt::kill::BlockedTask;
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
use rt::shouldnt_be_public::{EventLoop, Scheduler, SelectInner, SelectPortInner};
|
use rt::rtio::EventLoop;
|
||||||
|
use rt::sched::Scheduler;
|
||||||
|
use rt::shouldnt_be_public::{SelectInner, SelectPortInner};
|
||||||
use task;
|
use task;
|
||||||
use unstable::finally::Finally;
|
use unstable::finally::Finally;
|
||||||
use vec::{OwnedVector, MutableVector};
|
use vec::{OwnedVector, MutableVector};
|
||||||
|
|
|
@ -578,7 +578,7 @@ pub fn deschedule() {
|
||||||
//! Yield control to the task scheduler
|
//! Yield control to the task scheduler
|
||||||
|
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
use rt::shouldnt_be_public::Scheduler;
|
use rt::sched::Scheduler;
|
||||||
|
|
||||||
// FIXME(#7544): Optimize this, since we know we won't block.
|
// FIXME(#7544): Optimize this, since we know we won't block.
|
||||||
let sched: ~Scheduler = Local::take();
|
let sched: ~Scheduler = Local::take();
|
||||||
|
@ -1094,7 +1094,7 @@ fn test_try_fail() {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn get_sched_id() -> int {
|
fn get_sched_id() -> int {
|
||||||
do Local::borrow |sched: &mut ::rt::shouldnt_be_public::Scheduler| {
|
do Local::borrow |sched: &mut ::rt::sched::Scheduler| {
|
||||||
sched.sched_id() as int
|
sched.sched_id() as int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,11 @@ use hashmap::{HashSet, HashSetMoveIterator};
|
||||||
use local_data;
|
use local_data;
|
||||||
use rt::in_green_task_context;
|
use rt::in_green_task_context;
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
use rt::shouldnt_be_public::{Scheduler, KillHandle, WorkQueue, Thread, EventLoop};
|
use rt::sched::Scheduler;
|
||||||
|
use rt::KillHandle;
|
||||||
|
use rt::work_queue::WorkQueue;
|
||||||
|
use rt::rtio::EventLoop;
|
||||||
|
use rt::thread::Thread;
|
||||||
use rt::task::{Task, Sched};
|
use rt::task::{Task, Sched};
|
||||||
use rt::task::{UnwindReasonLinked, UnwindReasonStr};
|
use rt::task::{UnwindReasonLinked, UnwindReasonStr};
|
||||||
use rt::task::{UnwindResult, Success, Failure};
|
use rt::task::{UnwindResult, Success, Failure};
|
||||||
|
@ -627,7 +631,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
|
||||||
let mut new_sched_handle = new_sched.make_handle();
|
let mut new_sched_handle = new_sched.make_handle();
|
||||||
|
|
||||||
// Allow the scheduler to exit when the pinned task exits
|
// Allow the scheduler to exit when the pinned task exits
|
||||||
new_sched_handle.send_shutdown();
|
new_sched_handle.send(Shutdown);
|
||||||
|
|
||||||
// Pin the new task to the new scheduler
|
// Pin the new task to the new scheduler
|
||||||
let new_task = if opts.watched {
|
let new_task = if opts.watched {
|
||||||
|
@ -665,7 +669,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
|
||||||
debug!("enqueing join_task");
|
debug!("enqueing join_task");
|
||||||
// Now tell the original scheduler to join with this thread
|
// Now tell the original scheduler to join with this thread
|
||||||
// by scheduling a thread-joining task on the original scheduler
|
// by scheduling a thread-joining task on the original scheduler
|
||||||
orig_sched_handle.send_task_from_friend(join_task);
|
orig_sched_handle.send(TaskFromFriend(join_task));
|
||||||
|
|
||||||
// NB: We can't simply send a message from here to another task
|
// NB: We can't simply send a message from here to another task
|
||||||
// because this code isn't running in a task and message passing doesn't
|
// because this code isn't running in a task and message passing doesn't
|
||||||
|
|
|
@ -37,7 +37,7 @@ a normal large stack.
|
||||||
*/
|
*/
|
||||||
pub fn run_in_bare_thread(f: ~fn()) {
|
pub fn run_in_bare_thread(f: ~fn()) {
|
||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
use rt::shouldnt_be_public::Thread;
|
use rt::thread::Thread;
|
||||||
|
|
||||||
let f_cell = Cell::new(f);
|
let f_cell = Cell::new(f);
|
||||||
let (port, chan) = comm::stream();
|
let (port, chan) = comm::stream();
|
||||||
|
|
Loading…
Reference in New Issue