]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
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 | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
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. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * TimerElem.c | |
32 | * | |
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. | |
36 | */ | |
37 | ||
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> | |
44 | #include <sys/proc.h> | |
45 | #include <sys/filedesc.h> | |
46 | #include <sys/fcntl.h> | |
47 | #include <sys/mbuf.h> | |
48 | #include <sys/socket.h> | |
49 | ||
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> | |
56 | ||
1c79356b A |
57 | |
58 | extern void DoTimerElem(); /* (TimerElemPtr t); | |
59 | * External routine called to | |
60 | * process each one. */ | |
61 | ||
62 | /* | |
63 | * InsertTimerElem | |
64 | * | |
65 | * INPUTS: | |
66 | * qhead Address of ptr to first item in list | |
67 | * t timer element to link in | |
68 | * vbl timer value to use | |
69 | * OUTPUTS: | |
70 | * void | |
71 | */ | |
72 | void InsertTimerElem(qhead, t, val) | |
73 | /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */ | |
74 | TimerElemPtr *qhead, t; | |
75 | int val; | |
76 | { | |
77 | TimerElemPtr p; /* parent pointer */ | |
78 | TimerElemPtr n; /* current */ | |
5d5c5d0d | 79 | |
1c79356b A |
80 | if (t->onQ) { |
81 | /* | |
5d5c5d0d A |
82 | * someone else beat us to the punch and put this |
83 | * element back on the queue, just return in this case | |
84 | */ | |
85 | return; | |
1c79356b A |
86 | } |
87 | p = (TimerElemPtr)qhead; | |
88 | ||
89 | while (n = p->link) { | |
90 | if (val <= n->timer) /* Do we go in front of this? */ | |
91 | { | |
92 | n->timer -= val; /* Yes, adjust his delta */ | |
93 | break; /* and go link us in */ | |
94 | } | |
95 | val -= n->timer; /* No, subtract off delta from our value */ | |
96 | p = n; | |
97 | } /* while */ | |
98 | ||
99 | /* It must go after item pointed to by p and in front of item | |
100 | * pointed to by n */ | |
101 | ||
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 */ | |
106 | ||
1c79356b A |
107 | } |
108 | ||
109 | ||
110 | /* | |
111 | * RemoveTimerElem | |
112 | * | |
113 | * INPUTS: | |
114 | * qhead Address of ptr to first item in list | |
115 | * t timer element to link in | |
116 | * OUTPUTS: | |
117 | * void | |
118 | */ | |
119 | void RemoveTimerElem(qhead, t) /* (TimerElemPtr *qhead, TimerElemPtr t) */ | |
120 | TimerElemPtr *qhead, t; | |
121 | { | |
122 | TimerElemPtr p; /* parent pointer */ | |
123 | TimerElemPtr n; /* current */ | |
5d5c5d0d | 124 | |
1c79356b A |
125 | if ( !t->onQ) { |
126 | /* | |
5d5c5d0d A |
127 | * someone else beat us to the punch and took this |
128 | * element off of the queue, just return in this case | |
129 | */ | |
130 | return; | |
1c79356b A |
131 | } |
132 | p = (TimerElemPtr)qhead; | |
133 | ||
134 | while (n = p->link) /* Get next item in queue */ | |
135 | { | |
136 | if (n == t) /* Is it us? */ | |
137 | { | |
138 | if (p->link = n->link) /* Link our parent to our child */ | |
139 | { | |
140 | n->link->timer += t->timer; /* and update child's timer */ | |
141 | } | |
142 | n->onQ = 0; /* Not on linked list anymore */ | |
143 | break; | |
144 | } | |
145 | p = n; | |
146 | } /* while */ | |
147 | ||
1c79356b A |
148 | } |
149 | ||
150 | ||
151 | /* | |
152 | * TimerQueueTick | |
153 | * | |
154 | * INPUTS: | |
155 | * qhead Address of ptr to first item in list | |
156 | * | |
157 | * OUTPUTS: | |
158 | * void | |
159 | */ | |
160 | void TimerQueueTick(qhead) /* (TimerElemPtr *qhead) */ | |
161 | TimerElemPtr *qhead; | |
162 | { | |
163 | TimerElemPtr p; /* parent pointer */ | |
164 | TimerElemPtr n; /* current */ | |
5d5c5d0d | 165 | |
1c79356b | 166 | p = (TimerElemPtr)qhead; |
5d5c5d0d | 167 | if (p->link) { /* Is anything on queue? */ |
1c79356b | 168 | p->link->timer--; /* Yes, decrement by a tick */ |
5d5c5d0d A |
169 | while ((n = p->link) && |
170 | (n->timer == 0)) /* Next guy needs to be serviced */ | |
171 | { | |
172 | p->link = n->link; /* Unlink us */ | |
173 | n->onQ = 0; | |
1c79356b | 174 | |
5d5c5d0d | 175 | DoTimerElem(n); |
1c79356b | 176 | |
5d5c5d0d A |
177 | p = (TimerElemPtr)qhead; |
178 | } /* while */ | |
179 | } | |
1c79356b | 180 | } |