Benchmarks Documentation Examples Repository Blog Contact

Timers

Enumeration

Unknown member type eSleepType

Variable

Unknown member type sleepers

Functions

bool is_periodic(struct TimerEntry_t *entry)

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

unsigned get_sleeptime(const unsigned interval)

Will clean the periodicity flag from interval. sleep time in microseconds.

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

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

  • txn transaction used to modify the table
  • slot number of slot in
  • interval amount of us for which thread should sleep
  • type type of timer to set up

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.

  • microseconds time for which thread should sleep / wait for event
  • type type of timed event to set up

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.

  • owner thread ID which should own the timer
  • type type of the timer.

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.

  • owner thread which shall own the interval timer
  • type type of the event to be cancelled

Returns 0 if operation performed successfully.

int os_cancel_sleeper(int sleeper)

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

sleeper ID of the sleeper being cancelled 0 is operation performed successfully

  • sleeper ID of the sleeper being cancelled

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

  • 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()

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

uint32_t get_sleep_time(uint32_t sleep_from, uint32_t microtime)

This function will calculate the final time considering timer wraparound.

sleep_from time at which the sleep starts (microseconds)

microtime duration of sleep (microseconds) new value of kernel timer at the end of sleep

  • sleep_from time at which the sleep starts (microseconds)
  • microtime duration of sleep (microseconds)

Returns new value of kernel timer at the end of sleep

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.

  • delay address of buffer, where delay to next scheduled event will be written

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_run_timer(uint32_t microtime)

Will find and run scheduled event.

microtime current processor time in microseconds

  • microtime current processor time in microseconds

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

TIMER_INVALID_ID

64kB of protected memory ought to be enough for everyone.