]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 * From v01.00 04/15/90 mbs
29 * Modified for MP, 1996 by Tuyen Nguyen
30 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
33 #include <sys/errno.h>
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <machine/spl.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/filedesc.h>
41 #include <sys/fcntl.h>
43 #include <sys/socket.h>
45 #include <netat/sysglue.h>
46 #include <netat/appletalk.h>
47 #include <netat/at_pcb.h>
48 #include <netat/debug.h>
49 #include <netat/adsp.h>
50 #include <netat/adsp_internal.h>
52 atlock_t adsptmr_lock
;
54 extern void DoTimerElem(); /* (TimerElemPtr t);
55 * External routine called to
56 * process each one. */
62 * qhead Address of ptr to first item in list
63 * t timer element to link in
64 * vbl timer value to use
68 void InsertTimerElem(qhead
, t
, val
)
69 /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
70 TimerElemPtr
*qhead
, t
;
73 TimerElemPtr p
; /* parent pointer */
74 TimerElemPtr n
; /* current */
77 ATDISABLE(s
, adsptmr_lock
);
81 * someone else beat us to the punch and put this
82 * element back on the queue, just return in this case
84 ATENABLE(s
, adsptmr_lock
);
87 p
= (TimerElemPtr
)qhead
;
90 if (val
<= n
->timer
) /* Do we go in front of this? */
92 n
->timer
-= val
; /* Yes, adjust his delta */
93 break; /* and go link us in */
95 val
-= n
->timer
; /* No, subtract off delta from our value */
99 /* It must go after item pointed to by p and in front of item
102 t
->onQ
= 1; /* we're linked in now */
103 p
->link
= t
; /* parent points to us */
104 t
->timer
= val
; /* this is our value */
105 t
->link
= n
; /* we point to n */
107 ATENABLE(s
, adsptmr_lock
);
115 * qhead Address of ptr to first item in list
116 * t timer element to link in
120 void RemoveTimerElem(qhead
, t
) /* (TimerElemPtr *qhead, TimerElemPtr t) */
121 TimerElemPtr
*qhead
, t
;
123 TimerElemPtr p
; /* parent pointer */
124 TimerElemPtr n
; /* current */
127 ATDISABLE(s
, adsptmr_lock
);
131 * someone else beat us to the punch and took this
132 * element off of the queue, just return in this case
134 ATENABLE(s
, adsptmr_lock
);
137 p
= (TimerElemPtr
)qhead
;
139 while (n
= p
->link
) /* Get next item in queue */
141 if (n
== t
) /* Is it us? */
143 if (p
->link
= n
->link
) /* Link our parent to our child */
145 n
->link
->timer
+= t
->timer
; /* and update child's timer */
147 n
->onQ
= 0; /* Not on linked list anymore */
153 ATENABLE(s
, adsptmr_lock
);
161 * qhead Address of ptr to first item in list
166 void TimerQueueTick(qhead
) /* (TimerElemPtr *qhead) */
169 TimerElemPtr p
; /* parent pointer */
170 TimerElemPtr n
; /* current */
173 ATDISABLE(s
, adsptmr_lock
);
175 p
= (TimerElemPtr
)qhead
;
176 if (p
->link
) /* Is anything on queue? */
177 p
->link
->timer
--; /* Yes, decrement by a tick */
179 goto done
; /* No, we're outta' here */
181 while ((n
= p
->link
) &&
182 (n
->timer
== 0)) /* Next guy needs to be serviced */
184 p
->link
= n
->link
; /* Unlink us */
187 ATENABLE(s
, adsptmr_lock
);
189 ATDISABLE(s
, adsptmr_lock
);
191 p
= (TimerElemPtr
)qhead
;
195 ATENABLE(s
, adsptmr_lock
);