2012-02-07 19:43:54 -06:00
|
|
|
// Tests of the runtime's scheduler interface
|
|
|
|
|
2012-09-05 14:32:05 -05:00
|
|
|
use ptr::is_null;
|
2012-06-28 18:46:34 -05:00
|
|
|
|
2012-02-07 19:43:54 -06:00
|
|
|
type sched_id = int;
|
2012-06-28 18:46:34 -05:00
|
|
|
type task_id = *libc::c_void;
|
2012-02-07 19:43:54 -06:00
|
|
|
|
2012-03-12 22:04:27 -05:00
|
|
|
type task = *libc::c_void;
|
|
|
|
type closure = *libc::c_void;
|
2012-02-07 19:43:54 -06:00
|
|
|
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rustrt {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
2012-06-28 18:46:34 -05:00
|
|
|
fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id;
|
2012-02-07 19:43:54 -06:00
|
|
|
fn rust_get_sched_id() -> sched_id;
|
|
|
|
fn rust_new_task_in_sched(id: sched_id) -> task_id;
|
|
|
|
fn start_task(id: task_id, f: closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() unsafe {
|
2012-08-27 16:22:25 -05:00
|
|
|
let po = comm::Port();
|
|
|
|
let ch = comm::Chan(po);
|
2012-02-07 19:43:54 -06:00
|
|
|
let parent_sched_id = rustrt::rust_get_sched_id();
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("parent %?", parent_sched_id);
|
2012-02-07 19:43:54 -06:00
|
|
|
let num_threads = 1u;
|
|
|
|
let new_sched_id = rustrt::rust_new_sched(num_threads);
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("new_sched_id %?", new_sched_id);
|
2012-02-07 19:43:54 -06:00
|
|
|
let new_task_id = rustrt::rust_new_task_in_sched(new_sched_id);
|
2012-06-28 18:01:55 -05:00
|
|
|
assert !new_task_id.is_null();
|
2012-02-07 19:43:54 -06:00
|
|
|
let f = fn~() {
|
|
|
|
let child_sched_id = rustrt::rust_get_sched_id();
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("child_sched_id %?", child_sched_id);
|
2012-02-07 19:43:54 -06:00
|
|
|
assert child_sched_id != parent_sched_id;
|
|
|
|
assert child_sched_id == new_sched_id;
|
|
|
|
comm::send(ch, ());
|
|
|
|
};
|
2012-10-01 14:47:02 -05:00
|
|
|
let fptr = cast::reinterpret_cast(&ptr::addr_of(&f));
|
2012-02-07 19:43:54 -06:00
|
|
|
rustrt::start_task(new_task_id, fptr);
|
2012-09-18 19:34:08 -05:00
|
|
|
cast::forget(f);
|
2012-02-07 19:43:54 -06:00
|
|
|
comm::recv(po);
|
2012-06-28 18:01:55 -05:00
|
|
|
}
|