Rev 79 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | 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 | ------------ |
||
79 | pj | 21 | CVS : $Id: iqueue.h,v 1.2 2003-03-13 13:36:28 pj Exp $ |
29 | pj | 22 | |
23 | File: $File$ |
||
79 | pj | 24 | Revision: $Revision: 1.2 $ |
25 | Last update: $Date: 2003-03-13 13:36:28 $ |
||
29 | pj | 26 | ------------ |
27 | |||
28 | */ |
||
29 | |||
30 | /* |
||
31 | * Copyright (C) 2002 Paolo Gai |
||
32 | * |
||
33 | * This program is free software; you can redistribute it and/or modify |
||
34 | * it under the terms of the GNU General Public License as published by |
||
35 | * the Free Software Foundation; either version 2 of the License, or |
||
36 | * (at your option) any later version. |
||
37 | * |
||
38 | * This program is distributed in the hope that it will be useful, |
||
39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
41 | * GNU General Public License for more details. |
||
42 | * |
||
43 | * You should have received a copy of the GNU General Public License |
||
44 | * along with this program; if not, write to the Free Software |
||
45 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
46 | * |
||
47 | */ |
||
48 | |||
49 | |||
50 | /* |
||
51 | IQUEUEs |
||
52 | |||
53 | This file contains functions that helps to manage task queues. |
||
54 | |||
55 | These functions are different from the functions that manages the |
||
56 | QUEUE and QQUEUE types. In particular, these functions no more relies |
||
57 | on the prev & next fields of the task descriptor. In that way, tasks |
||
58 | can be inserted in more than one queue at a time. |
||
59 | |||
60 | Basically, an IQUEUE has an "I"nternal prev/next structure, that may |
||
61 | be shared between one or more queue. Of course, the user MUST |
||
62 | guarantee that the same task will not be inserted in two IQUEUEs that |
||
63 | share the same prev/next buffer. |
||
64 | |||
65 | The queue insertion is made by the following functions: |
||
66 | iq_insert -> insertion based on the priority field. |
||
67 | iq_timespec_insert -> same as above but use the timespec_priority field |
||
68 | iq_insertfirst -> insert in the first position of the queue |
||
69 | */ |
||
70 | |||
71 | #include <ll/ll.h> |
||
72 | #include <kernel/const.h> |
||
73 | #include <kernel/types.h> |
||
74 | |||
75 | #ifndef __KERNEL_IQUEUE_H__ |
||
76 | #define __KERNEL_IQUEUE_H__ |
||
77 | |||
1689 | fabio | 78 | #include <arch/sys/cdefs.h> |
79 | pj | 79 | |
80 | __BEGIN_DECLS |
||
81 | |||
29 | pj | 82 | #define IQUEUE_NO_PRIORITY 1 |
83 | #define IQUEUE_NO_TIMESPEC 2 |
||
84 | |||
85 | struct IQUEUE_shared { |
||
86 | PID prev[MAX_PROC]; |
||
87 | PID next[MAX_PROC]; |
||
88 | struct timespec *timespec_priority; |
||
89 | DWORD *priority; |
||
90 | }; |
||
91 | |||
92 | typedef struct { |
||
93 | PID first; |
||
94 | PID last; |
||
95 | struct IQUEUE_shared *s; |
||
96 | } IQUEUE; |
||
97 | |||
98 | |||
99 | |||
100 | /* Internal queue initialization: |
||
101 | |||
102 | share = &x -> the internal data structure of the IQUEUE x is used |
||
103 | to enqueue the tasks. |
||
104 | |||
105 | share = NULL -> an internal data structure to handle prev/next |
||
106 | pairs is dynamically allocated (The amount of |
||
107 | memory that is allocated can be reduced using the |
||
108 | flags). |
||
109 | |||
110 | flags can be used to reduce the memory usage of an IQUEUE when share=NULL: |
||
111 | IQUEUE_NO_PRIORITY -> the iqueue do not provide internally a priority field |
||
112 | IQUEUE_NO_TIMESPEC -> the iqueue do not provide internally a timespec field |
||
113 | |||
114 | - note that, if these flags are used, the corresponding insert |
||
115 | functions will not work! |
||
116 | - the default value for the flags is, of course, 0 |
||
117 | */ |
||
118 | void iq_init (IQUEUE *q, IQUEUE *share, int flags); |
||
119 | |||
120 | /* Queue insert functions: |
||
121 | |||
122 | - inserts a p into the q. p must not be already inserted into q. |
||
123 | - four versions of the function; |
||
124 | - iq_priority_insert -> ordered insertion using the priority field |
||
125 | - iq_timespec_insert -> ordered insertion using the timespec field |
||
126 | - iq_insertfirst -> insert at the first position of the queue |
||
127 | - iq_insertlast -> insert at the last position of the queue |
||
128 | */ |
||
129 | void iq_priority_insert (PID p, IQUEUE *q); |
||
130 | void iq_timespec_insert (PID p, IQUEUE *q); |
||
131 | void iq_insertfirst (PID p, IQUEUE *q); |
||
132 | void iq_insertlast (PID p, IQUEUE *q); |
||
133 | |||
134 | /* Queue extract functions: |
||
135 | |||
136 | - extracts a task p from the queue q. |
||
137 | - three versions of the function; |
||
138 | - iq_extract -> extracts given a task p |
||
139 | (that must be inserted in the queue) |
||
140 | |||
141 | - iq_getfirst -> extracts the first task in the queue, |
||
142 | NIL if the queue is empty |
||
143 | |||
144 | - iq_getlast -> extracts the last task in the queue, |
||
145 | NIL if the queue is empty |
||
146 | |||
147 | */ |
||
148 | void iq_extract (PID p, IQUEUE *q); |
||
149 | PID iq_getfirst ( IQUEUE *q); |
||
150 | PID iq_getlast ( IQUEUE *q); |
||
151 | |||
152 | |||
153 | /* Queue query functions: |
||
154 | |||
155 | The first two functions return the first and the last task in the queue, |
||
156 | NIL if the queue is empty. |
||
157 | |||
158 | The second two functions can be used to get/set the priority or the |
||
159 | timespec field used when queuing. |
||
160 | */ |
||
161 | static __inline__ PID iq_query_first(IQUEUE *q) |
||
162 | { |
||
163 | return q->first; |
||
164 | } |
||
165 | |||
166 | static __inline__ PID iq_query_last(IQUEUE *q) |
||
167 | { |
||
168 | return q->last; |
||
169 | } |
||
170 | |||
171 | static __inline__ struct timespec *iq_query_timespec(PID p, IQUEUE *q) |
||
172 | { |
||
173 | return &q->s->timespec_priority[p]; |
||
174 | } |
||
175 | |||
176 | static __inline__ DWORD *iq_query_priority (PID p, IQUEUE *q) |
||
177 | { |
||
178 | return &q->s->priority[p]; |
||
179 | } |
||
180 | |||
181 | /* Queue iterators */ |
||
182 | |||
183 | /* sometimes it is useful to go through the list. For that reason |
||
184 | You can use the following two functions... */ |
||
185 | static __inline__ PID iq_query_next (PID p, IQUEUE *q) |
||
186 | { |
||
187 | return q->s->next[p]; |
||
188 | } |
||
189 | |||
190 | static __inline__ PID iq_query_prev (PID p, IQUEUE *q) |
||
191 | { |
||
192 | return q->s->prev[p]; |
||
193 | } |
||
194 | |||
195 | /* Queue test functions */ |
||
196 | static __inline__ int iq_isempty (IQUEUE *q) |
||
197 | { |
||
198 | return q->first == NIL; |
||
199 | } |
||
200 | |||
79 | pj | 201 | __END_DECLS |
29 | pj | 202 | #endif |