Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1624 giacomo 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: iqueue.h,v 1.1.1.1 2004-05-24 17:54:51 giacomo Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2004-05-24 17:54:51 $
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 <kernel/const.h>
72
#include <kernel/types.h>
73
#include <sys/types.h>
74
 
75
#define IQUEUE_NO_PRIORITY 1
76
#define IQUEUE_NO_TIMESPEC 2
77
 
78
struct IQUEUE_shared {
79
  PID prev[MAX_PROC];
80
  PID next[MAX_PROC];
81
  struct timespec *timespec_priority;
82
  DWORD *priority;
83
};
84
 
85
typedef struct {
86
  PID first;
87
  PID last;
88
  struct IQUEUE_shared *s;
89
} IQUEUE;
90
 
91
 
92
 
93
/* Internal queue initialization:
94
 
95
   share = &x -> the internal data structure of the IQUEUE x is used
96
                 to enqueue the tasks.  
97
 
98
   share = NULL -> an internal data structure to handle prev/next
99
                   pairs is dynamically allocated (The amount of
100
                   memory that is allocated can be reduced using the
101
                   flags).
102
 
103
   flags can be used to reduce the memory usage of an IQUEUE when share=NULL:
104
   IQUEUE_NO_PRIORITY -> the iqueue do not provide internally a priority field
105
   IQUEUE_NO_TIMESPEC -> the iqueue do not provide internally a timespec field
106
 
107
   - note that, if these flags are used, the corresponding insert
108
     functions will not work!
109
   - the default value for the flags is, of course, 0
110
*/
111
void iq_init (IQUEUE *q, IQUEUE *share, int flags);
112
 
113
/* Queue insert functions:
114
 
115
   - inserts a p into the q. p must not be already inserted into q.
116
   - four versions of the function;
117
     - iq_priority_insert -> ordered insertion using the priority field
118
     - iq_timespec_insert -> ordered insertion using the timespec field
119
     - iq_insertfirst     -> insert at the first position of the queue
120
     - iq_insertlast      -> insert at the last position of the queue
121
*/
122
void iq_priority_insert (PID p, IQUEUE *q);
123
void iq_timespec_insert (PID p, IQUEUE *q);
124
void iq_insertfirst     (PID p, IQUEUE *q);
125
void iq_insertlast      (PID p, IQUEUE *q);
126
 
127
/* Queue extract functions:
128
 
129
   - extracts a task p from the queue q.
130
   - three versions of the function;
131
     - iq_extract -> extracts given a task p
132
                     (that must be inserted in the queue)
133
 
134
     - iq_getfirst -> extracts the first task in the queue,
135
                      NIL if the queue is empty
136
 
137
     - iq_getlast -> extracts the last task in the queue,
138
                     NIL if the queue is empty
139
 
140
*/
141
void iq_extract         (PID p, IQUEUE *q);
142
PID  iq_getfirst        (       IQUEUE *q);
143
PID  iq_getlast         (       IQUEUE *q);
144
 
145
 
146
/* Queue query functions:
147
 
148
   The first two functions return the first and the last task in the queue,
149
   NIL if the queue is empty.
150
 
151
   The second two functions can be used to get/set the priority or the
152
   timespec field used when queuing.
153
*/
154
static __inline__ PID iq_queryfirst(IQUEUE *q)
155
{
156
  return q->first;
157
}
158
 
159
static __inline__ PID iq_querylast(IQUEUE *q)
160
{
161
  return q->last;
162
}
163
 
164
static __inline__ struct timespec *iq_query_timespec(PID p, IQUEUE *q)
165
{
166
  return &q->s->timespec_priority[p];
167
}
168
 
169
static __inline__ DWORD *iq_query_priority (PID p, IQUEUE *q)
170
{
171
  return &q->s->priority[p];
172
}