keep last snapshot for benchmark before moving to new queue impl.
[IRC.git] / Robust / src / Runtime / mlp_runtime.h
1 #ifndef __MLP_RUNTIME__
2 #define __MLP_RUNTIME__
3
4
5 #include <pthread.h>
6 #include "Queue.h"
7 #include "psemaphore.h"
8 #include "mlp_lock.h"
9
10 #ifndef FALSE
11 #define FALSE 0
12 #endif
13
14 #ifndef TRUE
15 #define TRUE 1
16 #endif
17
18 // each allocation site needs the following
19 typedef struct AllocSite_t{
20   long id;
21   struct Queue* waitingQueue;
22 } AllocSite;
23
24 typedef struct ConflictNode_t{
25   int id;
26 } ConflictNode;
27
28
29 // forward declaration of pointer type
30 typedef struct SESEcommon_t* SESEcommon_p;
31
32 // these fields are common to any SESE, and casting the
33 // generated SESE record to this can be used, because
34 // the common structure is always the first item in a
35 // customized SESE record
36 typedef struct SESEcommon_t {  
37
38   // the identifier for the class of sese's that
39   // are instances of one particular static code block
40   int classID;
41
42   // a parent waits on this semaphore when stalling on
43   // this child, the child gives it at its SESE exit
44   psemaphore stallSem;
45
46   
47   // the lock guards the following data SESE's
48   // use to coordinate with one another
49   pthread_mutex_t lock;
50
51   struct Queue*   forwardList;
52   volatile int             unresolvedDependencies;
53
54   pthread_cond_t  doneCond;
55   int             doneExecuting;
56
57   pthread_cond_t  runningChildrenCond;
58   int             numRunningChildren;
59
60   SESEcommon_p    parent;
61
62   AllocSite* allocSiteArray;
63   int numRelatedAllocSites;
64   psemaphore memoryStallSiteSem;
65   struct Queue* connectedList;
66   int numRelatedWaitingQueue;
67   int waitingQueueItemID;
68
69   pthread_cond_t stallDone;
70
71 } SESEcommon;
72
73
74 typedef struct WaitingElement_t{
75   void* seseRec;
76   int status;
77   int id;
78   int resolved;
79   struct Queue* list;
80 } WaitingElement;
81
82 // a thread-local stack of SESEs and function to
83 // ensure it is initialized once per thread
84 /*
85 extern __thread struct Queue* seseCallStack;
86 extern __thread pthread_once_t mlpOnceObj;
87 void mlpInitOncePerThread();
88 */
89 extern __thread SESEcommon_p seseCaller;
90
91
92 // simple mechanical allocation and 
93 // deallocation of SESE records
94 void* mlpCreateSESErecord( int size );
95 void  mlpDestroySESErecord( void* seseRecord );
96
97 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
98 ConflictNode* mlpCreateConflictNode(int id);
99 int addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, WaitingElement* wElement);
100 WaitingElement* mlpCreateWaitingElement(int status, void* seseToIssue, struct Queue* queue, int id);
101 void* mlpAllocSESErecord( int size );
102
103
104 #endif /* __MLP_RUNTIME__ */