From 18de0f2aeb16439cfb220e344c15d88b0f41c82d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 2 Feb 2012 15:48:08 -0800 Subject: [PATCH] rt: Rename task_sleep intrinsic to task_yield. Remove usec param --- src/libcore/task.rs | 36 ++++++----------------- src/rt/intrinsics/intrinsics.cpp | 7 ++--- src/rt/intrinsics/intrinsics.i386.ll.in | 9 +++--- src/rt/intrinsics/intrinsics.x86_64.ll.in | 9 +++--- src/rt/rust_builtin.cpp | 4 +-- src/rt/rust_task.cpp | 2 +- src/rt/rust_task.h | 4 +-- src/rt/rustrt.def.in | 2 +- src/test/run-pass/task-comm-12.rs | 6 +++- 9 files changed, 31 insertions(+), 48 deletions(-) diff --git a/src/libcore/task.rs b/src/libcore/task.rs index bd2c7b369cf..6026d1b8125 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -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(+f: fn~() -> T) -> result::t { #[cfg(test)] mod tests { - #[test] - fn test_sleep() { sleep(1000000u); } - // FIXME: Leaks on windows #[test] #[ignore(cfg(target_os = "win32"))] diff --git a/src/rt/intrinsics/intrinsics.cpp b/src/rt/intrinsics/intrinsics.cpp index 8a99e6a4946..b5f7a2a07ec 100644 --- a/src/rt/intrinsics/intrinsics.cpp +++ b/src/rt/intrinsics/intrinsics.cpp @@ -10,7 +10,7 @@ #include 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); } diff --git a/src/rt/intrinsics/intrinsics.i386.ll.in b/src/rt/intrinsics/intrinsics.i386.ll.in index 8de1682732d..ca67bf91d89 100644 --- a/src/rt/intrinsics/intrinsics.i386.ll.in +++ b/src/rt/intrinsics/intrinsics.i386.ll.in @@ -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::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::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} diff --git a/src/rt/intrinsics/intrinsics.x86_64.ll.in b/src/rt/intrinsics/intrinsics.x86_64.ll.in index 55040a65959..ac96036a3e0 100644 --- a/src/rt/intrinsics/intrinsics.x86_64.ll.in +++ b/src/rt/intrinsics/intrinsics.x86_64.ll.in @@ -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::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::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} diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index c4c9927b3f7..140c4f1ae84 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -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 diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 017de8dca1b..faeae72f9db 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -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; } diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 63145153865..e150135b8d0 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -159,8 +159,8 @@ rust_task : public kernel_owned, 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(); diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 3701f73b0a8..87f6285fdfc 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -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 diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs index f92585cd254..beaa93c02e0 100644 --- a/src/test/run-pass/task-comm-12.rs +++ b/src/test/run-pass/task-comm-12.rs @@ -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);