bio
 
Loading...
Searching...
No Matches
Timer

Execute a function at an interval or after a delay. More...

Data Structures

struct  bio_timer_t
 Handle to a timer. More...
 

Enumerations

enum  bio_timer_type_t { BIO_TIMER_ONESHOT , BIO_TIMER_INTERVAL }
 Types of timer. More...
 

Functions

bio_timer_t bio_create_timer (bio_timer_type_t type, bio_time_t timeout_ms, bio_entrypoint_t fn, void *userdata)
 Create a new timer.
 
bool bio_is_timer_pending (bio_timer_t timer)
 Check whether a timer is pending.
 
void bio_reset_timer (bio_timer_t timer, bio_time_t timeout_ms)
 Reset a timer.
 
void bio_cancel_timer (bio_timer_t timer)
 Cancel a timer.
 

Detailed Description

Execute a function at an interval or after a delay.

Enumeration Type Documentation

◆ bio_timer_type_t

Types of timer.

Enumerator
BIO_TIMER_ONESHOT 

Trigger only once.

BIO_TIMER_INTERVAL 

Trigger repeatedly.

Function Documentation

◆ bio_cancel_timer()

void bio_cancel_timer ( bio_timer_t  timer)

Cancel a timer.

For a timer of type BIO_TIMER_ONESHOT, it is guaranteed that the associated function will not be invoked if the timer has not fired.

◆ bio_create_timer()

bio_timer_t bio_create_timer ( bio_timer_type_t  type,
bio_time_t  timeout_ms,
bio_entrypoint_t  fn,
void *  userdata 
)

Create a new timer.

Remarks
A timer is implemented as a coroutine waiting on its own (delayed) signal. When a timer of type BIO_TIMER_INTERVAL is no longer needed, it should be cancelled with bio_cancel_timer. Otherwise, bio_loop will never terminate.
Parameters
typeThe type of timer
timeout_msThe period or the delay for the timer in milliseconds
fnThe function to be called
userdataData passed to fn
Returns
Handle to a timer

◆ bio_is_timer_pending()

bool bio_is_timer_pending ( bio_timer_t  timer)

Check whether a timer is pending.

For an uncancelled timer of type BIO_TIMER_INTERVAL, this will always return true.

◆ bio_reset_timer()

void bio_reset_timer ( bio_timer_t  timer,
bio_time_t  timeout_ms 
)

Reset a timer.

For a timer of type BIO_TIMER_ONESHOT, this will postpone the execution time as if bio_create_timer was just called at this point.

For a timer of type BIO_TIMER_INTERVAL, the current wait interval will be cancelled. The timer will begin a new wait interval with value timeout_ms.

Parameters
timerThe timer to reset
timeout_msThe new timeout