1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * Timer module for Unix, using SIGALRM.
12 *
13 * By Michael Bukin.
14 *
15 * See readme.txt for copyright information.
16 */
17
18
19 #include "allegro.h"
20 #include "allegro/internal/aintern.h"
21 #include "allegro/platform/aintunix.h"
22
23
24
25 #ifndef ALLEGRO_HAVE_LIBPTHREAD
26
27
28 static int sigalrm_timer_init(void);
29 static void sigalrm_timer_exit(void);
30
31
32
33 TIMER_DRIVER timerdrv_unix_sigalrm =
34 {
35 TIMERDRV_UNIX_SIGALRM,
36 empty_string,
37 empty_string,
38 "Unix SIGALRM timer",
39 sigalrm_timer_init,
40 sigalrm_timer_exit,
41 NULL, NULL, /* install_int, remove_int */
42 NULL, NULL, /* install_param_int, remove_param_int */
43 NULL, NULL, /* can_simulate_retrace, simulate_retrace */
44 _unix_rest /* rest */
45 };
46
47
48
49 /* sigalrm_timerint:
50 * Timer "interrupt" handler.
51 */
sigalrm_timerint(unsigned long interval)52 static void sigalrm_timerint(unsigned long interval)
53 {
54 _handle_timer_tick(interval);
55 }
56
57
58
59 /* sigalrm_timer_init:
60 * Installs the timer driver.
61 */
sigalrm_timer_init(void)62 static int sigalrm_timer_init(void)
63 {
64 if (_unix_bg_man != &_bg_man_sigalrm)
65 return -1;
66
67 DISABLE();
68
69 _sigalrm_timer_interrupt_handler = sigalrm_timerint;
70
71 ENABLE();
72
73 return 0;
74 }
75
76
77
78 /* sigalrm_timer_exit:
79 * Shuts down the timer driver.
80 */
sigalrm_timer_exit(void)81 static void sigalrm_timer_exit(void)
82 {
83 DISABLE();
84
85 _sigalrm_timer_interrupt_handler = 0;
86
87 ENABLE();
88 }
89
90
91 #endif
92
93