changes.
[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
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 // forward declaration of pointer type
29 typedef struct SESEcommon_t* SESEcommon_p;
30
31 // these fields are common to any SESE, and casting the
32 // generated SESE record to this can be used, because
33 // the common structure is always the first item in a
34 // customized SESE record
35 typedef struct SESEcommon_t {  
36
37   // the identifier for the class of sese's that
38   // are instances of one particular static code block
39   int classID;
40
41   // a parent waits on this semaphore when stalling on
42   // this child, the child gives it at its SESE exit
43   psemaphore stallSem;
44
45   
46   // the lock guards the following data SESE's
47   // use to coordinate with one another
48   pthread_mutex_t lock;
49
50   struct Queue*   forwardList;
51   int             unresolvedDependencies;
52
53   pthread_cond_t  doneCond;
54   int             doneExecuting;
55
56   pthread_cond_t  runningChildrenCond;
57   int             numRunningChildren;
58
59   SESEcommon_p    parent;
60
61   AllocSite* allocSiteArray;
62   int numRelatedAllocSites;
63   psemaphore memoryStallSiteSem;
64   struct Queue* connectedList;
65
66 } SESEcommon;
67
68
69 // a thread-local stack of SESEs and function to
70 // ensure it is initialized once per thread
71 /*
72 extern __thread struct Queue* seseCallStack;
73 extern __thread pthread_once_t mlpOnceObj;
74 void mlpInitOncePerThread();
75 */
76 extern __thread SESEcommon_p seseCaller;
77
78
79 // simple mechanical allocation and 
80 // deallocation of SESE records
81 void* mlpCreateSESErecord( int size );
82 void  mlpDestroySESErecord( void* seseRecord );
83
84 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
85 ConflictNode* mlpCreateConflictNode(int id);
86 struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec);
87
88
89
90 #endif /* __MLP_RUNTIME__ */