]>
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>
50 extern void DoTimerElem(); /* (TimerElemPtr t);
51 * External routine called to
52 * process each one. */
58 * qhead Address of ptr to first item in list
59 * t timer element to link in
60 * vbl timer value to use
64 void InsertTimerElem(qhead
, t
, val
)
65 /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
66 TimerElemPtr
*qhead
, t
;
69 TimerElemPtr p
; /* parent pointer */
70 TimerElemPtr n
; /* current */
74 * someone else beat us to the punch and put this
75 * element back on the queue, just return in this case
79 p
= (TimerElemPtr
)qhead
;
82 if (val
<= n
->timer
) /* Do we go in front of this? */
84 n
->timer
-= val
; /* Yes, adjust his delta */
85 break; /* and go link us in */
87 val
-= n
->timer
; /* No, subtract off delta from our value */
91 /* It must go after item pointed to by p and in front of item
94 t
->onQ
= 1; /* we're linked in now */
95 p
->link
= t
; /* parent points to us */
96 t
->timer
= val
; /* this is our value */
97 t
->link
= n
; /* we point to n */
106 * qhead Address of ptr to first item in list
107 * t timer element to link in
111 void RemoveTimerElem(qhead
, t
) /* (TimerElemPtr *qhead, TimerElemPtr t) */
112 TimerElemPtr
*qhead
, t
;
114 TimerElemPtr p
; /* parent pointer */
115 TimerElemPtr n
; /* current */
119 * someone else beat us to the punch and took this
120 * element off of the queue, just return in this case
124 p
= (TimerElemPtr
)qhead
;
126 while (n
= p
->link
) /* Get next item in queue */
128 if (n
== t
) /* Is it us? */
130 if (p
->link
= n
->link
) /* Link our parent to our child */
132 n
->link
->timer
+= t
->timer
; /* and update child's timer */
134 n
->onQ
= 0; /* Not on linked list anymore */
147 * qhead Address of ptr to first item in list
152 void TimerQueueTick(qhead
) /* (TimerElemPtr *qhead) */
155 TimerElemPtr p
; /* parent pointer */
156 TimerElemPtr n
; /* current */
158 p
= (TimerElemPtr
)qhead
;
159 if (p
->link
) { /* Is anything on queue? */
160 p
->link
->timer
--; /* Yes, decrement by a tick */
161 while ((n
= p
->link
) &&
162 (n
->timer
== 0)) /* Next guy needs to be serviced */
164 p
->link
= n
->link
; /* Unlink us */
169 p
= (TimerElemPtr
)qhead
;