]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_TimerElem.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * From v01.00 04/15/90 mbs
26 * Modified for MP, 1996 by Tuyen Nguyen
27 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
30 #include <sys/errno.h>
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <machine/spl.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
40 #include <sys/socket.h>
42 #include <netat/sysglue.h>
43 #include <netat/appletalk.h>
44 #include <netat/at_pcb.h>
45 #include <netat/debug.h>
46 #include <netat/adsp.h>
47 #include <netat/adsp_internal.h>
49 atlock_t adsptmr_lock
;
51 extern void DoTimerElem(); /* (TimerElemPtr t);
52 * External routine called to
53 * process each one. */
59 * qhead Address of ptr to first item in list
60 * t timer element to link in
61 * vbl timer value to use
65 void InsertTimerElem(qhead
, t
, val
)
66 /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
67 TimerElemPtr
*qhead
, t
;
70 TimerElemPtr p
; /* parent pointer */
71 TimerElemPtr n
; /* current */
74 ATDISABLE(s
, adsptmr_lock
);
78 * someone else beat us to the punch and put this
79 * element back on the queue, just return in this case
81 ATENABLE(s
, adsptmr_lock
);
84 p
= (TimerElemPtr
)qhead
;
87 if (val
<= n
->timer
) /* Do we go in front of this? */
89 n
->timer
-= val
; /* Yes, adjust his delta */
90 break; /* and go link us in */
92 val
-= n
->timer
; /* No, subtract off delta from our value */
96 /* It must go after item pointed to by p and in front of item
99 t
->onQ
= 1; /* we're linked in now */
100 p
->link
= t
; /* parent points to us */
101 t
->timer
= val
; /* this is our value */
102 t
->link
= n
; /* we point to n */
104 ATENABLE(s
, adsptmr_lock
);
112 * qhead Address of ptr to first item in list
113 * t timer element to link in
117 void RemoveTimerElem(qhead
, t
) /* (TimerElemPtr *qhead, TimerElemPtr t) */
118 TimerElemPtr
*qhead
, t
;
120 TimerElemPtr p
; /* parent pointer */
121 TimerElemPtr n
; /* current */
124 ATDISABLE(s
, adsptmr_lock
);
128 * someone else beat us to the punch and took this
129 * element off of the queue, just return in this case
131 ATENABLE(s
, adsptmr_lock
);
134 p
= (TimerElemPtr
)qhead
;
136 while (n
= p
->link
) /* Get next item in queue */
138 if (n
== t
) /* Is it us? */
140 if (p
->link
= n
->link
) /* Link our parent to our child */
142 n
->link
->timer
+= t
->timer
; /* and update child's timer */
144 n
->onQ
= 0; /* Not on linked list anymore */
150 ATENABLE(s
, adsptmr_lock
);
158 * qhead Address of ptr to first item in list
163 void TimerQueueTick(qhead
) /* (TimerElemPtr *qhead) */
166 TimerElemPtr p
; /* parent pointer */
167 TimerElemPtr n
; /* current */
170 ATDISABLE(s
, adsptmr_lock
);
172 p
= (TimerElemPtr
)qhead
;
173 if (p
->link
) /* Is anything on queue? */
174 p
->link
->timer
--; /* Yes, decrement by a tick */
176 goto done
; /* No, we're outta' here */
178 while ((n
= p
->link
) &&
179 (n
->timer
== 0)) /* Next guy needs to be serviced */
181 p
->link
= n
->link
; /* Unlink us */
184 ATENABLE(s
, adsptmr_lock
);
186 ATDISABLE(s
, adsptmr_lock
);
188 p
= (TimerElemPtr
)qhead
;
192 ATENABLE(s
, adsptmr_lock
);