Skip to content

Commit f41a0d9

Browse files
committed
---
yaml --- r: 142577 b: refs/heads/try2 c: 41c2168 h: refs/heads/master i: 142575: 9208e89 v: v3
1 parent 02dd442 commit f41a0d9

File tree

2 files changed

+79
-24
lines changed

2 files changed

+79
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a0cd55a1d7436dc9532ddf5cdad7d1f7e8f108f3
8+
refs/heads/try2: 41c21685dd149fb95dededfb4edaf87c6603c099
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/rt/sched.rs

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cell::Cell;
1515

1616
use super::work_queue::WorkQueue;
1717
use super::stack::{StackPool, StackSegment};
18-
use super::rtio::{EventLoop, EventLoopObject};
18+
use super::rtio::{EventLoop, EventLoopObject, RemoteCallbackObject};
1919
use super::context::Context;
2020
use super::task::Task;
2121
use rt::local_ptr;
@@ -41,16 +41,19 @@ pub struct Scheduler {
4141
priv cleanup_job: Option<CleanupJob>
4242
}
4343

44-
// XXX: Some hacks to put a &fn in Scheduler without borrowck
45-
// complaining
46-
type UnsafeTaskReceiver = sys::Closure;
47-
trait ClosureConverter {
48-
fn from_fn(&fn(~Coroutine)) -> Self;
49-
fn to_fn(self) -> &fn(~Coroutine);
44+
pub struct Coroutine {
45+
/// The segment of stack on which the task is currently running or,
46+
/// if the task is blocked, on which the task will resume execution
47+
priv current_stack_segment: StackSegment,
48+
/// These are always valid when the task is not running, unless
49+
/// the task is dead
50+
priv saved_context: Context,
51+
/// The heap, GC, unwinding, local storage, logging
52+
task: ~Task
5053
}
51-
impl ClosureConverter for UnsafeTaskReceiver {
52-
fn from_fn(f: &fn(~Coroutine)) -> UnsafeTaskReceiver { unsafe { transmute(f) } }
53-
fn to_fn(self) -> &fn(~Coroutine) { unsafe { transmute(self) } }
54+
55+
pub struct SchedHandle {
56+
priv remote: ~RemoteCallbackObject
5457
}
5558

5659
enum CleanupJob {
@@ -103,6 +106,17 @@ pub impl Scheduler {
103106
return sched;
104107
}
105108

109+
fn make_handle(&mut self) -> SchedHandle {
110+
let remote = self.event_loop.remote_callback(wake_up);
111+
112+
return SchedHandle {
113+
remote: remote
114+
};
115+
116+
fn wake_up() {
117+
}
118+
}
119+
106120
/// Schedule a task to be executed later.
107121
///
108122
/// Pushes the task onto the work stealing queue and tells the event loop
@@ -337,19 +351,6 @@ pub impl Scheduler {
337351
}
338352
}
339353

340-
static MIN_STACK_SIZE: uint = 10000000; // XXX: Too much stack
341-
342-
pub struct Coroutine {
343-
/// The segment of stack on which the task is currently running or,
344-
/// if the task is blocked, on which the task will resume execution
345-
priv current_stack_segment: StackSegment,
346-
/// These are always valid when the task is not running, unless
347-
/// the task is dead
348-
priv saved_context: Context,
349-
/// The heap, GC, unwinding, local storage, logging
350-
task: ~Task
351-
}
352-
353354
pub impl Coroutine {
354355
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
355356
Coroutine::with_task(stack_pool, ~Task::new(), start)
@@ -358,6 +359,9 @@ pub impl Coroutine {
358359
fn with_task(stack_pool: &mut StackPool,
359360
task: ~Task,
360361
start: ~fn()) -> Coroutine {
362+
363+
static MIN_STACK_SIZE: uint = 10000000; // XXX: Too much stack
364+
361365
let start = Coroutine::build_start_wrapper(start);
362366
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
363367
// NB: Context holds a pointer to that ~fn
@@ -401,6 +405,18 @@ pub impl Coroutine {
401405
}
402406
}
403407

408+
// XXX: Some hacks to put a &fn in Scheduler without borrowck
409+
// complaining
410+
type UnsafeTaskReceiver = sys::Closure;
411+
trait ClosureConverter {
412+
fn from_fn(&fn(~Coroutine)) -> Self;
413+
fn to_fn(self) -> &fn(~Coroutine);
414+
}
415+
impl ClosureConverter for UnsafeTaskReceiver {
416+
fn from_fn(f: &fn(~Coroutine)) -> UnsafeTaskReceiver { unsafe { transmute(f) } }
417+
fn to_fn(self) -> &fn(~Coroutine) { unsafe { transmute(self) } }
418+
}
419+
404420
#[cfg(test)]
405421
mod test {
406422
use int;
@@ -411,6 +427,7 @@ mod test {
411427
use rt::local::Local;
412428
use rt::test::*;
413429
use super::*;
430+
use rt::thread::Thread;
414431

415432
#[test]
416433
fn test_simple_scheduling() {
@@ -551,4 +568,42 @@ mod test {
551568
}
552569
}
553570
}
571+
572+
#[test]
573+
fn handle() {
574+
use rt::comm::*;
575+
576+
do run_in_bare_thread {
577+
let (port, chan) = oneshot::<()>();
578+
let port_cell = Cell(port);
579+
let chan_cell = Cell(chan);
580+
let mut sched1 = ~UvEventLoop::new_scheduler();
581+
let handle1 = sched1.make_handle();
582+
let handle1_cell = Cell(handle1);
583+
let task1 = ~do Coroutine::new(&mut sched1.stack_pool) {
584+
chan_cell.take().send(());
585+
};
586+
sched1.enqueue_task(task1);
587+
588+
let mut sched2 = ~UvEventLoop::new_scheduler();
589+
let task2 = ~do Coroutine::new(&mut sched2.stack_pool) {
590+
port_cell.take().recv();
591+
// Release the other scheduler's handle so it can exit
592+
handle1_cell.take();
593+
};
594+
sched2.enqueue_task(task2);
595+
596+
let sched1_cell = Cell(sched1);
597+
let _thread1 = do Thread::start {
598+
let mut sched1 = sched1_cell.take();
599+
sched1.run();
600+
};
601+
602+
let sched2_cell = Cell(sched2);
603+
let _thread2 = do Thread::start {
604+
let mut sched2 = sched2_cell.take();
605+
sched2.run();
606+
};
607+
}
608+
}
554609
}

0 commit comments

Comments
 (0)