]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
1c79356b | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * TimerElem.c | |
24 | * | |
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. | |
28 | */ | |
29 | ||
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> | |
36 | #include <sys/proc.h> | |
37 | #include <sys/filedesc.h> | |
38 | #include <sys/fcntl.h> | |
39 | #include <sys/mbuf.h> | |
40 | #include <sys/socket.h> | |
41 | ||
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> | |
48 | ||
1c79356b A |
49 | |
50 | extern void DoTimerElem(); /* (TimerElemPtr t); | |
51 | * External routine called to | |
52 | * process each one. */ | |
53 | ||
54 | /* | |
55 | * InsertTimerElem | |
56 | * | |
57 | * INPUTS: | |
58 | * qhead Address of ptr to first item in list | |
59 | * t timer element to link in | |
60 | * vbl timer value to use | |
61 | * OUTPUTS: | |
62 | * void | |
63 | */ | |
64 | void InsertTimerElem(qhead, t, val) | |
65 | /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */ | |
66 | TimerElemPtr *qhead, t; | |
67 | int val; | |
68 | { | |
69 | TimerElemPtr p; /* parent pointer */ | |
70 | TimerElemPtr n; /* current */ | |
c0fea474 | 71 | |
1c79356b A |
72 | if (t->onQ) { |
73 | /* | |
c0fea474 A |
74 | * someone else beat us to the punch and put this |
75 | * element back on the queue, just return in this case | |
76 | */ | |
77 | return; | |
1c79356b A |
78 | } |
79 | p = (TimerElemPtr)qhead; | |
80 | ||
81 | while (n = p->link) { | |
82 | if (val <= n->timer) /* Do we go in front of this? */ | |
83 | { | |
84 | n->timer -= val; /* Yes, adjust his delta */ | |
85 | break; /* and go link us in */ | |
86 | } | |
87 | val -= n->timer; /* No, subtract off delta from our value */ | |
88 | p = n; | |
89 | } /* while */ | |
90 | ||
91 | /* It must go after item pointed to by p and in front of item | |
92 | * pointed to by n */ | |
93 | ||
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 */ | |
98 | ||
1c79356b A |
99 | } |
100 | ||
101 | ||
102 | /* | |
103 | * RemoveTimerElem | |
104 | * | |
105 | * INPUTS: | |
106 | * qhead Address of ptr to first item in list | |
107 | * t timer element to link in | |
108 | * OUTPUTS: | |
109 | * void | |
110 | */ | |
111 | void RemoveTimerElem(qhead, t) /* (TimerElemPtr *qhead, TimerElemPtr t) */ | |
112 | TimerElemPtr *qhead, t; | |
113 | { | |
114 | TimerElemPtr p; /* parent pointer */ | |
115 | TimerElemPtr n; /* current */ | |
c0fea474 | 116 | |
1c79356b A |
117 | if ( !t->onQ) { |
118 | /* | |
c0fea474 A |
119 | * someone else beat us to the punch and took this |
120 | * element off of the queue, just return in this case | |
121 | */ | |
122 | return; | |
1c79356b A |
123 | } |
124 | p = (TimerElemPtr)qhead; | |
125 | ||
126 | while (n = p->link) /* Get next item in queue */ | |
127 | { | |
128 | if (n == t) /* Is it us? */ | |
129 | { | |
130 | if (p->link = n->link) /* Link our parent to our child */ | |
131 | { | |
132 | n->link->timer += t->timer; /* and update child's timer */ | |
133 | } | |
134 | n->onQ = 0; /* Not on linked list anymore */ | |
135 | break; | |
136 | } | |
137 | p = n; | |
138 | } /* while */ | |
139 | ||
1c79356b A |
140 | } |
141 | ||
142 | ||
143 | /* | |
144 | * TimerQueueTick | |
145 | * | |
146 | * INPUTS: | |
147 | * qhead Address of ptr to first item in list | |
148 | * | |
149 | * OUTPUTS: | |
150 | * void | |
151 | */ | |
152 | void TimerQueueTick(qhead) /* (TimerElemPtr *qhead) */ | |
153 | TimerElemPtr *qhead; | |
154 | { | |
155 | TimerElemPtr p; /* parent pointer */ | |
156 | TimerElemPtr n; /* current */ | |
c0fea474 | 157 | |
1c79356b | 158 | p = (TimerElemPtr)qhead; |
c0fea474 | 159 | if (p->link) { /* Is anything on queue? */ |
1c79356b | 160 | p->link->timer--; /* Yes, decrement by a tick */ |
c0fea474 A |
161 | while ((n = p->link) && |
162 | (n->timer == 0)) /* Next guy needs to be serviced */ | |
163 | { | |
164 | p->link = n->link; /* Unlink us */ | |
165 | n->onQ = 0; | |
1c79356b | 166 | |
c0fea474 | 167 | DoTimerElem(n); |
1c79356b | 168 | |
c0fea474 A |
169 | p = (TimerElemPtr)qhead; |
170 | } /* while */ | |
171 | } | |
1c79356b | 172 | } |