nlib
nlib_timerspec Struct Reference

Specifies the time to elapse before the timer initially starts up and the interval between the subsequent startups. If 0 is specified for the both values, the timer stops. More...

#include <manual_en_platform.h>

Public Attributes

A timer

It allows a task to be regularly run.

Description
The following is a sample code that creates a timer, reads the callback function five times at an interval of 100 milliseconds after 200 milliseconds have elapsed from the timer creation, and deletes the timer with the last callback function call.
nlib_timer timer;
int counter = 0;
e = nlib_timer_create(&timer, [](nlib_timer t, void* p) {
// NOTE:
// callback function can be called in parallel
int32_t* pcounter = reinterpret_cast<int*>(p);
int32_t cnt = nlib_atomic_add_fetch32(pcounter, 1, NLIB_ATOMIC_SEQ_CST);
nlib_printf("counter = %d\n", cnt);
if (cnt == 5) {
nlib_timer_delete(t, 1, NULL);
}
}, &counter, 0);
SUCCEED_IF(e == 0);
nlib_timerspec spec = {
_100msec * 2, // due_time
_100msec // interval
};
e = nlib_timer_settime(timer, &spec, NULL);
if (e != 0) {
nlib_timer_delete(timer, 1, NULL);
SUCCEED_IF(0);
}
while (counter < 5) {
nlib_sleep(_100msec);
}
/*
Output:
counter = 1
counter = 2
counter = 3
counter = 4
counter = 5
*/
nlib_duration due_time
 Specifies the time to elapse before the timer initially starts up.
 
nlib_duration interval
 Specifies the interval between the startups of the timer following its initial startup. If 0 is specified, the time works as a one-shot timer.
 

Detailed Description

Specifies the time to elapse before the timer initially starts up and the interval between the subsequent startups. If 0 is specified for the both values, the timer stops.

Definition at line 515 of file Platform.h.


The documentation for this struct was generated from the following files: