Struct green::sched::Scheduler[src]
pub struct Scheduler {
pub pool_id: uint,
pub stack_pool: StackPool,
pub task_state: TaskState,
pub event_loop: Box<EventLoop + Send>,
// some fields omitted
}A scheduler is responsible for coordinating the execution of Tasks on a single thread. The scheduler runs inside a slightly modified Rust Task. When not running this task is stored in the scheduler struct. The scheduler struct acts like a baton, all scheduling actions are transfers of the baton.
FIXME: This creates too many callbacks to run_sched_once, resulting in too much allocation and too many events.
Fields
pool_id | ID number of the pool that this scheduler is a member of. When reawakening green tasks, this is used to ensure that tasks aren't reawoken on the wrong pool of schedulers. |
stack_pool | The pool of stacks that this scheduler has cached |
task_state | Bookkeeping for the number of tasks which are currently running around inside this pool of schedulers |
event_loop | The event loop used to drive the scheduler and perform I/O |
Methods
impl Scheduler
fn new(pool_id: uint, event_loop: Box<EventLoop + Send>, work_queue: Worker<Box<GreenTask>>, work_queues: Vec<Stealer<Box<GreenTask>>>, sleeper_list: SleeperList, state: TaskState) -> Scheduler
fn new_special(pool_id: uint, event_loop: Box<EventLoop + Send>, work_queue: Worker<Box<GreenTask>>, work_queues: Vec<Stealer<Box<GreenTask>>>, sleeper_list: SleeperList, run_anything: bool, friend: Option<SchedHandle>, state: TaskState) -> Scheduler
fn bootstrap(~self)
fn run(~self, stask: Box<GreenTask>) -> Box<GreenTask>
fn enqueue_task(&mut self, task: Box<GreenTask>)
Schedule a task to be executed later.
Pushes the task onto the work stealing queue and tells the event loop to run it later. Always use this instead of pushing to the work queue directly.
fn change_task_context(~self, current_task: Box<GreenTask>, next_task: Box<GreenTask>, f: |&mut Scheduler, Box<GreenTask>|) -> Box<GreenTask>
fn get_contexts<'a>(current_task: &mut GreenTask, next_task: &mut GreenTask) -> (&'a mut Context, &'a mut Context)
fn resume_task_immediately(~self, cur: Box<GreenTask>, next: Box<GreenTask>) -> (Box<Scheduler>, Box<GreenTask>)
fn deschedule_running_task_and_then(~self, cur: Box<GreenTask>, f: |&mut Scheduler, BlockedTask|)
Block a running task, context switch to the scheduler, then pass the blocked task to a closure.
Safety note
The closure here is a stack closure that lives in the running task. It gets transmuted to the scheduler's lifetime and called while the task is blocked.
This passes a Scheduler pointer to the fn after the context switch in order to prevent that fn from performing further scheduling operations. Doing further scheduling could easily result in infinite recursion.
Note that if the closure provided relinquishes ownership of the BlockedTask, then it is possible for the task to resume execution before the closure has finished executing. This would naturally introduce a race if the closure and task shared portions of the environment.
This situation is currently prevented, or in other words it is guaranteed that this function will not return before the given closure has returned.
fn switch_running_tasks_and_then(~self, cur: Box<GreenTask>, next: Box<GreenTask>, f: |&mut Scheduler, BlockedTask|)
fn terminate_current_task(~self, cur: Box<GreenTask>) -> !
Called by a running task to end execution, after which it will be recycled by the scheduler for reuse in a new task.
fn run_task(~self, cur: Box<GreenTask>, next: Box<GreenTask>)
fn run_task_later(cur: Box<GreenTask>, next: Box<GreenTask>)
fn yield_now(~self, cur: Box<GreenTask>)
Yield control to the scheduler, executing another task. This is guaranteed to introduce some amount of randomness to the scheduler. Currently the randomness is a result of performing a round of work stealing (which may end up stealing from the current scheduler).