]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_TimerElem.c
8f8a9ce52c18eba5d781ffa3f56a5609f50fa736
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 * From v01.00 04/15/90 mbs
34 * Modified for MP, 1996 by Tuyen Nguyen
35 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
38 #include <sys/errno.h>
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <machine/spl.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
45 #include <sys/filedesc.h>
46 #include <sys/fcntl.h>
48 #include <sys/socket.h>
50 #include <netat/sysglue.h>
51 #include <netat/appletalk.h>
52 #include <netat/at_pcb.h>
53 #include <netat/debug.h>
54 #include <netat/adsp.h>
55 #include <netat/adsp_internal.h>
57 atlock_t adsptmr_lock
;
59 extern void DoTimerElem(); /* (TimerElemPtr t);
60 * External routine called to
61 * process each one. */
67 * qhead Address of ptr to first item in list
68 * t timer element to link in
69 * vbl timer value to use
73 void InsertTimerElem(qhead
, t
, val
)
74 /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
75 TimerElemPtr
*qhead
, t
;
78 TimerElemPtr p
; /* parent pointer */
79 TimerElemPtr n
; /* current */
82 ATDISABLE(s
, adsptmr_lock
);
86 * someone else beat us to the punch and put this
87 * element back on the queue, just return in this case
89 ATENABLE(s
, adsptmr_lock
);
92 p
= (TimerElemPtr
)qhead
;
95 if (val
<= n
->timer
) /* Do we go in front of this? */
97 n
->timer
-= val
; /* Yes, adjust his delta */
98 break; /* and go link us in */
100 val
-= n
->timer
; /* No, subtract off delta from our value */
104 /* It must go after item pointed to by p and in front of item
107 t
->onQ
= 1; /* we're linked in now */
108 p
->link
= t
; /* parent points to us */
109 t
->timer
= val
; /* this is our value */
110 t
->link
= n
; /* we point to n */
112 ATENABLE(s
, adsptmr_lock
);
120 * qhead Address of ptr to first item in list
121 * t timer element to link in
125 void RemoveTimerElem(qhead
, t
) /* (TimerElemPtr *qhead, TimerElemPtr t) */
126 TimerElemPtr
*qhead
, t
;
128 TimerElemPtr p
; /* parent pointer */
129 TimerElemPtr n
; /* current */
132 ATDISABLE(s
, adsptmr_lock
);
136 * someone else beat us to the punch and took this
137 * element off of the queue, just return in this case
139 ATENABLE(s
, adsptmr_lock
);
142 p
= (TimerElemPtr
)qhead
;
144 while (n
= p
->link
) /* Get next item in queue */
146 if (n
== t
) /* Is it us? */
148 if (p
->link
= n
->link
) /* Link our parent to our child */
150 n
->link
->timer
+= t
->timer
; /* and update child's timer */
152 n
->onQ
= 0; /* Not on linked list anymore */
158 ATENABLE(s
, adsptmr_lock
);
166 * qhead Address of ptr to first item in list
171 void TimerQueueTick(qhead
) /* (TimerElemPtr *qhead) */
174 TimerElemPtr p
; /* parent pointer */
175 TimerElemPtr n
; /* current */
178 ATDISABLE(s
, adsptmr_lock
);
180 p
= (TimerElemPtr
)qhead
;
181 if (p
->link
) /* Is anything on queue? */
182 p
->link
->timer
--; /* Yes, decrement by a tick */
184 goto done
; /* No, we're outta' here */
186 while ((n
= p
->link
) &&
187 (n
->timer
== 0)) /* Next guy needs to be serviced */
189 p
->link
= n
->link
; /* Unlink us */
192 ATENABLE(s
, adsptmr_lock
);
194 ATDISABLE(s
, adsptmr_lock
);
196 p
= (TimerElemPtr
)qhead
;
200 ATENABLE(s
, adsptmr_lock
);