Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
gqueue.h
Go to the documentation of this file.
1 /*****************************************************************************
2 // File: GQueue.h
3 // Contents: Header of C functions for circular queue access and control.
4 // Author: G. A. Borges.
5 // Description: Circular queues are FIFOS implemented with limited length vectors.
6 // Their control variables are defined in a structure named GQUEUECONTROL.
7 // It means that no data is stored in GQUEUECONTROL, but read/write indexes and
8 // control variables. The data is stored in a separate array. Indexes to access
9 // the array are computed using GQUEUECONTROL internal values.
10 // The circular queues may have up to MAXSIZE_QUEUE_READ_GATES reading heads but
11 // only one writing head.
12 //
13 //
14 *****************************************************************************/
15 
16 #ifndef GQUEUE_H
17 #define GQUEUE_H
18 
19 #define TRUE 1
20 #define FALSE 0
21 
22 #define MAXSIZE_QUEUE_READ_GATES 5
23 #define QUEUE_READ_GATE_0 0
24 #define QUEUE_READ_GATE_1 1
25 #define QUEUE_READ_GATE_2 2
26 #define QUEUE_READ_GATE_3 3
27 #define QUEUE_READ_GATE_4 4
28 
29 #define GQUEUE_RTAI_SUPPORT 0
30 
31 #if GQUEUE_RTAI_SUPPORT
32 #include <rtai_spl.h>
33 #endif
34 
35 typedef struct{
36  int Size;
37  int ReadIndex[MAXSIZE_QUEUE_READ_GATES];
39 #if GQUEUE_RTAI_SUPPORT
40  SPL SPLAtomicAccess;
41 #endif
42  int NReaders;
44  int FlagStillNotRead[MAXSIZE_QUEUE_READ_GATES];
45  int FlagFull[MAXSIZE_QUEUE_READ_GATES];
47 
48 /* Example:
49 #define QUEUESIZE 100
50 
51 double buffer[QUEUESIZE];
52 GQUEUECONTROL gQueueControlBuffer;
53 
54 gQUEUE_Init(&gQueueControlBuffer, QUEUESIZE, 1);
55 
56 int Index;
57 if(gQUEUE_RequestWriteIndex(&gQueueControlBuffer, &Index)){
58  buffer[Index] = 100;
59 }
60 
61 int Index;
62 if(gQUEUE_RequestReadIndex(&gQueueControlBuffer, QUEUE_READ_GATE_0, &Index)){
63  x = buffer[Index];
64 }
65 
66 */
67 
68 /* Prototypes: */
69 int gQUEUE_Init(PGQUEUECONTROL pQueueControl, int Size, int NReaders);
70 int gQUEUE_GetReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int* Index, int IndexHorizon);
71 int gQUEUE_GetWriteIndex(PGQUEUECONTROL pQueueControl, int* Index, int IndexHorizon);
72 int gQUEUE_RequestReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int* Index);
73 int gQUEUE_RequestWriteIndex(PGQUEUECONTROL pQueueControl, int* Index);
74 int gQUEUE_RequestLastReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int* Index);
75 int gQUEUE_UnwrapWriteIndex(PGQUEUECONTROL pQueueControl);
76 int gQUEUE_UnwrapReadIndex(PGQUEUECONTROL pQueueControl, int NReader);
77 int gQUEUE_GetNumberOfUnreadData(PGQUEUECONTROL pQueueControl, int NReader, int *Index);
78 
79 #endif
int gQUEUE_RequestReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:117
int gQUEUE_UnwrapReadIndex(PGQUEUECONTROL pQueueControl, int NReader)
Definition: gqueue.c:277
int gQUEUE_GetWriteIndex(PGQUEUECONTROL pQueueControl, int *Index, int IndexHorizon)
Definition: gqueue.c:203
int gQUEUE_RequestLastReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:67
int gQUEUE_GetReadIndex(PGQUEUECONTROL pQueueControl, int NReader, int *Index, int IndexHorizon)
Definition: gqueue.c:166
struct GQUEUECONTROL * PGQUEUECONTROL
int WriteIndex
Definition: gqueue.h:38
int gQUEUE_UnwrapWriteIndex(PGQUEUECONTROL pQueueControl)
Definition: gqueue.c:297
int gQUEUE_RequestWriteIndex(PGQUEUECONTROL pQueueControl, int *Index)
Definition: gqueue.c:233
int gQUEUE_GetNumberOfUnreadData(PGQUEUECONTROL pQueueControl, int NReader, int *Index)
Definition: gqueue.c:314
int FlagStillNotWritten
Definition: gqueue.h:43
int NReaders
Definition: gqueue.h:42
int gQUEUE_Init(PGQUEUECONTROL pQueueControl, int Size, int NReaders)
Definition: gqueue.c:31
#define MAXSIZE_QUEUE_READ_GATES
Definition: gqueue.h:22
int Size
Definition: gqueue.h:36