rt: Rename task_sleep intrinsic to task_yield. Remove usec param
This commit is contained in:
parent
8693fcc2d7
commit
18de0f2aeb
@ -33,7 +33,6 @@ import c = ctypes;
|
||||
|
||||
export task;
|
||||
export joinable_task;
|
||||
export sleep;
|
||||
export yield;
|
||||
export task_notification;
|
||||
export join;
|
||||
@ -55,7 +54,7 @@ export try;
|
||||
#[abi = "rust-intrinsic"]
|
||||
native mod rusti {
|
||||
// these must run on the Rust stack so that they can swap stacks etc:
|
||||
fn task_sleep(task: *rust_task, time_in_us: c::size_t, &killed: bool);
|
||||
fn task_yield(task: *rust_task, &killed: bool);
|
||||
}
|
||||
|
||||
type rust_closure = {
|
||||
@ -257,27 +256,6 @@ Retreives a handle to the currently executing task
|
||||
*/
|
||||
fn get_task() -> task { rustrt::get_task_id() }
|
||||
|
||||
/*
|
||||
Function: sleep
|
||||
|
||||
Hints the scheduler to yield this task for a specified ammount of time.
|
||||
|
||||
Parameters:
|
||||
|
||||
time_in_us - maximum number of microseconds to yield control for
|
||||
*/
|
||||
fn sleep(time_in_us: uint) {
|
||||
let task = rustrt::rust_get_task();
|
||||
let killed = false;
|
||||
// FIXME: uncomment this when extfmt is moved to core
|
||||
// in a snapshot.
|
||||
// #debug("yielding for %u us", time_in_us);
|
||||
rusti::task_sleep(task, time_in_us, killed);
|
||||
if killed && !currently_unwinding() {
|
||||
fail "killed";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: yield
|
||||
|
||||
@ -285,7 +263,14 @@ Yield control to the task scheduler
|
||||
|
||||
The scheduler may schedule another task to execute.
|
||||
*/
|
||||
fn yield() { sleep(1u) }
|
||||
fn yield() {
|
||||
let task = rustrt::rust_get_task();
|
||||
let killed = false;
|
||||
rusti::task_yield(task, killed);
|
||||
if killed && !currently_unwinding() {
|
||||
fail "killed";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: join
|
||||
@ -374,9 +359,6 @@ fn try<T:send>(+f: fn~() -> T) -> result::t<T,()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_sleep() { sleep(1000000u); }
|
||||
|
||||
// FIXME: Leaks on windows
|
||||
#[test]
|
||||
#[ignore(cfg(target_os = "win32"))]
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <cstring>
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_task_sleep(rust_task *task, size_t time_in_us, bool *killed);
|
||||
rust_task_yield(rust_task *task, bool *killed);
|
||||
|
||||
extern "C" void
|
||||
rust_intrinsic_vec_len(size_t *retptr,
|
||||
@ -77,11 +77,10 @@ rust_intrinsic_get_type_desc(void **retptr,
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
rust_intrinsic_task_sleep(void **retptr,
|
||||
rust_intrinsic_task_yield(void **retptr,
|
||||
void *env,
|
||||
rust_task *task,
|
||||
size_t time_in_us,
|
||||
bool *killed) {
|
||||
rust_task_sleep(task, time_in_us, killed);
|
||||
rust_task_yield(task, killed);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ target triple = "@CFG_TARGET_TRIPLE@"
|
||||
%struct.rust_vec = type { i32, i32, [0 x i8] }
|
||||
%struct.rust_fn = type { i32*, %struct.rust_box* }
|
||||
%struct.rust_box = type opaque
|
||||
%struct.rust_task = type { %struct.rust_task_user, i32, [8 x i8], %class.context, %struct.stk_seg*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, %class.timer, i32*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i32, [8 x i8] }
|
||||
%struct.rust_task = type { %struct.rust_task_user, i32, [8 x i8], %class.context, %struct.stk_seg*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i32, [12 x i8] }
|
||||
%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 }
|
||||
%struct.chan_handle = type { i32, i32 }
|
||||
%class.context = type { %struct.registers_t, %class.context*, [12 x i8] }
|
||||
@ -42,7 +42,6 @@ target triple = "@CFG_TARGET_TRIPLE@"
|
||||
%"struct.hash_map<int, rust_task *>::map_entry" = type opaque
|
||||
%union.pthread_attr_t = type { i32, [32 x i8] }
|
||||
%struct.rust_cond = type { i8 }
|
||||
%class.timer = type { i32 (...)**, i64, i64 }
|
||||
%class.boxed_region = type { %class.memory_region*, %struct.rust_opaque_box* }
|
||||
%struct.rust_opaque_box = type { i32, %struct.type_desc*, %struct.rust_opaque_box*, %struct.rust_opaque_box* }
|
||||
%class.hash_map.4 = type { %"struct.hash_map<int, rust_port *>::map_entry"* }
|
||||
@ -113,13 +112,13 @@ entry:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @rust_intrinsic_task_sleep(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i32 %time_in_us, i8* %killed) {
|
||||
define void @rust_intrinsic_task_yield(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i8* %killed) {
|
||||
entry:
|
||||
tail call void @rust_task_sleep(%struct.rust_task* %task, i32 %time_in_us, i8* %killed)
|
||||
tail call void @rust_task_yield(%struct.rust_task* %task, i8* %killed)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @rust_task_sleep(%struct.rust_task*, i32, i8*)
|
||||
declare void @rust_task_yield(%struct.rust_task*, i8*)
|
||||
|
||||
!0 = metadata !{metadata !"any pointer", metadata !1}
|
||||
!1 = metadata !{metadata !"omnipotent char", metadata !2}
|
||||
|
@ -10,7 +10,7 @@ target triple = "@CFG_TARGET_TRIPLE@"
|
||||
%struct.rust_vec = type { i64, i64, [0 x i8] }
|
||||
%struct.rust_fn = type { i64*, %struct.rust_box* }
|
||||
%struct.rust_box = type opaque
|
||||
%struct.rust_task = type { %struct.rust_task_user, i64, %class.context, %struct.stk_seg*, i64, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i64, %class.timer, i64*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i64, [8 x i8] }
|
||||
%struct.rust_task = type { %struct.rust_task_user, i64, %class.context, %struct.stk_seg*, i64, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i64, i64*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i64 }
|
||||
%struct.rust_task_user = type { i64, i64, %struct.chan_handle, i64 }
|
||||
%struct.chan_handle = type { i64, i64 }
|
||||
%class.context = type { %struct.registers_t, %class.context*, [8 x i8] }
|
||||
@ -42,7 +42,6 @@ target triple = "@CFG_TARGET_TRIPLE@"
|
||||
%"struct.hash_map<long, rust_task *>::map_entry" = type opaque
|
||||
%union.pthread_attr_t = type { i64, [48 x i8] }
|
||||
%struct.rust_cond = type { i8 }
|
||||
%class.timer = type { i32 (...)**, i64, i64 }
|
||||
%class.boxed_region = type { %class.memory_region*, %struct.rust_opaque_box* }
|
||||
%struct.rust_opaque_box = type { i64, %struct.type_desc*, %struct.rust_opaque_box*, %struct.rust_opaque_box* }
|
||||
%class.hash_map.4 = type { %"struct.hash_map<long, rust_port *>::map_entry"* }
|
||||
@ -113,13 +112,13 @@ entry:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @rust_intrinsic_task_sleep(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i64 %time_in_us, i8* %killed) uwtable {
|
||||
define void @rust_intrinsic_task_yield(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i8* %killed) uwtable {
|
||||
entry:
|
||||
tail call void @rust_task_sleep(%struct.rust_task* %task, i64 %time_in_us, i8* %killed)
|
||||
tail call void @rust_task_yield(%struct.rust_task* %task, i8* %killed)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @rust_task_sleep(%struct.rust_task*, i64, i8*)
|
||||
declare void @rust_task_yield(%struct.rust_task*, i8*)
|
||||
|
||||
!0 = metadata !{metadata !"any pointer", metadata !1}
|
||||
!1 = metadata !{metadata !"omnipotent char", metadata !2}
|
||||
|
@ -499,8 +499,8 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
|
||||
// This is called by an intrinsic on the Rust stack and must run
|
||||
// entirely in the red zone. Do not call on the C stack.
|
||||
extern "C" CDECL void
|
||||
rust_task_sleep(rust_task *task, size_t time_in_us, bool *killed) {
|
||||
task->yield(time_in_us, killed);
|
||||
rust_task_yield(rust_task *task, bool *killed) {
|
||||
task->yield(killed);
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
|
@ -401,7 +401,7 @@ void rust_task::start()
|
||||
|
||||
// Only run this on the rust stack
|
||||
void
|
||||
rust_task::yield(size_t time_in_us, bool *killed) {
|
||||
rust_task::yield(bool *killed) {
|
||||
if (this->killed) {
|
||||
*killed = true;
|
||||
}
|
||||
|
@ -159,8 +159,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||
// Print a backtrace, if the "bt" logging option is on.
|
||||
void backtrace();
|
||||
|
||||
// Yields for a specified duration of time.
|
||||
void yield(size_t time_in_ms, bool *killed);
|
||||
// Yields control to the scheduler. Called from the Rust stack
|
||||
void yield(bool *killed);
|
||||
|
||||
// Fail this task (assuming caller-on-stack is different task).
|
||||
void kill();
|
||||
|
@ -45,8 +45,8 @@ rust_run_program
|
||||
rust_set_exit_status
|
||||
rust_start
|
||||
rust_getcwd
|
||||
rust_task_yield
|
||||
rust_task_is_unwinding
|
||||
rust_task_sleep
|
||||
rust_get_task
|
||||
sched_threads
|
||||
shape_log_str
|
||||
|
@ -10,7 +10,11 @@ fn test00() {
|
||||
let t = task::spawn_joinable {|| start(i); };
|
||||
|
||||
// Sleep long enough for the task to finish.
|
||||
task::sleep(10000u);
|
||||
let i = 0;
|
||||
while i < 10000 {
|
||||
task::yield();
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// Try joining tasks that have already finished.
|
||||
task::join(t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user