Timers

Enumeration

Unknown member type eSleepType

Variable

Unknown member type sleepers Unknown member type sleeper_queue Unknown member type sleeper_queue_size Unknown member type sleeper_queue_cursor

Functions

bool is_periodic(struct TimerEntry_t *entry)

1 if interval is periodic, 0 if interval is one-shot.

int os_find_timer_slot(Thread_t owner, enum eSleepType type)

int os_find_timer_queue(int timer_slot_id)

void os_dequeue_timed_event(unsigned queue_offs)

void os_enqueue_timed_event(unsigned sleeper_id, uint32_t next_resume)

int do_set_timed_event(Txn_t txn, const unsigned slot, const unsigned interval, const enum eSleepType type)

If event is not periodic, it will also stop thread (os_usleep

Returns 0 if timer was set up properly

int os_set_timed_event(unsigned microseconds, enum eSleepType type)

This is actual execution core for both os_usleepos_setitimer

microseconds time for which thread should sleep / wait for event

type type of timed event to set up error status. 0 means no error.

Returns error status. 0 means no error.

int os_find_timer(Thread_t owner, enum eSleepType type)

This will find a slot which bears the timer of given type for given thread.

owner thread ID which should own the timer

type type of the timer. offset of entry in timer queue or TIMER_INVALID_ID if no such timer was found.

Returns offset of entry in timer queue or TIMER_INVALID_ID if no such timer was found.

int os_cancel_timed_event(Thread_t owner, enum eSleepType type)

This function is only accessible for periodic timers externally. It allows cancelling of interval timers set previously.

owner thread which shall own the interval timer

type type of the event to be cancelled 0 if operation performed successfully.

Returns 0 if operation performed successfully.

int os_cancel_sleeper(unsigned sleeper_queue_id)

This function will cancel existing sleeper. It is useful for cases where you already know the identity of the sleeper in advance.

sleeper_queue_id ID of the item in sorted key array 0 is operation performed successfully

Returns 0 is operation performed successfully

void delay_us(uint32_t period_us)

This will perform busywait in the context of current thread. Useful to do short waits for I/O.

period_us how long the wait should take

int os_usleep(unsigned microseconds)

See usleep

int os_setitimer(unsigned microseconds)

See setitimer

void os_timer_init(void)

It is necessary to call this routine before first call to either timer syscalls, or os_run_timer

bool os_schedule_timer(unsigned *delay)

This function informs caller about delay until next scheduled event. Next scheduled event may be either wake-up of sleeped thread, or interval timer.

delay address of buffer, where delay to next scheduled event will be written true if there is any scheduled event known and at address pointed to by delay value was written. Returns false if there is no known scheduled event. In such case content of memory pointed to by delay is undefined.

Returns true if there is any scheduled event known and at address pointed to by delay value was written. Returns false if there is no known scheduled event. In such case content of memory pointed to by delay is undefined.

void os_sleeper_reschedule(unsigned sleeper_queue_id)

void os_run_timer(uint32_t start_microtime, uint32_t interval)

Will find and run all scheduled events in given time interval.

microtime starting processor time in microseconds of interval to run

interval lenght of the interval events should be fired

uint32_t os_cpu_freq_get(void)

Will return the current CPU frequency (if known and/or available). CPU frequency in Hz, 0 if value is not known.

Macros

SLEEPER_KEY_TYPE_SHIFT

SLEEPER_KEY(_type, _thread)

TIMER_INVALID_ID

← Thread scheduling Tracing Kernel Events →