O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1#pragma once
2
3/* ************************************************************************** */
4/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
5/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
6/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
7/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
8/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
9/* */
16/* ************************************************************************** */
17
18#include <signal.h> // sigaction
19#include <stdbool.h> // bool
20#include <time.h> // timer_t
21
22typedef struct o2s_timer
23{
24 timer_t timer_id;
25 bool created;
26 bool armed;
28
29bool o2s_timer_setup_process(void (*handle)(int, siginfo_t*, void*));
31o2s_timer_t o2s_timer_start(o2s_timer_t timer, unsigned milliseconds);
32void o2s_timer_stop(o2s_timer_t* timer);
33void o2s_timer_delete(o2s_timer_t* timer);
34
50#define O2sTimer __attribute__((cleanup(o2s_timer_delete))) o2s_timer_t
51
67#define ArmedTimer __attribute__((cleanup(o2s_timer_stop))) o2s_timer_t
bool o2s_timer_setup_process(void(*handle)(int, siginfo_t *, void *))
Prepare the process for timeouts.
Definition timer.c:40
o2s_timer_t o2s_timer_start(o2s_timer_t timer, unsigned milliseconds)
Arm timer for the specified duration, in milliseconds.
Definition timer.c:82
void o2s_timer_stop(o2s_timer_t *timer)
Disarm timer.
Definition timer.c:96
o2s_timer_t o2s_timer_create(void)
Initialize a timer, that will create a SIGALRM in the current thread when timing out.
Definition timer.c:59
void o2s_timer_delete(o2s_timer_t *timer)
Destructor.
Definition timer.c:111