class scheduler

Defined at line 23 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

Keeps track of runnable and suspended tasks.

This is a low-level building block for implementing executors.

For a concrete implementation, see |fpromise::single_threaded_executor|.

Instances of this object are not thread-safe. Its client is responsible

for providing all necessary synchronization.

Public Methods

void scheduler ()

Defined at line 14 of file ../../sdk/lib/fit-promise/scheduler.cc

void ~scheduler ()

Defined at line 16 of file ../../sdk/lib/fit-promise/scheduler.cc

void schedule_task (pending_task task)

Adds a task to the runnable queue.

Preconditions:

- |task| must be non-empty

Defined at line 18 of file ../../sdk/lib/fit-promise/scheduler.cc

suspended_task::ticket obtain_ticket (ref_count_type initial_refs)

Obtains a new ticket with a ref-count of |initial_refs|.

The executor must eventually call |finalize_ticket()| to update the

state of the ticket.

Preconditions:

- |initial_refs| must be at least 1

Defined at line 23 of file ../../sdk/lib/fit-promise/scheduler.cc

void finalize_ticket (suspended_task::ticket ticket, pending_task * task)

Updates a ticket after one run of a task's continuation according

to the state of the task after its run. The executor must call this

method after calling |obtain_ticket()| to indicate the disposition of

the task for which the ticket was obtained.

Passing an empty |task| indicates that the task has completed so it

does not need to be resumed.

Passing a non-empty |task| indicates that the task returned a pending

result and may need to be suspended depending on the current state

of the ticket.

- If the ticket has already been resumed, moves |task| into the

runnable queue.

- Otherwise, if the ticket still has a non-zero ref-count, moves |task|

into the suspended task table.

- Otherwise, considers the task abandoned and the caller retains

ownership of |task|.

Preconditions:

- |task| must be non-null (may be empty)

- the ticket must not have already been finalized

Defined at line 29 of file ../../sdk/lib/fit-promise/scheduler.cc

void duplicate_ticket (suspended_task::ticket ticket)

Increments the ticket's ref-count.

Preconditions:

- the ticket's ref-count must be non-zero (positive)

Defined at line 52 of file ../../sdk/lib/fit-promise/scheduler.cc

pending_task release_ticket (suspended_task::ticket ticket)

Decrements the ticket's ref-count.

If the task's ref-count reaches 0 and has an associated task that

has not already been resumed, returns the associated task back

to the caller.

Otherwise, returns an empty task.

Preconditions:

- the ticket's ref-count must be non-zero (positive)

Defined at line 61 of file ../../sdk/lib/fit-promise/scheduler.cc

bool resume_task_with_ticket (suspended_task::ticket ticket)

Resumes a task and decrements the ticket's ref-count.

If the ticket has an associated task that has not already been resumed,

moves its associated task to the runnable queue and returns true.

Otherwise, returns false.

Preconditions:

- the ticket's ref-count must be non-zero (positive)

Defined at line 79 of file ../../sdk/lib/fit-promise/scheduler.cc

void take_runnable_tasks (task_queue * tasks)

Takes all tasks in the runnable queue.

Preconditions:

- |tasks| must be non-null and empty

Defined at line 101 of file ../../sdk/lib/fit-promise/scheduler.cc

void take_all_tasks (task_queue * tasks)

Takes all remaining tasks, regardless of whether they are runnable

or suspended.

This operation is useful when shutting down an executor.

Preconditions:

- |tasks| must be non-null and empty

Defined at line 106 of file ../../sdk/lib/fit-promise/scheduler.cc

bool has_runnable_tasks ()

Returns true if there are any runnable tasks.

Defined at line 111 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

bool has_suspended_tasks ()

Returns true if there are any suspended tasks that have yet to

be resumed.

Defined at line 115 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

bool has_outstanding_tickets ()

Returns true if there are any tickets that have yet to be finalized,

released, or resumed.

Defined at line 119 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

void scheduler (const scheduler & )

Defined at line 121 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

void scheduler (scheduler && )

Defined at line 122 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

scheduler & operator= (const scheduler & )

Defined at line 123 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h

scheduler & operator= (scheduler && )

Defined at line 124 of file ../../sdk/lib/fit-promise/include/lib/fpromise/scheduler.h