changes.
[IRC.git] / Robust / src / Runtime / deque.h
1 #ifndef ___DEQUE_H__
2 #define ___DEQUE_H__
3
4 #include "runtime.h"
5 #include "memPool.h"
6
7
8
9 // the bottom and top 64-bit values encode
10 // several sub-values, see deque.c
11 typedef struct deque_t {
12   MemPool*        memPool;
13   volatile INTPTR bottom;
14
15   // force bottom and top to different cache lines
16   char buffer[CACHELINESIZE];
17
18   volatile INTPTR top;
19 } deque;
20
21
22 void  dqInit(deque* dq);
23 void  dqPushBottom(deque* dq, void* item);
24 void* dqPopTop(deque* dq);
25 void* dqPopBottom(deque* dq);
26
27
28 // pop operations may return these values
29 // instead of an item
30 extern void* DQ_POP_EMPTY;
31 extern void* DQ_POP_ABORT;
32
33
34 // there are 9 bits for the index into a Node's array,
35 // so 2^9 = 512 elements per node of the deque
36 #define DQNODE_ARRAYSIZE 512
37
38
39 typedef struct dequeNode_t {
40   void* itsDataArr[DQNODE_ARRAYSIZE];
41   struct dequeNode_t* next;
42   struct dequeNode_t* prev;
43 } dequeNode;
44
45
46 static inline int        dqDecodeTag(INTPTR E) {
47   return (int)        ((0xffffe00000000000 & E) >> 45);
48 }
49 static inline dequeNode* dqDecodePtr(INTPTR E) {
50   return (dequeNode*) ((0x00001ffffffffe00 & E) <<  3);
51 }
52 static inline int        dqDecodeIdx(INTPTR E) {
53   return (int)        ((0x00000000000001ff & E)      );
54 }
55
56
57 #endif // ___DEQUE_H__