![]() |
O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
|
Use timeouts backed by signals and realtime clock. More...
#include <signal.h>
#include <stdbool.h>
#include <time.h>
Go to the source code of this file.
Data Structures | |
struct | o2s_timer_t |
Macros | |
#define | O2sTimer |
Automatically delete the timer when going out of scope. | |
#define | ArmedTimer |
Automatically disarm the timer when going out of scope. |
Functions | |
bool | o2s_timer_setup_process (void(*handle)(int, siginfo_t *, void *)) |
Prepare the process for timeouts. | |
o2s_timer_t | o2s_timer_create (void) |
Initialize a timer, that will create a SIGALRM in the current thread when timing out. | |
o2s_timer_t | o2s_timer_start (o2s_timer_t timer, unsigned milliseconds) |
Arm timer for the specified duration, in milliseconds. | |
void | o2s_timer_stop (o2s_timer_t *timer) |
Disarm timer. | |
void | o2s_timer_delete (o2s_timer_t *timer) |
Destructor. |
Use timeouts backed by signals and realtime clock.
Here is the intended usage of timers:
Definition in file timer.h.
#define ArmedTimer |
Automatically disarm the timer when going out of scope.
In a situation where one wants to declare a timer in a local scope, this "typedef" can be used for that timer to be disarmed automatically when the variable goes out of scope.
It means this "typedef" can only be used like this:
#define O2sTimer |
Automatically delete the timer when going out of scope.
In a situation where one wants to declare a timer in a local scope, this "typedef" can be used for that timer to be deleted automatically when the variable goes out of scope.
It means this "typedef" can only be used like this:
o2s_timer_t o2s_timer_create | ( | void | ) |
Initialize a timer, that will create a SIGALRM in the current thread when timing out.
This needs to be done once per thread, as the goal is for the timer to interrupt the system calls of the current thread.
bool o2s_timer_setup_process | ( | void(* | handle )(int, siginfo_t *, void *) | ) |
o2s_timer_t o2s_timer_start | ( | o2s_timer_t | timer, |
unsigned | milliseconds ) |