Skip to content

Commit 390dde5

Browse files
committed
core::rt: Rename Task to Coroutine
1 parent 7f5746f commit 390dde5

File tree

5 files changed

+58
-58
lines changed

5 files changed

+58
-58
lines changed

src/libcore/rt/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use ptr::Ptr;
6767
/// The global (exchange) heap.
6868
pub mod global_heap;
6969

70-
/// The Scheduler and Task types.
70+
/// The Scheduler and Coroutine types.
7171
mod sched;
7272

7373
/// Thread-local access to the current Scheduler.
@@ -138,14 +138,14 @@ pub mod tube;
138138
/// The return value is used as the process return code. 0 on success, 101 on error.
139139
pub fn start(_argc: int, _argv: **u8, crate_map: *u8, main: ~fn()) -> int {
140140

141-
use self::sched::{Scheduler, Task};
141+
use self::sched::{Scheduler, Coroutine};
142142
use self::uv::uvio::UvEventLoop;
143143

144144
init(crate_map);
145145

146146
let loop_ = ~UvEventLoop::new();
147147
let mut sched = ~Scheduler::new(loop_);
148-
let main_task = ~Task::new(&mut sched.stack_pool, main);
148+
let main_task = ~Coroutine::new(&mut sched.stack_pool, main);
149149

150150
sched.enqueue_task(main_task);
151151
sched.run();
@@ -210,15 +210,15 @@ pub fn context() -> RuntimeContext {
210210
#[test]
211211
fn test_context() {
212212
use unstable::run_in_bare_thread;
213-
use self::sched::{local_sched, Task};
213+
use self::sched::{local_sched, Coroutine};
214214
use rt::uv::uvio::UvEventLoop;
215215
use cell::Cell;
216216

217217
assert!(context() == OldTaskContext);
218218
do run_in_bare_thread {
219219
assert!(context() == GlobalContext);
220220
let mut sched = ~UvEventLoop::new_scheduler();
221-
let task = ~do Task::new(&mut sched.stack_pool) {
221+
let task = ~do Coroutine::new(&mut sched.stack_pool) {
222222
assert!(context() == TaskContext);
223223
let sched = local_sched::take();
224224
do sched.deschedule_running_task_and_then() |task| {

src/libcore/rt/sched.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ use cell::Cell;
2626
// A more convenient name for external callers, e.g. `local_sched::take()`
2727
pub mod local_sched;
2828

29-
/// The Scheduler is responsible for coordinating execution of Tasks
29+
/// The Scheduler is responsible for coordinating execution of Coroutines
3030
/// on a single thread. When the scheduler is running it is owned by
3131
/// thread local storage and the running task is owned by the
3232
/// scheduler.
3333
pub struct Scheduler {
34-
priv work_queue: WorkQueue<~Task>,
34+
priv work_queue: WorkQueue<~Coroutine>,
3535
stack_pool: StackPool,
3636
/// The event loop used to drive the scheduler and perform I/O
3737
event_loop: ~EventLoopObject,
3838
/// The scheduler's saved context.
3939
/// Always valid when a task is executing, otherwise not
4040
priv saved_context: Context,
4141
/// The currently executing task
42-
current_task: Option<~Task>,
42+
current_task: Option<~Coroutine>,
4343
/// An action performed after a context switch on behalf of the
4444
/// code running before the context switch
4545
priv cleanup_job: Option<CleanupJob>
@@ -49,17 +49,17 @@ pub struct Scheduler {
4949
// complaining
5050
type UnsafeTaskReceiver = sys::Closure;
5151
trait ClosureConverter {
52-
fn from_fn(&fn(~Task)) -> Self;
53-
fn to_fn(self) -> &fn(~Task);
52+
fn from_fn(&fn(~Coroutine)) -> Self;
53+
fn to_fn(self) -> &fn(~Coroutine);
5454
}
5555
impl ClosureConverter for UnsafeTaskReceiver {
56-
fn from_fn(f: &fn(~Task)) -> UnsafeTaskReceiver { unsafe { transmute(f) } }
57-
fn to_fn(self) -> &fn(~Task) { unsafe { transmute(self) } }
56+
fn from_fn(f: &fn(~Coroutine)) -> UnsafeTaskReceiver { unsafe { transmute(f) } }
57+
fn to_fn(self) -> &fn(~Coroutine) { unsafe { transmute(self) } }
5858
}
5959

6060
enum CleanupJob {
6161
DoNothing,
62-
GiveTask(~Task, UnsafeTaskReceiver)
62+
GiveTask(~Coroutine, UnsafeTaskReceiver)
6363
}
6464

6565
pub impl Scheduler {
@@ -115,7 +115,7 @@ pub impl Scheduler {
115115
/// Pushes the task onto the work stealing queue and tells the event loop
116116
/// to run it later. Always use this instead of pushing to the work queue
117117
/// directly.
118-
fn enqueue_task(&mut self, task: ~Task) {
118+
fn enqueue_task(&mut self, task: ~Coroutine) {
119119
self.work_queue.push_front(task);
120120
self.event_loop.callback(resume_task_from_queue);
121121

@@ -164,7 +164,7 @@ pub impl Scheduler {
164164
abort!("control reached end of task");
165165
}
166166

167-
fn schedule_new_task(~self, task: ~Task) {
167+
fn schedule_new_task(~self, task: ~Coroutine) {
168168
assert!(self.in_task_context());
169169

170170
do self.switch_running_tasks_and_then(task) |last_task| {
@@ -177,7 +177,7 @@ pub impl Scheduler {
177177

178178
// Core scheduling ops
179179

180-
fn resume_task_immediately(~self, task: ~Task) {
180+
fn resume_task_immediately(~self, task: ~Coroutine) {
181181
let mut this = self;
182182
assert!(!this.in_task_context());
183183

@@ -215,15 +215,15 @@ pub impl Scheduler {
215215
/// The closure here is a *stack* closure that lives in the
216216
/// running task. It gets transmuted to the scheduler's lifetime
217217
/// and called while the task is blocked.
218-
fn deschedule_running_task_and_then(~self, f: &fn(~Task)) {
218+
fn deschedule_running_task_and_then(~self, f: &fn(~Coroutine)) {
219219
let mut this = self;
220220
assert!(this.in_task_context());
221221

222222
rtdebug!("blocking task");
223223

224224
unsafe {
225225
let blocked_task = this.current_task.swap_unwrap();
226-
let f_fake_region = transmute::<&fn(~Task), &fn(~Task)>(f);
226+
let f_fake_region = transmute::<&fn(~Coroutine), &fn(~Coroutine)>(f);
227227
let f_opaque = ClosureConverter::from_fn(f_fake_region);
228228
this.enqueue_cleanup_job(GiveTask(blocked_task, f_opaque));
229229
}
@@ -245,14 +245,14 @@ pub impl Scheduler {
245245
/// Switch directly to another task, without going through the scheduler.
246246
/// You would want to think hard about doing this, e.g. if there are
247247
/// pending I/O events it would be a bad idea.
248-
fn switch_running_tasks_and_then(~self, next_task: ~Task, f: &fn(~Task)) {
248+
fn switch_running_tasks_and_then(~self, next_task: ~Coroutine, f: &fn(~Coroutine)) {
249249
let mut this = self;
250250
assert!(this.in_task_context());
251251

252252
rtdebug!("switching tasks");
253253

254254
let old_running_task = this.current_task.swap_unwrap();
255-
let f_fake_region = unsafe { transmute::<&fn(~Task), &fn(~Task)>(f) };
255+
let f_fake_region = unsafe { transmute::<&fn(~Coroutine), &fn(~Coroutine)>(f) };
256256
let f_opaque = ClosureConverter::from_fn(f_fake_region);
257257
this.enqueue_cleanup_job(GiveTask(old_running_task, f_opaque));
258258
this.current_task = Some(next_task);
@@ -318,7 +318,7 @@ pub impl Scheduler {
318318
// because borrowck thinks the three patterns are conflicting
319319
// borrows
320320
unsafe {
321-
let last_task = transmute::<Option<&Task>, Option<&mut Task>>(last_task);
321+
let last_task = transmute::<Option<&Coroutine>, Option<&mut Coroutine>>(last_task);
322322
let last_task_context = match last_task {
323323
Some(t) => Some(&mut t.saved_context), None => None
324324
};
@@ -333,9 +333,9 @@ pub impl Scheduler {
333333
}
334334
}
335335

336-
static TASK_MIN_STACK_SIZE: uint = 10000000; // XXX: Too much stack
336+
static MIN_STACK_SIZE: uint = 10000000; // XXX: Too much stack
337337

338-
pub struct Task {
338+
pub struct Coroutine {
339339
/// The segment of stack on which the task is currently running or,
340340
/// if the task is blocked, on which the task will resume execution
341341
priv current_stack_segment: StackSegment,
@@ -346,19 +346,19 @@ pub struct Task {
346346
local_services: LocalServices
347347
}
348348

349-
pub impl Task {
350-
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Task {
351-
Task::with_local(stack_pool, LocalServices::new(), start)
349+
pub impl Coroutine {
350+
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
351+
Coroutine::with_local(stack_pool, LocalServices::new(), start)
352352
}
353353

354354
fn with_local(stack_pool: &mut StackPool,
355355
local_services: LocalServices,
356-
start: ~fn()) -> Task {
357-
let start = Task::build_start_wrapper(start);
358-
let mut stack = stack_pool.take_segment(TASK_MIN_STACK_SIZE);
356+
start: ~fn()) -> Coroutine {
357+
let start = Coroutine::build_start_wrapper(start);
358+
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
359359
// NB: Context holds a pointer to that ~fn
360360
let initial_context = Context::new(start, &mut stack);
361-
return Task {
361+
return Coroutine {
362362
current_stack_segment: stack,
363363
saved_context: initial_context,
364364
local_services: local_services
@@ -390,7 +390,7 @@ pub impl Task {
390390
/// Destroy the task and try to reuse its components
391391
fn recycle(~self, stack_pool: &mut StackPool) {
392392
match self {
393-
~Task {current_stack_segment, _} => {
393+
~Coroutine {current_stack_segment, _} => {
394394
stack_pool.give_segment(current_stack_segment);
395395
}
396396
}
@@ -414,7 +414,7 @@ mod test {
414414
let task_ran_ptr: *mut bool = &mut task_ran;
415415

416416
let mut sched = ~UvEventLoop::new_scheduler();
417-
let task = ~do Task::new(&mut sched.stack_pool) {
417+
let task = ~do Coroutine::new(&mut sched.stack_pool) {
418418
unsafe { *task_ran_ptr = true; }
419419
};
420420
sched.enqueue_task(task);
@@ -432,7 +432,7 @@ mod test {
432432

433433
let mut sched = ~UvEventLoop::new_scheduler();
434434
for int::range(0, total) |_| {
435-
let task = ~do Task::new(&mut sched.stack_pool) {
435+
let task = ~do Coroutine::new(&mut sched.stack_pool) {
436436
unsafe { *task_count_ptr = *task_count_ptr + 1; }
437437
};
438438
sched.enqueue_task(task);
@@ -449,10 +449,10 @@ mod test {
449449
let count_ptr: *mut int = &mut count;
450450

451451
let mut sched = ~UvEventLoop::new_scheduler();
452-
let task1 = ~do Task::new(&mut sched.stack_pool) {
452+
let task1 = ~do Coroutine::new(&mut sched.stack_pool) {
453453
unsafe { *count_ptr = *count_ptr + 1; }
454454
let mut sched = local_sched::take();
455-
let task2 = ~do Task::new(&mut sched.stack_pool) {
455+
let task2 = ~do Coroutine::new(&mut sched.stack_pool) {
456456
unsafe { *count_ptr = *count_ptr + 1; }
457457
};
458458
// Context switch directly to the new task
@@ -479,7 +479,7 @@ mod test {
479479

480480
let mut sched = ~UvEventLoop::new_scheduler();
481481

482-
let start_task = ~do Task::new(&mut sched.stack_pool) {
482+
let start_task = ~do Coroutine::new(&mut sched.stack_pool) {
483483
run_task(count_ptr);
484484
};
485485
sched.enqueue_task(start_task);
@@ -489,7 +489,7 @@ mod test {
489489

490490
fn run_task(count_ptr: *mut int) {
491491
do local_sched::borrow |sched| {
492-
let task = ~do Task::new(&mut sched.stack_pool) {
492+
let task = ~do Coroutine::new(&mut sched.stack_pool) {
493493
unsafe {
494494
*count_ptr = *count_ptr + 1;
495495
if *count_ptr != MAX {
@@ -507,7 +507,7 @@ mod test {
507507
fn test_block_task() {
508508
do run_in_bare_thread {
509509
let mut sched = ~UvEventLoop::new_scheduler();
510-
let task = ~do Task::new(&mut sched.stack_pool) {
510+
let task = ~do Coroutine::new(&mut sched.stack_pool) {
511511
let sched = local_sched::take();
512512
assert!(sched.in_task_context());
513513
do sched.deschedule_running_task_and_then() |task| {

src/libcore/rt/test.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ use rt::local_services::LocalServices;
1818
/// will abort the process.
1919
pub fn run_in_newsched_task(f: ~fn()) {
2020
use unstable::run_in_bare_thread;
21-
use super::sched::Task;
21+
use super::sched::Coroutine;
2222
use rt::uv::uvio::UvEventLoop;
2323

2424
let f = Cell(f);
2525

2626
do run_in_bare_thread {
2727
let mut sched = ~UvEventLoop::new_scheduler();
28-
let task = ~Task::with_local(&mut sched.stack_pool,
29-
LocalServices::without_unwinding(),
30-
f.take());
28+
let task = ~Coroutine::with_local(&mut sched.stack_pool,
29+
LocalServices::without_unwinding(),
30+
f.take());
3131
sched.enqueue_task(task);
3232
sched.run();
3333
}
@@ -38,9 +38,9 @@ pub fn spawntask(f: ~fn()) {
3838
use super::sched::*;
3939

4040
let mut sched = local_sched::take();
41-
let task = ~Task::with_local(&mut sched.stack_pool,
42-
LocalServices::without_unwinding(),
43-
f);
41+
let task = ~Coroutine::with_local(&mut sched.stack_pool,
42+
LocalServices::without_unwinding(),
43+
f);
4444
do sched.switch_running_tasks_and_then(task) |task| {
4545
let task = Cell(task);
4646
let sched = local_sched::take();
@@ -53,9 +53,9 @@ pub fn spawntask_immediately(f: ~fn()) {
5353
use super::sched::*;
5454

5555
let mut sched = local_sched::take();
56-
let task = ~Task::with_local(&mut sched.stack_pool,
57-
LocalServices::without_unwinding(),
58-
f);
56+
let task = ~Coroutine::with_local(&mut sched.stack_pool,
57+
LocalServices::without_unwinding(),
58+
f);
5959
do sched.switch_running_tasks_and_then(task) |task| {
6060
let task = Cell(task);
6161
do local_sched::borrow |sched| {
@@ -69,9 +69,9 @@ pub fn spawntask_later(f: ~fn()) {
6969
use super::sched::*;
7070

7171
let mut sched = local_sched::take();
72-
let task = ~Task::with_local(&mut sched.stack_pool,
73-
LocalServices::without_unwinding(),
74-
f);
72+
let task = ~Coroutine::with_local(&mut sched.stack_pool,
73+
LocalServices::without_unwinding(),
74+
f);
7575

7676
sched.enqueue_task(task);
7777
local_sched::put(sched);
@@ -86,9 +86,9 @@ pub fn spawntask_random(f: ~fn()) {
8686
let run_now: bool = Rand::rand(&mut rng);
8787

8888
let mut sched = local_sched::take();
89-
let task = ~Task::with_local(&mut sched.stack_pool,
90-
LocalServices::without_unwinding(),
91-
f);
89+
let task = ~Coroutine::with_local(&mut sched.stack_pool,
90+
LocalServices::without_unwinding(),
91+
f);
9292

9393
if run_now {
9494
do sched.switch_running_tasks_and_then(task) |task| {
@@ -122,7 +122,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> {
122122
let old_task = Cell(old_task);
123123
let f = f.take();
124124
let mut sched = local_sched::take();
125-
let new_task = ~do Task::new(&mut sched.stack_pool) {
125+
let new_task = ~do Coroutine::new(&mut sched.stack_pool) {
126126
do (|| {
127127
(f.take())()
128128
}).finally {

src/libcore/rt/tube.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
use option::*;
1717
use clone::Clone;
1818
use super::rc::RC;
19-
use rt::sched::Task;
19+
use rt::sched::Coroutine;
2020
use rt::{context, TaskContext, SchedulerContext};
2121
use rt::local_sched;
2222
use vec::OwnedVector;
2323
use container::Container;
2424

2525
struct TubeState<T> {
26-
blocked_task: Option<~Task>,
26+
blocked_task: Option<~Coroutine>,
2727
buf: ~[T]
2828
}
2929

src/libcore/task/spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) {
581581
use rt::sched::*;
582582

583583
let mut sched = local_sched::take();
584-
let task = ~Task::new(&mut sched.stack_pool, f);
584+
let task = ~Coroutine::new(&mut sched.stack_pool, f);
585585
sched.schedule_new_task(task);
586586
}
587587

0 commit comments

Comments
 (0)