FreeWRL/FreeX3D  3.0.0
ringbuf.h
1 
2 typedef union un1 {
3  int i;
4  float f;
5  void *p;
6 } rbItem;
7 
8 typedef struct rb1 {
9  int head ;
10  int tail ;
11  int noOfElements ;
12  void * data;
13 } RingBuffer ;
14 
15 #define FORCE_GUARD_ELEMENT 1
16 #define TRACK_RINGBUFFER_MSG 0
17 
18 /* Con/De-structors */
19 RingBuffer * NewRingBuffer (int elCount) ;
20 /*
21  * You should only use makeEmpty for floats and ints.
22  *
23  * For pointers you should first do something like this:
24  *
25  while (!RingBuffer_testEmpty(buffer) ;
26  toClean = RingBuffer_pullUnion(buffer).p ;
27  free(toClean);
28  }
29  */
30 void RingBuffer_makeEmpty(RingBuffer * buffer) ;
31 void RingBuffer_freeDataArea(RingBuffer * buffer) ;
32 
33 
34 /* helpers */
35 int RingBuffer_qLen(RingBuffer * buffer) ;
36 int RingBuffer_freeLen(RingBuffer * buffer) ;
37 int RingBuffer_testEmpty(RingBuffer * buffer) ;
38 int RingBuffer_testFull(RingBuffer * buffer) ;
39 
40 /* Add data to back of queue */
41 int RingBuffer_pushInt(RingBuffer * buffer, int newInt) ;
42 int RingBuffer_pushFloat(RingBuffer * buffer, float newFloat) ;
43 int RingBuffer_pushPointer(RingBuffer * buffer, void *newPointer) ;
44 
45 
46 /* remove data from the front of the queue */
47 /* Note: RingBuffer_pullUnion is not bulletproof!! You should
48 ALWAYS first test RingBuffer_testEmpty BEFORE a RingBuffer_pullUnion.
49 
50 However, because it is a pull rather than a push then not checking
51 is not fatal.
52 */
53 
54 rbItem * RingBuffer_pullUnion(RingBuffer * buffer) ;
55 rbItem * RingBuffer_peekUnion(RingBuffer * buffer) ;
56 
Definition: ringbuf.h:2
Definition: ringbuf.h:8