Removed vestigial code left over from "waiting queues". Scratch previous comment...
[IRC.git] / Robust / src / Runtime / oooJava / hashStructure.h
1 #ifndef HASHSTRUCTURE_H_
2 #define HASHSTRUCTURE_H_
3
4 #include "mlp_runtime.h"
5 //#include "WaitingQueue.h"
6 #include "memPool.h"
7
8 #define bitvt unsigned long long
9
10 //Note READEFFECT = READBIN and WRITEEFFECT=WRITEBIN. They mean the same thing
11 //but are named differently for clarity in code.
12 #define READEFFECT 0
13 #define WRITEEFFECT 1
14 #define WAITINGQUEUENOTE 2
15
16 #define READBIN 0
17 #define WRITEBIN 1
18 #define BINMASK 1
19 #define PARENTBIN 1ULL
20
21 #define SPEC 2
22 #define READY 1          //Item is ready and we haven't seen this bin before
23 #define NOTREADY 0       //Item is not ready and we haven't seen this bin before
24 #define SPECREADY (SPEC|READY)      //Item is ready and we've seen this bin before
25 #define SPECNOTREADY (SPEC|NOTREADY)   //Item is not ready and we've seen this bin before
26 #define READYMASK 1
27
28
29 #define TRUE 1
30 #define FALSE 0
31
32 #define RNUMBINS 131072
33 #define RNUMREAD 24
34 #define RH_MASK (RNUMBINS)-1
35
36 //Note: put resolved things at the end and unresolved at the front.
37 typedef struct BinItem_rcr {
38   int total;
39   int status;
40   int type;
41   //TODO keep track of record ptr here
42   struct BinItem_rcr * next;
43 } BinItem_rcr;
44
45 typedef struct BinElement_rcr {
46   BinItem_rcr * head;
47   BinItem_rcr * tail;
48 } BinElement_rcr;
49
50 typedef struct Hashtable_rcr {
51   BinElement_rcr array[RNUMBINS];
52   //  WaitingQueueBin * waitingQueue;
53   
54   // use a different memory queue for each
55   // bin item type because the difference in
56   // size is very big
57   MemPool* memPoolWrite;
58   MemPool* memPoolRead;
59 } HashStructure;
60
61 //Todo this is a clone of REntry, remove data fields as necessary
62 typedef struct Entry_rcr {
63   SESEcommon * task;
64   bitvt bitindex;
65 } TraverserData;
66
67 typedef struct WriteBinItem_rcr {
68   BinItem_rcr item;
69   SESEcommon * task;
70   bitvt bitindexwr;
71   bitvt bitindexrd;
72 } WriteBinItem_rcr;
73
74 typedef struct ReadBinItem_rcr {
75   BinItem_rcr item;
76   TraverserData array[RNUMREAD];
77   //We don't need a head index since if the item before it was freed, then all these would be considered ready as well.
78   int index;
79 } ReadBinItem_rcr;
80
81 extern __thread HashStructure ** allHashStructures;
82
83 HashStructure ** rcr_createMasterHashTableArray(int maxSize);
84 HashStructure* rcr_createHashtable();
85 WriteBinItem_rcr* rcr_createWriteBinItem( HashStructure* htable );
86 ReadBinItem_rcr* rcr_createReadBinItem( HashStructure* htable );
87 inline int rcr_generateKey(void * ptr);
88
89 //Method signatures are not in their final form since I have still not decided what is the optimum amount of data
90 //to store in each entry.
91
92 void RESOLVE(SESEcommon *record, bitvt mask);
93 int rcr_WRITEBINCASE(HashStructure *T, int key, SESEcommon *task, struct rcrRecord *rcrrec, int index);
94 int rcr_READBINCASE(HashStructure *T, int key, SESEcommon * task, struct rcrRecord *rcrrec, int index);
95
96 int rcr_WTWRITEBINCASE(HashStructure *T, int key, SESEcommon *task, struct rcrRecord *rcrrec, int index);
97 int rcr_WTREADBINCASE(HashStructure *T, int key, SESEcommon * task, struct rcrRecord *rcrrec, int index);
98 int rcr_TAILREADCASE(HashStructure *T, BinItem_rcr *val, BinItem_rcr *bintail, int key, SESEcommon * task, struct rcrRecord *rcrrec, int index);
99 void rcr_TAILWRITECASE(HashStructure *T, BinItem_rcr *val, BinItem_rcr *bintail, int key, SESEcommon * task, struct rcrRecord *rcrrec, int index);
100 void rcr_RETIREHASHTABLE(HashStructure *T, SESEcommon *task, int key, BinItem_rcr *b);
101 #endif