Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
21 | CVS : $Id: qqueue.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $ |
||
22 | |||
23 | File: $File$ |
||
24 | Revision: $Revision: 1.1.1.1 $ |
||
25 | Last update: $Date: 2002-03-29 14:12:52 $ |
||
26 | ------------ |
||
27 | |||
28 | This file contains the system queues function management |
||
29 | The functions use the general process descriptor table entries, |
||
30 | particularly the next & prev to mantain the queues order; |
||
31 | the insertion is based on the field priority, inserted in generic process |
||
32 | descriptor to simplify the implementation of many schedulers (like EDF, |
||
33 | RM, DM, etc.) |
||
34 | |||
35 | There are 2 queue types: |
||
36 | QUEUE -> a simple queue with only head. |
||
37 | QQUEUE -> a queue that manage the head and the tail of the queue |
||
38 | |||
39 | ... and 2 queue function sets, beginning with q_ if related to the type |
||
40 | QUEUE, qq_ if related to the other type. |
||
41 | |||
42 | The queue insertion is made by the following functions: |
||
43 | q_insert, qq_insert -> insertion based on the priority field. |
||
44 | q_timespec_insert, qq_timespec_insert -> same as above but use |
||
45 | the timespec_priority field |
||
46 | q_insertfirst, qq_insertfirst -> insert in the first position of the queue |
||
47 | |||
48 | **/ |
||
49 | |||
50 | /* |
||
51 | * Copyright (C) 2000 Paolo Gai |
||
52 | * |
||
53 | * This program is free software; you can redistribute it and/or modify |
||
54 | * it under the terms of the GNU General Public License as published by |
||
55 | * the Free Software Foundation; either version 2 of the License, or |
||
56 | * (at your option) any later version. |
||
57 | * |
||
58 | * This program is distributed in the hope that it will be useful, |
||
59 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
60 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
61 | * GNU General Public License for more details. |
||
62 | * |
||
63 | * You should have received a copy of the GNU General Public License |
||
64 | * along with this program; if not, write to the Free Software |
||
65 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
66 | * |
||
67 | */ |
||
68 | |||
69 | |||
70 | #include <kernel/const.h> |
||
71 | #include <sys/types.h> |
||
72 | #include <kernel/var.h> |
||
73 | |||
74 | /* |
||
75 | * |
||
76 | * QQUEUE Functions |
||
77 | * |
||
78 | */ |
||
79 | |||
80 | /*+ This function initialize a QQUEUE +*/ |
||
81 | void qq_init(QQUEUE *que) |
||
82 | { |
||
83 | que->first = NIL; |
||
84 | que->last = NIL; |
||
85 | } |
||
86 | |||
87 | |||
88 | /*+ |
||
89 | This function insert the task with PID p in the queue que. |
||
90 | The insertion is made respecting the priority field. |
||
91 | (the first item in the queue have the less priority) |
||
92 | +*/ |
||
93 | void qq_insert(PID i, QQUEUE *que) |
||
94 | { |
||
95 | DWORD prio; |
||
96 | PID p,q; |
||
97 | |||
98 | p = NIL; |
||
99 | q = que->first; |
||
100 | prio = proc_table[i].priority; |
||
101 | |||
102 | while ((q != NIL) && (prio >= proc_table[q].priority)) { |
||
103 | p = q; |
||
104 | q = proc_table[q].next; |
||
105 | } |
||
106 | |||
107 | if (p != NIL) |
||
108 | proc_table[p].next = i; |
||
109 | else |
||
110 | que->first = i; |
||
111 | |||
112 | if (q != NIL) |
||
113 | proc_table[q].prev = i; |
||
114 | else |
||
115 | que->last = i; |
||
116 | |||
117 | proc_table[i].next = q; |
||
118 | proc_table[i].prev = p; |
||
119 | } |
||
120 | |||
121 | /*+ |
||
122 | This function insert the task with PID p in the queue que. |
||
123 | The insertion is made respecting the timespec priority field. |
||
124 | (the first item in the queue have the less priority) |
||
125 | +*/ |
||
126 | void qq_timespec_insert(PID i, QQUEUE *que) |
||
127 | { |
||
128 | struct timespec prio; |
||
129 | PID p,q; |
||
130 | |||
131 | p = NIL; |
||
132 | q = que->first; |
||
133 | TIMESPEC_ASSIGN(&prio, &proc_table[i].timespec_priority); |
||
134 | |||
135 | |||
136 | while ((q != NIL) && |
||
137 | !TIMESPEC_A_LT_B(&prio, &proc_table[q].timespec_priority)) { |
||
138 | p = q; |
||
139 | q = proc_table[q].next; |
||
140 | } |
||
141 | |||
142 | if (p != NIL) |
||
143 | proc_table[p].next = i; |
||
144 | else |
||
145 | que->first = i; |
||
146 | |||
147 | if (q != NIL) |
||
148 | proc_table[q].prev = i; |
||
149 | else |
||
150 | que->last = i; |
||
151 | |||
152 | proc_table[i].next = q; |
||
153 | proc_table[i].prev = p; |
||
154 | } |
||
155 | |||
156 | /*+ |
||
157 | This function extract the task i from the queue que. |
||
158 | It not check if the task i is REALLY IN the queue que... |
||
159 | so make attention!!! |
||
160 | +*/ |
||
161 | void qq_extract(PID i, QQUEUE *que) |
||
162 | { |
||
163 | PID p,q; |
||
164 | |||
165 | p = proc_table[i].prev; |
||
166 | q = proc_table[i].next; |
||
167 | |||
168 | if (p != NIL) |
||
169 | proc_table[p].next = proc_table[i].next; |
||
170 | else |
||
171 | que->first = q; |
||
172 | |||
173 | if (q != NIL) |
||
174 | proc_table[q].prev = proc_table[i].prev; |
||
175 | else |
||
176 | que->last = p; |
||
177 | |||
178 | } |
||
179 | |||
180 | /*+ |
||
181 | This function returns the first task in the queue que, or NIL if the |
||
182 | queue is empty... (it extracts the task from the queue...) |
||
183 | +*/ |
||
184 | PID qq_getfirst(QQUEUE *q) |
||
185 | { |
||
186 | PID p = q->first; |
||
187 | |||
188 | if (p == NIL) return(NIL); |
||
189 | q->first = proc_table[q->first].next; |
||
190 | |||
191 | if (q->first != NIL) |
||
192 | proc_table[q->first].prev = NIL; |
||
193 | else |
||
194 | q->last = NIL; |
||
195 | |||
196 | return(p); |
||
197 | } |
||
198 | |||
199 | /*+ |
||
200 | This function insert the task with PID p in the first position |
||
201 | of the queue que redardless of the priority field |
||
202 | +*/ |
||
203 | |||
204 | void qq_insertfirst(PID p, QQUEUE *que) |
||
205 | { |
||
206 | if (que->first != NIL) { |
||
207 | proc_table[p].next = que->first; |
||
208 | proc_table[que->first].prev = p; |
||
209 | } |
||
210 | else { |
||
211 | que->last = p; |
||
212 | proc_table[p].next = NIL; |
||
213 | } |
||
214 | proc_table[p].prev = NIL; |
||
215 | que->first = p; |
||
216 | } |
||
217 | |||
218 | /*+ |
||
219 | This function insert the task with PID p in the last position |
||
220 | of the queue que redardless of the priority field |
||
221 | +*/ |
||
222 | |||
223 | void qq_insertlast(PID p, QQUEUE *que) |
||
224 | { |
||
225 | if (que->last != NIL) { |
||
226 | proc_table[p].prev = que->last; |
||
227 | proc_table[que->last].next = p; |
||
228 | } |
||
229 | else { |
||
230 | que->first = p; |
||
231 | proc_table[p].prev = NIL; |
||
232 | } |
||
233 | proc_table[p].next = NIL; |
||
234 | que->last = p; |
||
235 | } |
||
236 | |||
237 | /*+ |
||
238 | This function returns the first task in the queue que, without removing it |
||
239 | +*/ |
||
240 | PID qq_queryfirst(QQUEUE *q) |
||
241 | { |
||
242 | return q->first; |
||
243 | } |
||
244 | |||
245 | /*+ |
||
246 | This function returns the last task in the queue que, without removing it |
||
247 | +*/ |
||
248 | PID qq_querylast(QQUEUE *q) |
||
249 | { |
||
250 | return q->last; |
||
251 | } |
||
252 |