changes, use atomic operation for managing dependency counter.
[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 } SESEcommon;
70
71
72 typedef struct WaitingElement_t{
73   void* seseRec;
74   int status;
75   int id;
76   struct Queue* list;
77 } WaitingElement;
78
79 // a thread-local stack of SESEs and function to
80 // ensure it is initialized once per thread
81 /*
82 extern __thread struct Queue* seseCallStack;
83 extern __thread pthread_once_t mlpOnceObj;
84 void mlpInitOncePerThread();
85 */
86 extern __thread SESEcommon_p seseCaller;
87
88
89 // simple mechanical allocation and 
90 // deallocation of SESE records
91 void* mlpCreateSESErecord( int size );
92 void  mlpDestroySESErecord( void* seseRecord );
93
94 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
95 ConflictNode* mlpCreateConflictNode(int id);
96 struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec);
97 WaitingElement* mlpCreateWaitingElement(int status, void* seseToIssue, struct Queue* queue, int id);
98
99
100 #endif /* __MLP_RUNTIME__ */