Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
gqueue.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GQUEUECONTROL
 

Macros

#define TRUE   1
 
#define FALSE   0
 
#define MAXSIZE_QUEUE_READ_GATES   5
 
#define QUEUE_READ_GATE_0   0
 
#define QUEUE_READ_GATE_1   1
 
#define QUEUE_READ_GATE_2   2
 
#define QUEUE_READ_GATE_3   3
 
#define QUEUE_READ_GATE_4   4
 
#define GQUEUE_RTAI_SUPPORT   0
 

Typedefs

typedef struct GQUEUECONTROLPGQUEUECONTROL
 

Functions

int gQUEUE_Init (PGQUEUECONTROL pQueueControl, int Size, int NReaders)
 
int gQUEUE_GetReadIndex (PGQUEUECONTROL pQueueControl, int NReader, int *Index, int IndexHorizon)
 
int gQUEUE_GetWriteIndex (PGQUEUECONTROL pQueueControl, int *Index, int IndexHorizon)
 
int gQUEUE_RequestReadIndex (PGQUEUECONTROL pQueueControl, int NReader, int *Index)
 
int gQUEUE_RequestWriteIndex (PGQUEUECONTROL pQueueControl, int *Index)
 
int gQUEUE_RequestLastReadIndex (PGQUEUECONTROL pQueueControl, int NReader, int *Index)
 
int gQUEUE_UnwrapWriteIndex (PGQUEUECONTROL pQueueControl)
 
int gQUEUE_UnwrapReadIndex (PGQUEUECONTROL pQueueControl, int NReader)
 
int gQUEUE_GetNumberOfUnreadData (PGQUEUECONTROL pQueueControl, int NReader, int *Index)
 

Macro Definition Documentation

#define FALSE   0

Definition at line 20 of file gqueue.h.

#define GQUEUE_RTAI_SUPPORT   0

Definition at line 29 of file gqueue.h.

#define MAXSIZE_QUEUE_READ_GATES   5

Definition at line 22 of file gqueue.h.

Referenced by gQUEUE_Init().

#define QUEUE_READ_GATE_0   0

Definition at line 23 of file gqueue.h.

#define QUEUE_READ_GATE_1   1

Definition at line 24 of file gqueue.h.

#define QUEUE_READ_GATE_2   2

Definition at line 25 of file gqueue.h.

#define QUEUE_READ_GATE_3   3

Definition at line 26 of file gqueue.h.

#define QUEUE_READ_GATE_4   4

Definition at line 27 of file gqueue.h.

#define TRUE   1

Definition at line 19 of file gqueue.h.

Typedef Documentation

typedef struct GQUEUECONTROL * PGQUEUECONTROL

Function Documentation

int gQUEUE_GetNumberOfUnreadData ( PGQUEUECONTROL  pQueueControl,
int  NReader,
int *  Index 
)

Definition at line 314 of file gqueue.c.

References FALSE, GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, GQUEUECONTROL::Size, TRUE, and GQUEUECONTROL::WriteIndex.

Referenced by gDataLogger_IPCUpdate(), and gDataLogger_MatfileUpdate().

315 {
316  if(NReader>=pQueueControl->NReaders){
317  return FALSE;
318  }
319 
320  if(pQueueControl->WriteIndex >= pQueueControl->ReadIndex[NReader]){
321  *Index = pQueueControl->WriteIndex-pQueueControl->ReadIndex[NReader];
322  }
323  else{
324  *Index = pQueueControl->Size-(pQueueControl->ReadIndex[NReader]-pQueueControl->WriteIndex);
325  }
326 
327  return TRUE;
328 }
#define FALSE
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37
int Size
Definition: gqueue.h:36

Here is the caller graph for this function:

int gQUEUE_GetReadIndex ( PGQUEUECONTROL  pQueueControl,
int  NReader,
int *  Index,
int  IndexHorizon 
)

Definition at line 166 of file gqueue.c.

References BEGIN_ATOMIC, END_ATOMIC, FALSE, GQUEUECONTROL::FlagStillNotWritten, gQUEUE_UnwrapReadIndex(), GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, GQUEUECONTROL::Size, and TRUE.

167 {
168  if(NReader>=pQueueControl->NReaders){
169  return FALSE;
170  }
171 
172  if(pQueueControl->FlagStillNotWritten == TRUE){
173  return FALSE;
174  }
175 
176 BEGIN_ATOMIC();
177 
178  *Index = (pQueueControl->ReadIndex[NReader]-IndexHorizon);
179  if(*Index<0){
180  *Index += pQueueControl->Size;
181  }
182  gQUEUE_UnwrapReadIndex(pQueueControl, NReader);
183 
184 END_ATOMIC();
185 
186 
187  return TRUE;
188 }
#define FALSE
#define END_ATOMIC()
Definition: gqueue.c:18
int gQUEUE_UnwrapReadIndex(PGQUEUECONTROL pQueueControl, int NReader)
Definition: gqueue.c:277
#define BEGIN_ATOMIC()
Definition: gqueue.c:17
#define TRUE
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37
int Size
Definition: gqueue.h:36

Here is the call graph for this function:

int gQUEUE_GetWriteIndex ( PGQUEUECONTROL  pQueueControl,
int *  Index,
int  IndexHorizon 
)

Definition at line 203 of file gqueue.c.

References BEGIN_ATOMIC, END_ATOMIC, FALSE, GQUEUECONTROL::FlagStillNotWritten, gQUEUE_UnwrapWriteIndex(), GQUEUECONTROL::Size, TRUE, and GQUEUECONTROL::WriteIndex.

204 {
205 
206  if(pQueueControl->FlagStillNotWritten == TRUE){
207  return FALSE;
208  }
209 
210 BEGIN_ATOMIC();
211 
212  *Index = (pQueueControl->WriteIndex-IndexHorizon);
213  if(*Index<0){
214  *Index += pQueueControl->Size;
215  }
216  gQUEUE_UnwrapWriteIndex(pQueueControl);
217 
218 END_ATOMIC();
219 
220  return TRUE;
221 }
int gQUEUE_UnwrapWriteIndex(PGQUEUECONTROL pQueueControl)
Definition: gqueue.c:297
#define FALSE
#define END_ATOMIC()
Definition: gqueue.c:18
#define BEGIN_ATOMIC()
Definition: gqueue.c:17
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int FlagStillNotWritten
Definition: gqueue.h:43
int Size
Definition: gqueue.h:36

Here is the call graph for this function:

int gQUEUE_Init ( PGQUEUECONTROL  pQueueControl,
int  Size,
int  NReaders 
)

Definition at line 31 of file gqueue.c.

References FALSE, GQUEUECONTROL::FlagFull, GQUEUECONTROL::FlagStillNotRead, GQUEUECONTROL::FlagStillNotWritten, MAXSIZE_QUEUE_READ_GATES, GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, GQUEUECONTROL::Size, TRUE, and GQUEUECONTROL::WriteIndex.

Referenced by gDataLogger_DeclareVariable().

32 {
33  int n;
34 
35  if(NReaders > MAXSIZE_QUEUE_READ_GATES){
36  return FALSE;
37  }
38 
39  pQueueControl->Size = Size,
40  pQueueControl->NReaders = NReaders;
41  pQueueControl->FlagStillNotWritten = TRUE;
42  for(n=0;n<NReaders;++n){
43  pQueueControl->ReadIndex[n] = 0;
44  pQueueControl->FlagStillNotRead[n] = TRUE;
45  pQueueControl->FlagFull[n] = FALSE;
46  }
47  pQueueControl->WriteIndex = 0;
48 
49 #if GQUEUE_RTAI_SUPPORT
50  rt_spl_init(&pQueueControl->SPLAtomicAccess);
51 #endif
52  return TRUE;
53 }
int FlagFull[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:45
#define FALSE
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int FlagStillNotRead[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:44
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37
#define MAXSIZE_QUEUE_READ_GATES
Definition: gqueue.h:22
int Size
Definition: gqueue.h:36

Here is the caller graph for this function:

int gQUEUE_RequestLastReadIndex ( PGQUEUECONTROL  pQueueControl,
int  NReader,
int *  Index 
)

Definition at line 67 of file gqueue.c.

References BEGIN_ATOMIC, END_ATOMIC, FALSE, GQUEUECONTROL::FlagFull, GQUEUECONTROL::FlagStillNotRead, GQUEUECONTROL::FlagStillNotWritten, gQUEUE_UnwrapReadIndex(), GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, TRUE, and GQUEUECONTROL::WriteIndex.

68 {
69  if(NReader>=pQueueControl->NReaders){
70  return FALSE;
71  }
72 
73  if(pQueueControl->FlagStillNotWritten == TRUE){
74  return FALSE;
75  }
76 
77 BEGIN_ATOMIC();
78 
79  if(pQueueControl->FlagStillNotRead[NReader] == TRUE){
80  pQueueControl->ReadIndex[NReader] = pQueueControl->WriteIndex;
81  *Index = pQueueControl->ReadIndex[NReader];
82  pQueueControl->FlagStillNotRead[NReader] = FALSE;
83  }
84  else{
85  if(pQueueControl->ReadIndex[NReader] == pQueueControl->WriteIndex){
86  pQueueControl->FlagFull[NReader] = FALSE;
87  *Index = -1;
88  }
89  else{
90  pQueueControl->ReadIndex[NReader] = pQueueControl->WriteIndex;
91  gQUEUE_UnwrapReadIndex(pQueueControl,NReader);
92  *Index = pQueueControl->ReadIndex[NReader];
93  }
94  }
95 
96 END_ATOMIC();
97 
98  if(*Index==-1){
99  return FALSE;
100  }
101 
102  return TRUE;
103 }
int FlagFull[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:45
#define FALSE
#define END_ATOMIC()
Definition: gqueue.c:18
int gQUEUE_UnwrapReadIndex(PGQUEUECONTROL pQueueControl, int NReader)
Definition: gqueue.c:277
#define BEGIN_ATOMIC()
Definition: gqueue.c:17
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int FlagStillNotRead[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:44
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37

Here is the call graph for this function:

int gQUEUE_RequestReadIndex ( PGQUEUECONTROL  pQueueControl,
int  NReader,
int *  Index 
)

Definition at line 117 of file gqueue.c.

References BEGIN_ATOMIC, END_ATOMIC, FALSE, GQUEUECONTROL::FlagFull, GQUEUECONTROL::FlagStillNotRead, GQUEUECONTROL::FlagStillNotWritten, gQUEUE_UnwrapReadIndex(), GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, TRUE, and GQUEUECONTROL::WriteIndex.

Referenced by gDataLogger_IPCUpdate(), and gDataLogger_MatfileUpdate().

118 {
119  if(NReader>=pQueueControl->NReaders){
120  return FALSE;
121  }
122 
123  if(pQueueControl->FlagStillNotWritten == TRUE){
124  return FALSE;
125  }
126 
127 BEGIN_ATOMIC();
128  if(pQueueControl->FlagStillNotRead[NReader] == TRUE){
129  *Index = pQueueControl->ReadIndex[NReader];
130  pQueueControl->FlagStillNotRead[NReader] = FALSE;
131  }
132  else{
133  if(pQueueControl->ReadIndex[NReader] == pQueueControl->WriteIndex){
134  pQueueControl->FlagFull[NReader] = FALSE;
135  *Index = -1;
136  }
137  else{
138  ++pQueueControl->ReadIndex[NReader];
139  gQUEUE_UnwrapReadIndex(pQueueControl,NReader);
140  *Index = pQueueControl->ReadIndex[NReader];
141  }
142  }
143 END_ATOMIC();
144 
145  if(*Index==-1){
146  return FALSE;
147  }
148 
149  return TRUE;
150 }
int FlagFull[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:45
#define FALSE
#define END_ATOMIC()
Definition: gqueue.c:18
int gQUEUE_UnwrapReadIndex(PGQUEUECONTROL pQueueControl, int NReader)
Definition: gqueue.c:277
#define BEGIN_ATOMIC()
Definition: gqueue.c:17
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int FlagStillNotRead[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:44
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

int gQUEUE_RequestWriteIndex ( PGQUEUECONTROL  pQueueControl,
int *  Index 
)

Definition at line 233 of file gqueue.c.

References BEGIN_ATOMIC, END_ATOMIC, FALSE, GQUEUECONTROL::FlagFull, GQUEUECONTROL::FlagStillNotWritten, gQUEUE_UnwrapWriteIndex(), GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, GQUEUECONTROL::Size, TRUE, and GQUEUECONTROL::WriteIndex.

Referenced by gDataLogger_InsertVariable().

234 {
235  int n;
236  int FlagNotFull = TRUE;
237 
238 BEGIN_ATOMIC();
239 
240  if(pQueueControl->FlagStillNotWritten == TRUE){
241  *Index = pQueueControl->WriteIndex;
242  pQueueControl->FlagStillNotWritten = FALSE;
243  }
244  else{
245  /* Increment write index in two positions to test if queue is full */
246  pQueueControl->WriteIndex += 2;
247  gQUEUE_UnwrapWriteIndex(pQueueControl);
248 
249  for(n=0;n<pQueueControl->NReaders;++n){
250  if(pQueueControl->ReadIndex[n] == pQueueControl->WriteIndex){
251  pQueueControl->FlagFull[n] = TRUE;
252  FlagNotFull = FALSE;
253  }
254  }
255 
256  /* Decrement write index of one position to return to the correct state */
257  pQueueControl->WriteIndex += pQueueControl->Size-1;
258  gQUEUE_UnwrapWriteIndex(pQueueControl);
259 
260  *Index = pQueueControl->WriteIndex;
261  }
262 
263 END_ATOMIC();
264 
265  return FlagNotFull;
266 }
int gQUEUE_UnwrapWriteIndex(PGQUEUECONTROL pQueueControl)
Definition: gqueue.c:297
int FlagFull[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:45
#define FALSE
#define END_ATOMIC()
Definition: gqueue.c:18
#define BEGIN_ATOMIC()
Definition: gqueue.c:17
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37
int Size
Definition: gqueue.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

int gQUEUE_UnwrapReadIndex ( PGQUEUECONTROL  pQueueControl,
int  NReader 
)

Definition at line 277 of file gqueue.c.

References FALSE, GQUEUECONTROL::NReaders, GQUEUECONTROL::ReadIndex, GQUEUECONTROL::Size, and TRUE.

Referenced by gQUEUE_GetReadIndex(), gQUEUE_RequestLastReadIndex(), and gQUEUE_RequestReadIndex().

278 {
279  if(NReader>=pQueueControl->NReaders){
280  return FALSE;
281  }
282 
283  pQueueControl->ReadIndex[NReader] = (pQueueControl->ReadIndex[NReader]) % (pQueueControl->Size);
284 
285  return TRUE;
286 }
#define FALSE
#define TRUE
int NReaders
Definition: gqueue.h:42
int ReadIndex[MAXSIZE_QUEUE_READ_GATES]
Definition: gqueue.h:37
int Size
Definition: gqueue.h:36

Here is the caller graph for this function:

int gQUEUE_UnwrapWriteIndex ( PGQUEUECONTROL  pQueueControl)

Definition at line 297 of file gqueue.c.

References GQUEUECONTROL::Size, TRUE, and GQUEUECONTROL::WriteIndex.

Referenced by gQUEUE_GetWriteIndex(), and gQUEUE_RequestWriteIndex().

298 {
299  pQueueControl->WriteIndex = (pQueueControl->WriteIndex) % (pQueueControl->Size);
300 
301  return TRUE;
302 }
int WriteIndex
Definition: gqueue.h:38
#define TRUE
int Size
Definition: gqueue.h:36

Here is the caller graph for this function: