3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/lib/libatm/timer.c,v 1.3.2.1 2001/09/28 16:52:10 dillon Exp $
27 * @(#) $DragonFly: src/lib/libatm/timer.c,v 1.4 2008/11/10 15:58:20 swildner Exp $
31 #include <sys/cdefs.h>
34 * User Space Library Functions
35 * ----------------------------
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <netatm/port.h>
47 #include <netatm/queue.h>
48 #include <netatm/atm.h>
49 #include <netatm/atm_if.h>
50 #include <netatm/atm_sap.h>
51 #include <netatm/atm_sys.h>
52 #include <netatm/atm_ioctl.h>
59 Harp_timer
*harp_timer_head
;
64 * Process a HARP timer tick
66 * This function is called via the SIGALRM signal. It increments
67 * harp_timer_exec. The user should check this flag frequently and
68 * call timer_proc when it is set.
78 timer_tick(int signo __unused
)
90 * This function is called after a SIGALRM signal is posted. It runs
91 * down the list of timer entries, calling the specified functions
92 * for any timers that have expired.
108 * Reset marks in all timers on the queue
110 for (htp
= harp_timer_head
; htp
; htp
= htp
->ht_next
) {
115 * Run through timer chain decrementing each timer.
116 * If an expired timer is found, take the timer block
117 * off the chain and call the specified function. A
118 * timer's action can result in other timers being
119 * cancelled (taken off the queue), so every time we
120 * call a user function, we start over from the top of
124 for (htp
= harp_timer_head
; htp
; htp
= htp
->ht_next
) {
126 * Make sure we only process each entry once and
127 * don't process entries that are put on the queue
128 * by user functions we call for this tick
130 if (htp
->ht_mark
== -1) {
132 * Decrement the timer and mark that we've
133 * processed the entry
135 htp
->ht_ticks
-= harp_timer_exec
;
139 * Check whether the timer is expired
141 if (htp
->ht_ticks
<= 0) {
143 * Unlink the timer block and call
147 UNLINK(htp
, Harp_timer
, harp_timer_head
,
160 * Reset the timer exec flag
169 * Set up the SIGALRM signal handler and set up the real-time
170 * timer to tick once per second.
177 * errno reason for failure
184 struct itimerval timeval
;
187 * Clear the timer flag
192 * Set up signal handler
194 if (signal(SIGALRM
, timer_tick
) == SIG_ERR
) {
201 timeval
.it_value
.tv_sec
= 1;
202 timeval
.it_value
.tv_usec
= 0;
203 timeval
.it_interval
.tv_sec
= 1;
204 timeval
.it_interval
.tv_usec
= 0;
206 if (setitimer(ITIMER_REAL
, &timeval
,
209 (void)signal(SIGALRM
, SIG_DFL
);
217 * Block timers from firing
219 * Block the SIGALRM signal.
225 * mask the previous blocked signal mask
232 * Block the SIGALRM signal
234 return(sigblock(sigmask(SIGALRM
)));
241 * Restore the signal mask (presumably one that was returned by
245 * mask the signal mask to be restored
248 * mask the previous blocked signal mask
252 enable_timer(int mask
)
255 * Set the signal mask