sched

Simple Task Scheduler (Min-Heap)

Functions

FunctionDescription
sched_newCreate a new scheduler.
_sched_swapInternal: swap two entries in the heap.
_sched_sift_upInternal: sift up from index i.
_sched_sift_downInternal: sift down from index i, with count elements.
sched_enterAdd a task to the scheduler.
sched_cancelCancel a task by id. Returns 1 if found and removed.
sched_nextReturn id of the next (earliest) task, or -1 if empty.
sched_next_timeReturn time of the next (earliest) task.
_sched_popInternal: remove the root element from the heap.
sched_runRun the next task if its time <= now. Returns task id or -1.
sched_emptyReturn 1 if the scheduler has no tasks.
sched_countReturn the number of tasks.

Details

sched_new

fn sched_new() -> &i64

Create a new scheduler.

_sched_swap

fn _sched_swap(times: &i64, ids: &i64, a: i64, b: i64) -> i64

Internal: swap two entries in the heap.

_sched_sift_up

fn _sched_sift_up(times: &i64, ids: &i64, i: i64) -> i64

Internal: sift up from index i.

_sched_sift_down

fn _sched_sift_down(times: &i64, ids: &i64, i: i64, count: i64) -> i64

Internal: sift down from index i, with count elements.

sched_enter

fn sched_enter(h: &i64, time: i64, id: i64) -> i64

Add a task to the scheduler.

sched_cancel

fn sched_cancel(h: &i64, id: i64) -> i64

Cancel a task by id. Returns 1 if found and removed.

sched_next

fn sched_next(h: &i64) -> i64

Return id of the next (earliest) task, or -1 if empty.

sched_next_time

fn sched_next_time(h: &i64) -> i64

Return time of the next (earliest) task.

_sched_pop

fn _sched_pop(h: &i64) -> i64

Internal: remove the root element from the heap.

sched_run

fn sched_run(h: &i64, now: i64) -> i64

Run the next task if its time <= now. Returns task id or -1.

sched_empty

fn sched_empty(h: &i64) -> i64

Return 1 if the scheduler has no tasks.

sched_count

fn sched_count(h: &i64) -> i64

Return the number of tasks.