rust/src/lib/task.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

native "rust" mod rustrt {
2011-07-27 07:19:39 -05:00
fn task_sleep(time_in_us: uint);
fn task_yield();
2011-07-27 07:19:39 -05:00
fn task_join(t: task) -> int;
fn unsupervise();
fn pin_task();
fn unpin_task();
2011-07-27 07:19:39 -05:00
fn clone_chan(c: *rust_chan) -> *rust_chan;
type rust_chan;
fn set_min_stack(stack_size: uint);
}
/**
* Hints the scheduler to yield this task for a specified ammount of time.
*
* arg: time_in_us maximum number of microseconds to yield control for
*/
2011-07-27 07:19:39 -05:00
fn sleep(time_in_us: uint) { ret rustrt::task_sleep(time_in_us); }
2011-07-27 07:19:39 -05:00
fn yield() { ret rustrt::task_yield(); }
2011-07-27 07:19:39 -05:00
tag task_result { tr_success; tr_failure; }
2011-07-27 07:19:39 -05:00
fn join(t: task) -> task_result {
alt rustrt::task_join(t) { 0 { tr_success } _ { tr_failure } }
}
2011-07-27 07:19:39 -05:00
fn unsupervise() { ret rustrt::unsupervise(); }
2011-07-27 07:19:39 -05:00
fn pin() { rustrt::pin_task(); }
2011-07-27 07:19:39 -05:00
fn unpin() { rustrt::unpin_task(); }
2011-07-27 07:19:39 -05:00
fn clone_chan[T](c: chan[T]) -> chan[T] {
let cloned = rustrt::clone_chan(unsafe::reinterpret_cast(c));
ret unsafe::reinterpret_cast(cloned);
}
2011-07-27 07:19:39 -05:00
fn send[T](c: chan[T], v: &T) { c <| v; }
2011-07-24 00:41:28 -05:00
2011-07-27 07:19:39 -05:00
fn recv[T](p: port[T]) -> T { let v; p |> v; v }
2011-07-24 00:41:28 -05:00
2011-07-28 12:41:48 -05:00
fn set_min_stack(stack_size : uint) {
rustrt::set_min_stack(stack_size);
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End: