Skip to content

Commit 18de0f2

Browse files
committed
rt: Rename task_sleep intrinsic to task_yield. Remove usec param
1 parent 8693fcc commit 18de0f2

File tree

9 files changed

+28
-45
lines changed

9 files changed

+28
-45
lines changed

src/libcore/task.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import c = ctypes;
3333

3434
export task;
3535
export joinable_task;
36-
export sleep;
3736
export yield;
3837
export task_notification;
3938
export join;
@@ -55,7 +54,7 @@ export try;
5554
#[abi = "rust-intrinsic"]
5655
native mod rusti {
5756
// these must run on the Rust stack so that they can swap stacks etc:
58-
fn task_sleep(task: *rust_task, time_in_us: c::size_t, &killed: bool);
57+
fn task_yield(task: *rust_task, &killed: bool);
5958
}
6059

6160
type rust_closure = {
@@ -258,35 +257,21 @@ Retreives a handle to the currently executing task
258257
fn get_task() -> task { rustrt::get_task_id() }
259258

260259
/*
261-
Function: sleep
262-
263-
Hints the scheduler to yield this task for a specified ammount of time.
260+
Function: yield
264261
265-
Parameters:
262+
Yield control to the task scheduler
266263
267-
time_in_us - maximum number of microseconds to yield control for
264+
The scheduler may schedule another task to execute.
268265
*/
269-
fn sleep(time_in_us: uint) {
266+
fn yield() {
270267
let task = rustrt::rust_get_task();
271268
let killed = false;
272-
// FIXME: uncomment this when extfmt is moved to core
273-
// in a snapshot.
274-
// #debug("yielding for %u us", time_in_us);
275-
rusti::task_sleep(task, time_in_us, killed);
269+
rusti::task_yield(task, killed);
276270
if killed && !currently_unwinding() {
277271
fail "killed";
278272
}
279273
}
280274

281-
/*
282-
Function: yield
283-
284-
Yield control to the task scheduler
285-
286-
The scheduler may schedule another task to execute.
287-
*/
288-
fn yield() { sleep(1u) }
289-
290275
/*
291276
Function: join
292277
@@ -374,9 +359,6 @@ fn try<T:send>(+f: fn~() -> T) -> result::t<T,()> {
374359

375360
#[cfg(test)]
376361
mod tests {
377-
#[test]
378-
fn test_sleep() { sleep(1000000u); }
379-
380362
// FIXME: Leaks on windows
381363
#[test]
382364
#[ignore(cfg(target_os = "win32"))]

src/rt/intrinsics/intrinsics.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <cstring>
1111

1212
extern "C" CDECL void
13-
rust_task_sleep(rust_task *task, size_t time_in_us, bool *killed);
13+
rust_task_yield(rust_task *task, bool *killed);
1414

1515
extern "C" void
1616
rust_intrinsic_vec_len(size_t *retptr,
@@ -77,11 +77,10 @@ rust_intrinsic_get_type_desc(void **retptr,
7777
}
7878

7979
extern "C" void
80-
rust_intrinsic_task_sleep(void **retptr,
80+
rust_intrinsic_task_yield(void **retptr,
8181
void *env,
8282
rust_task *task,
83-
size_t time_in_us,
8483
bool *killed) {
85-
rust_task_sleep(task, time_in_us, killed);
84+
rust_task_yield(task, killed);
8685
}
8786

src/rt/intrinsics/intrinsics.i386.ll.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ target triple = "@CFG_TARGET_TRIPLE@"
1010
%struct.rust_vec = type { i32, i32, [0 x i8] }
1111
%struct.rust_fn = type { i32*, %struct.rust_box* }
1212
%struct.rust_box = type opaque
13-
%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] }
13+
%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] }
1414
%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 }
1515
%struct.chan_handle = type { i32, i32 }
1616
%class.context = type { %struct.registers_t, %class.context*, [12 x i8] }
@@ -42,7 +42,6 @@ target triple = "@CFG_TARGET_TRIPLE@"
4242
%"struct.hash_map<int, rust_task *>::map_entry" = type opaque
4343
%union.pthread_attr_t = type { i32, [32 x i8] }
4444
%struct.rust_cond = type { i8 }
45-
%class.timer = type { i32 (...)**, i64, i64 }
4645
%class.boxed_region = type { %class.memory_region*, %struct.rust_opaque_box* }
4746
%struct.rust_opaque_box = type { i32, %struct.type_desc*, %struct.rust_opaque_box*, %struct.rust_opaque_box* }
4847
%class.hash_map.4 = type { %"struct.hash_map<int, rust_port *>::map_entry"* }
@@ -113,13 +112,13 @@ entry:
113112
ret void
114113
}
115114

116-
define void @rust_intrinsic_task_sleep(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i32 %time_in_us, i8* %killed) {
115+
define void @rust_intrinsic_task_yield(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i8* %killed) {
117116
entry:
118-
tail call void @rust_task_sleep(%struct.rust_task* %task, i32 %time_in_us, i8* %killed)
117+
tail call void @rust_task_yield(%struct.rust_task* %task, i8* %killed)
119118
ret void
120119
}
121120

122-
declare void @rust_task_sleep(%struct.rust_task*, i32, i8*)
121+
declare void @rust_task_yield(%struct.rust_task*, i8*)
123122

124123
!0 = metadata !{metadata !"any pointer", metadata !1}
125124
!1 = metadata !{metadata !"omnipotent char", metadata !2}

src/rt/intrinsics/intrinsics.x86_64.ll.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ target triple = "@CFG_TARGET_TRIPLE@"
1010
%struct.rust_vec = type { i64, i64, [0 x i8] }
1111
%struct.rust_fn = type { i64*, %struct.rust_box* }
1212
%struct.rust_box = type opaque
13-
%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] }
13+
%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 }
1414
%struct.rust_task_user = type { i64, i64, %struct.chan_handle, i64 }
1515
%struct.chan_handle = type { i64, i64 }
1616
%class.context = type { %struct.registers_t, %class.context*, [8 x i8] }
@@ -42,7 +42,6 @@ target triple = "@CFG_TARGET_TRIPLE@"
4242
%"struct.hash_map<long, rust_task *>::map_entry" = type opaque
4343
%union.pthread_attr_t = type { i64, [48 x i8] }
4444
%struct.rust_cond = type { i8 }
45-
%class.timer = type { i32 (...)**, i64, i64 }
4645
%class.boxed_region = type { %class.memory_region*, %struct.rust_opaque_box* }
4746
%struct.rust_opaque_box = type { i64, %struct.type_desc*, %struct.rust_opaque_box*, %struct.rust_opaque_box* }
4847
%class.hash_map.4 = type { %"struct.hash_map<long, rust_port *>::map_entry"* }
@@ -113,13 +112,13 @@ entry:
113112
ret void
114113
}
115114

116-
define void @rust_intrinsic_task_sleep(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i64 %time_in_us, i8* %killed) uwtable {
115+
define void @rust_intrinsic_task_yield(i8** nocapture %retptr, i8* nocapture %env, %struct.rust_task* %task, i8* %killed) uwtable {
117116
entry:
118-
tail call void @rust_task_sleep(%struct.rust_task* %task, i64 %time_in_us, i8* %killed)
117+
tail call void @rust_task_yield(%struct.rust_task* %task, i8* %killed)
119118
ret void
120119
}
121120

122-
declare void @rust_task_sleep(%struct.rust_task*, i64, i8*)
121+
declare void @rust_task_yield(%struct.rust_task*, i8*)
123122

124123
!0 = metadata !{metadata !"any pointer", metadata !1}
125124
!1 = metadata !{metadata !"omnipotent char", metadata !2}

src/rt/rust_builtin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
499499
// This is called by an intrinsic on the Rust stack and must run
500500
// entirely in the red zone. Do not call on the C stack.
501501
extern "C" CDECL void
502-
rust_task_sleep(rust_task *task, size_t time_in_us, bool *killed) {
503-
task->yield(time_in_us, killed);
502+
rust_task_yield(rust_task *task, bool *killed) {
503+
task->yield(killed);
504504
}
505505

506506
extern "C" CDECL void

src/rt/rust_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void rust_task::start()
401401

402402
// Only run this on the rust stack
403403
void
404-
rust_task::yield(size_t time_in_us, bool *killed) {
404+
rust_task::yield(bool *killed) {
405405
if (this->killed) {
406406
*killed = true;
407407
}

src/rt/rust_task.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
159159
// Print a backtrace, if the "bt" logging option is on.
160160
void backtrace();
161161

162-
// Yields for a specified duration of time.
163-
void yield(size_t time_in_ms, bool *killed);
162+
// Yields control to the scheduler. Called from the Rust stack
163+
void yield(bool *killed);
164164

165165
// Fail this task (assuming caller-on-stack is different task).
166166
void kill();

src/rt/rustrt.def.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ rust_run_program
4545
rust_set_exit_status
4646
rust_start
4747
rust_getcwd
48+
rust_task_yield
4849
rust_task_is_unwinding
49-
rust_task_sleep
5050
rust_get_task
5151
sched_threads
5252
shape_log_str

src/test/run-pass/task-comm-12.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ fn test00() {
1010
let t = task::spawn_joinable {|| start(i); };
1111

1212
// Sleep long enough for the task to finish.
13-
task::sleep(10000u);
13+
let i = 0;
14+
while i < 10000 {
15+
task::yield();
16+
i += 1;
17+
}
1418

1519
// Try joining tasks that have already finished.
1620
task::join(t);

0 commit comments

Comments
 (0)