-
Notifications
You must be signed in to change notification settings - Fork 0
/
posix_timers.h
35 lines (30 loc) · 1.05 KB
/
posix_timers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* An example of how to use signals to implement a timer facility using
* POSIX threads.
*
* Rationale: when using normal Unix signals (SIGALRM), the signal handler executes
* in a signal handler context. In a signal handler context, only async-signal-safe
* functions may be called. Few POSIX functions are async-signal-safe.
*
* Instead of handling the timer activity in the signal handler function,
* we create a separate thread to perform the timer activity.
* This timer thread receives a signal from a semaphore, which is signaled ("posted")
* every time a timer signal arrives.
*
* You'll have to redefine "timer_func" below and "set_periodic_timer."
*
* Read the man pages of the functions used, such as signal(2), signal(7),
* alarm(2).
*
* Written by Godmar Back <[email protected]>, February 2006.
*/
#ifndef __POSIXTIMERS
#define __POSIXTIMERS
/**
* NOTE: the user has to provide a function with the signature:
void timer_func(void);
*/
void init_timer(void);
void shutdown_timer();
void set_periodic_timer(long delay);
#endif