O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
timer.c File Reference

Use timeouts backed by signals and realtime clock. More...

#include "o2s/timer.h"
#include "o2s/log.h"
#include <errno.h>
#include <iso646.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define MS_IN_NS
 Milli-seconds expressed in nano-seconds.
#define MS_PER_S
 Number of milli-seconds in a second.

Functions

bool o2s_timer_setup_process (void(*handle)(int, siginfo_t *, void *))
 Prepare the process for timeouts.
o2s_timer_t o2s_timer_create ()
 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.

Detailed Description

Use timeouts backed by signals and realtime clock.

Author
Antoine GAGNIERE

Definition in file timer.c.

Function Documentation

◆ o2s_timer_create()

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.

Returns
a timer object whose member created is false if it was unable to create the timer

Definition at line 59 of file timer.c.

◆ o2s_timer_setup_process()

bool o2s_timer_setup_process ( void(* handle )(int, siginfo_t *, void *))

Prepare the process for timeouts.

Needed to be called only once, preferably before creating the threads.

Returns
true if successful, false otherwise

Definition at line 40 of file timer.c.

◆ o2s_timer_start()

o2s_timer_t o2s_timer_start ( o2s_timer_t timer,
unsigned milliseconds )

Arm timer for the specified duration, in milliseconds.

Returns
another timer object whose member armed is false if unable to start

Definition at line 82 of file timer.c.