Skip to content

Commit

Permalink
Merge remote-tracking branch 'toddaaro/niots'
Browse files Browse the repository at this point in the history
Conflicts:
	src/libstd/rt/sched.rs
  • Loading branch information
brson committed Jul 2, 2013
2 parents 6fd15ff + 0607178 commit 75a913f
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 551 deletions.
12 changes: 8 additions & 4 deletions src/libstd/rt/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use cast;
use util;
use ops::Drop;
use kinds::Owned;
use rt::sched::{Scheduler, Coroutine};
use rt::sched::{Scheduler};
use rt::task::Task;
use rt::local::Local;
use unstable::atomics::{AtomicUint, AtomicOption, SeqCst};
use unstable::sync::UnsafeAtomicRcBox;
Expand Down Expand Up @@ -136,7 +137,7 @@ impl<T> ChanOne<T> {
}
task_as_state => {
// Port is blocked. Wake it up.
let recvr: ~Coroutine = cast::transmute(task_as_state);
let recvr: ~Task = cast::transmute(task_as_state);
let mut sched = Local::take::<Scheduler>();
rtdebug!("rendezvous send");
sched.metrics.rendezvous_sends += 1;
Expand Down Expand Up @@ -192,7 +193,7 @@ impl<T> PortOne<T> {
// NB: We have to drop back into the scheduler event loop here
// instead of switching immediately back or we could end up
// triggering infinite recursion on the scheduler's stack.
let task: ~Coroutine = cast::transmute(task_as_state);
let task: ~Task = cast::transmute(task_as_state);
sched.enqueue_task(task);
}
_ => util::unreachable()
Expand Down Expand Up @@ -257,7 +258,7 @@ impl<T> Drop for ChanOneHack<T> {
task_as_state => {
// The port is blocked waiting for a message we will never send. Wake it.
assert!((*this.packet()).payload.is_none());
let recvr: ~Coroutine = cast::transmute(task_as_state);
let recvr: ~Task = cast::transmute(task_as_state);
let sched = Local::take::<Scheduler>();
sched.schedule_task(recvr);
}
Expand Down Expand Up @@ -554,6 +555,8 @@ mod test {
{ let _c = chan; }
port.recv();
};
// What is our res?
rtdebug!("res is: %?", res.is_err());
assert!(res.is_err());
}
}
Expand Down Expand Up @@ -905,4 +908,5 @@ mod test {
}
}
}

}
1 change: 1 addition & 0 deletions src/libstd/rt/join_latch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,4 @@ mod test {
}
}
}

9 changes: 7 additions & 2 deletions src/libstd/rt/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rt::sched::Scheduler;
use rt::task::Task;
use rt::local_ptr;
use rt::rtio::{EventLoop, IoFactoryObject};
//use borrow::to_uint;

pub trait Local {
fn put(value: ~Self);
Expand All @@ -32,6 +33,7 @@ impl Local for Scheduler {
let res_ptr: *mut Option<T> = &mut res;
unsafe {
do local_ptr::borrow |sched| {
// rtdebug!("successfully unsafe borrowed sched pointer");
let result = f(sched);
*res_ptr = Some(result);
}
Expand All @@ -51,9 +53,12 @@ impl Local for Task {
fn exists() -> bool { rtabort!("unimpl") }
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
do Local::borrow::<Scheduler, T> |sched| {
// rtdebug!("sched about to grab current_task");
match sched.current_task {
Some(~ref mut task) => {
f(&mut *task.task)
// rtdebug!("current task pointer: %x", to_uint(task));
// rtdebug!("current task heap pointer: %x", to_uint(&task.heap));
f(task)
}
None => {
rtabort!("no scheduler")
Expand All @@ -64,7 +69,7 @@ impl Local for Task {
unsafe fn unsafe_borrow() -> *mut Task {
match (*Local::unsafe_borrow::<Scheduler>()).current_task {
Some(~ref mut task) => {
let s: *mut Task = &mut *task.task;
let s: *mut Task = &mut *task;
return s;
}
None => {
Expand Down
14 changes: 7 additions & 7 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use iter::Times;
use iterator::IteratorUtil;
use option::Some;
use ptr::RawPtr;
use rt::sched::{Scheduler, Coroutine, Shutdown};
use rt::sched::{Scheduler, Shutdown};
use rt::sleeper_list::SleeperList;
use rt::task::Task;
use rt::thread::Thread;
Expand Down Expand Up @@ -267,10 +267,10 @@ pub fn run(main: ~fn()) -> int {
};

// Create and enqueue the main task.
let mut new_task = ~Task::new_root();
new_task.on_exit = Some(on_exit);
let main_task = ~Coroutine::with_task(&mut scheds[0].stack_pool,
new_task, main);
let main_cell = Cell::new(main);
let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool,
main_cell.take());
main_task.on_exit = Some(on_exit);
scheds[0].enqueue_task(main_task);

// Run each scheduler in a thread.
Expand Down Expand Up @@ -347,15 +347,15 @@ pub fn context() -> RuntimeContext {
#[test]
fn test_context() {
use unstable::run_in_bare_thread;
use self::sched::{Scheduler, Coroutine};
use self::sched::{Scheduler};
use rt::local::Local;
use rt::test::new_test_uv_sched;

assert_eq!(context(), OldTaskContext);
do run_in_bare_thread {
assert_eq!(context(), GlobalContext);
let mut sched = ~new_test_uv_sched();
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
let task = ~do Task::new_root(&mut sched.stack_pool) {
assert_eq!(context(), TaskContext);
let sched = Local::take::<Scheduler>();
do sched.deschedule_running_task_and_then() |sched, task| {
Expand Down
Loading

0 comments on commit 75a913f

Please sign in to comment.