Skip to content

Commit e838edc

Browse files
nikomatsakisbrson
authored andcommitted
isolate those funcs in task that can run on the c stack
1 parent fb48817 commit e838edc

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/lib/task.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,25 @@ export spawn;
2222
export spawn_notify;
2323
export spawn_joinable;
2424

25-
native "rust" mod rustrt {
26-
fn task_sleep(time_in_us: uint);
27-
fn task_yield();
28-
fn task_join(t: task_id) -> int;
29-
fn pin_task();
30-
fn unpin_task();
31-
fn get_task_id() -> task_id;
25+
native "rust" mod rustrt { // C Stack?
26+
fn task_sleep(time_in_us: uint); // No
27+
fn task_yield(); // No
28+
fn start_task(id: task_id, closure: *u8); // No
29+
fn task_join(t: task_id) -> int; // Refactor
30+
}
3231

33-
type rust_chan;
32+
native "c-stack-cdecl" mod rustrt2 = "rustrt" {
33+
fn pin_task(); // Yes
34+
fn unpin_task(); // Yes
35+
fn get_task_id() -> task_id; // Yes
3436

35-
fn set_min_stack(stack_size: uint);
37+
fn set_min_stack(stack_size: uint); // Yes
3638

3739
fn new_task() -> task_id;
3840
fn drop_task(task: *rust_task);
3941
fn get_task_pointer(id: task_id) -> *rust_task;
4042

41-
fn migrate_alloc(alloc: *u8, target: task_id);
42-
fn start_task(id: task_id, closure: *u8);
43+
fn migrate_alloc(alloc: *u8, target: task_id); // Yes
4344
}
4445

4546
type rust_task =
@@ -48,13 +49,13 @@ type rust_task =
4849
mutable notify_chan: comm::chan<task_notification>,
4950
mutable stack_ptr: *u8};
5051

51-
resource rust_task_ptr(task: *rust_task) { rustrt::drop_task(task); }
52+
resource rust_task_ptr(task: *rust_task) { rustrt2::drop_task(task); }
5253

5354
type task = int;
5455
type task_id = task;
5556
type joinable_task = (task_id, comm::port<task_notification>);
5657

57-
fn get_task_id() -> task_id { rustrt::get_task_id() }
58+
fn get_task_id() -> task_id { rustrt2::get_task_id() }
5859

5960
/**
6061
* Hints the scheduler to yield this task for a specified ammount of time.
@@ -86,11 +87,11 @@ fn join_id(t: task_id) -> task_result {
8687

8788
fn unsupervise() { ret sys::unsupervise(); }
8889

89-
fn pin() { rustrt::pin_task(); }
90+
fn pin() { rustrt2::pin_task(); }
9091

91-
fn unpin() { rustrt::unpin_task(); }
92+
fn unpin() { rustrt2::unpin_task(); }
9293

93-
fn set_min_stack(stack_size: uint) { rustrt::set_min_stack(stack_size); }
94+
fn set_min_stack(stack_size: uint) { rustrt2::set_min_stack(stack_size); }
9495

9596
fn spawn<~T>(-data: T, f: fn(T)) -> task {
9697
spawn_inner2(data, f, none)
@@ -138,12 +139,12 @@ fn spawn_inner2<~T>(-data: T, f: fn(T),
138139
fn unsafe_spawn_inner(-thunk: fn@(),
139140
notify: option<comm::chan<task_notification>>) ->
140141
task_id unsafe {
141-
let id = rustrt::new_task();
142+
let id = rustrt2::new_task();
142143

143144
let raw_thunk: {code: u32, env: u32} = cast(thunk);
144145

145146
// set up the task pointer
146-
let task_ptr <- rust_task_ptr(rustrt::get_task_pointer(id));
147+
let task_ptr <- rust_task_ptr(rustrt2::get_task_pointer(id));
147148

148149
assert (ptr::null() != (**task_ptr).stack_ptr);
149150

@@ -167,7 +168,7 @@ fn unsafe_spawn_inner(-thunk: fn@(),
167168
}
168169

169170
// give the thunk environment's allocation to the new task
170-
rustrt::migrate_alloc(cast(raw_thunk.env), id);
171+
rustrt2::migrate_alloc(cast(raw_thunk.env), id);
171172
rustrt::start_task(id, cast(thunkfn));
172173
// don't cleanup the thunk in this task
173174
unsafe::leak(thunk);

0 commit comments

Comments
 (0)