]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_TimerElem.c
7950171507d0ac91f96c7bd57fb8534144d40b58
2 * Copyright (c) 2000 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>
58 extern void DoTimerElem(); /* (TimerElemPtr t);
59 * External routine called to
60 * process each one. */
66 * qhead Address of ptr to first item in list
67 * t timer element to link in
68 * vbl timer value to use
72 void InsertTimerElem(qhead
, t
, val
)
73 /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
74 TimerElemPtr
*qhead
, t
;
77 TimerElemPtr p
; /* parent pointer */
78 TimerElemPtr n
; /* current */
82 * someone else beat us to the punch and put this
83 * element back on the queue, just return in this case
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 */
114 * qhead Address of ptr to first item in list
115 * t timer element to link in
119 void RemoveTimerElem(qhead
, t
) /* (TimerElemPtr *qhead, TimerElemPtr t) */
120 TimerElemPtr
*qhead
, t
;
122 TimerElemPtr p
; /* parent pointer */
123 TimerElemPtr n
; /* current */
127 * someone else beat us to the punch and took this
128 * element off of the queue, just return in this case
132 p
= (TimerElemPtr
)qhead
;
134 while (n
= p
->link
) /* Get next item in queue */
136 if (n
== t
) /* Is it us? */
138 if (p
->link
= n
->link
) /* Link our parent to our child */
140 n
->link
->timer
+= t
->timer
; /* and update child's timer */
142 n
->onQ
= 0; /* Not on linked list anymore */
155 * qhead Address of ptr to first item in list
160 void TimerQueueTick(qhead
) /* (TimerElemPtr *qhead) */
163 TimerElemPtr p
; /* parent pointer */
164 TimerElemPtr n
; /* current */
166 p
= (TimerElemPtr
)qhead
;
167 if (p
->link
) { /* Is anything on queue? */
168 p
->link
->timer
--; /* Yes, decrement by a tick */
169 while ((n
= p
->link
) &&
170 (n
->timer
== 0)) /* Next guy needs to be serviced */
172 p
->link
= n
->link
; /* Unlink us */
177 p
= (TimerElemPtr
)qhead
;