Skip to content

Commit 5dd1583

Browse files
committed
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.
1 parent 2ab4a6f commit 5dd1583

File tree

6 files changed

+28
-30
lines changed

6 files changed

+28
-30
lines changed

src/libstd/rt/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ pub use self::util::set_exit_status;
8787
// method...
8888
pub use self::util::default_sched_threads;
8989

90+
// Re-export of the functionality in the kill module
91+
pub use self::kill::{KillHandle, BlockedTask};
92+
9093
// XXX: these probably shouldn't be public...
9194
#[doc(hidden)]
9295
pub mod shouldnt_be_public {
93-
pub use super::sched::Scheduler;
94-
pub use super::kill::KillHandle;
95-
pub use super::thread::Thread;
96-
pub use super::work_queue::WorkQueue;
9796
pub use super::select::SelectInner;
98-
pub use super::rtio::EventLoop;
9997
pub use super::select::{SelectInner, SelectPortInner};
10098
pub use super::local_ptr::maybe_tls_key;
10199
}
@@ -116,13 +114,13 @@ pub mod task;
116114
mod kill;
117115

118116
/// The coroutine task scheduler, built on the `io` event loop.
119-
mod sched;
117+
pub mod sched;
120118

121119
/// Synchronous I/O.
122120
pub mod io;
123121

124122
/// The EventLoop and internal synchronous I/O interface.
125-
mod rtio;
123+
pub mod rtio;
126124

127125
/// libuv and default rtio implementation.
128126
pub mod uv;
@@ -132,10 +130,10 @@ pub mod uv;
132130
pub mod local;
133131

134132
/// A parallel work-stealing deque.
135-
mod work_queue;
133+
pub mod work_queue;
136134

137135
/// A parallel queue.
138-
mod message_queue;
136+
pub mod message_queue;
139137

140138
/// A mostly lock-free multi-producer, single consumer queue.
141139
mod mpsc_queue;
@@ -144,7 +142,7 @@ mod mpsc_queue;
144142
mod mpmc_bounded_queue;
145143

146144
/// A parallel data structure for tracking sleeping schedulers.
147-
mod sleeper_list;
145+
pub mod sleeper_list;
148146

149147
/// Stack segments and caching.
150148
pub mod stack;
@@ -153,7 +151,7 @@ pub mod stack;
153151
mod context;
154152

155153
/// Bindings to system threading libraries.
156-
mod thread;
154+
pub mod thread;
157155

158156
/// The runtime configuration, read from environment variables.
159157
pub mod env;
@@ -327,7 +325,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
327325
// waking up schedulers for work stealing; since this is a
328326
// non-work-stealing scheduler it should not be adding itself
329327
// to the list.
330-
main_handle.send_shutdown();
328+
main_handle.send(Shutdown);
331329
Some(main_sched)
332330
} else {
333331
None

src/libstd/rt/sched.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl Scheduler {
542542

543543
match this.sleeper_list.casual_pop() {
544544
Some(handle) => {
545-
let mut handle = handle;
545+
let mut handle = handle;
546546
handle.send(Wake)
547547
}
548548
None => { (/* pass */) }
@@ -818,12 +818,6 @@ impl SchedHandle {
818818
self.queue.push(msg);
819819
self.remote.fire();
820820
}
821-
pub fn send_task_from_friend(&mut self, friend: ~Task) {
822-
self.send(TaskFromFriend(friend));
823-
}
824-
pub fn send_shutdown(&mut self) {
825-
self.send(Shutdown);
826-
}
827821
}
828822

829823
struct CleanupJob {
@@ -1266,15 +1260,15 @@ mod test {
12661260
use comm::{GenericPort, GenericChan};
12671261

12681262
do run_in_mt_newsched_task {
1269-
let (end_port, end_chan) = oneshot();
1263+
let (end_port, end_chan) = oneshot();
12701264

12711265
let n_tasks = 10;
12721266
let token = 2000;
12731267

1274-
let (p, ch1) = stream();
1268+
let (p, ch1) = stream();
12751269
let mut p = p;
1276-
ch1.send((token, end_chan));
1277-
let mut i = 2;
1270+
ch1.send((token, end_chan));
1271+
let mut i = 2;
12781272
while i <= n_tasks {
12791273
let (next_p, ch) = stream();
12801274
let imm_i = i;

src/libstd/select.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use option::*;
1818
// use either::{Either, Left, Right};
1919
// use rt::kill::BlockedTask;
2020
use rt::local::Local;
21-
use rt::shouldnt_be_public::{EventLoop, Scheduler, SelectInner, SelectPortInner};
21+
use rt::rtio::EventLoop;
22+
use rt::sched::Scheduler;
23+
use rt::shouldnt_be_public::{SelectInner, SelectPortInner};
2224
use task;
2325
use unstable::finally::Finally;
2426
use vec::{OwnedVector, MutableVector};

src/libstd/task/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ pub fn deschedule() {
578578
//! Yield control to the task scheduler
579579
580580
use rt::local::Local;
581-
use rt::shouldnt_be_public::Scheduler;
581+
use rt::sched::Scheduler;
582582

583583
// FIXME(#7544): Optimize this, since we know we won't block.
584584
let sched: ~Scheduler = Local::take();
@@ -1094,7 +1094,7 @@ fn test_try_fail() {
10941094
10951095
#[cfg(test)]
10961096
fn get_sched_id() -> int {
1097-
do Local::borrow |sched: &mut ::rt::shouldnt_be_public::Scheduler| {
1097+
do Local::borrow |sched: &mut ::rt::sched::Scheduler| {
10981098
sched.sched_id() as int
10991099
}
11001100
}

src/libstd/task/spawn.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ use hashmap::{HashSet, HashSetMoveIterator};
8282
use local_data;
8383
use rt::in_green_task_context;
8484
use rt::local::Local;
85-
use rt::shouldnt_be_public::{Scheduler, KillHandle, WorkQueue, Thread, EventLoop};
85+
use rt::sched::Scheduler;
86+
use rt::KillHandle;
87+
use rt::work_queue::WorkQueue;
88+
use rt::rtio::EventLoop;
89+
use rt::thread::Thread;
8690
use rt::task::{Task, Sched};
8791
use rt::task::{UnwindReasonLinked, UnwindReasonStr};
8892
use rt::task::{UnwindResult, Success, Failure};
@@ -627,7 +631,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
627631
let mut new_sched_handle = new_sched.make_handle();
628632

629633
// Allow the scheduler to exit when the pinned task exits
630-
new_sched_handle.send_shutdown();
634+
new_sched_handle.send(Shutdown);
631635

632636
// Pin the new task to the new scheduler
633637
let new_task = if opts.watched {
@@ -665,7 +669,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
665669
debug!("enqueing join_task");
666670
// Now tell the original scheduler to join with this thread
667671
// by scheduling a thread-joining task on the original scheduler
668-
orig_sched_handle.send_task_from_friend(join_task);
672+
orig_sched_handle.send(TaskFromFriend(join_task));
669673

670674
// NB: We can't simply send a message from here to another task
671675
// because this code isn't running in a task and message passing doesn't

src/libstd/unstable/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ a normal large stack.
3737
*/
3838
pub fn run_in_bare_thread(f: ~fn()) {
3939
use cell::Cell;
40-
use rt::shouldnt_be_public::Thread;
40+
use rt::thread::Thread;
4141

4242
let f_cell = Cell::new(f);
4343
let (port, chan) = comm::stream();

0 commit comments

Comments
 (0)