more updates towards implementing SESE runtime
[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
8
9 // a forward delcaration for SESEvar
10 struct SESErecord_t;
11
12
13 typedef struct SESEvar_t {
14   //unsigned char mode;
15
16   // the value when it is known will be placed
17   // in this location, which can be accessed
18   // as a variety of types
19   union {
20     char      sesetype_byte;
21     int       sesetype_boolean;
22     short     sesetype_short;
23     int       sesetype_int;
24     long long sesetype_long;
25     short     sesetype_char;
26     float     sesetype_float;
27     double    sesetype_double;
28     void*     sesetype_object;
29   };
30   
31   // a statically or dynamically known SESE
32   // to gather the variable's value from
33   // if source==NULL it indicates the root
34   // SESE, which has no record, just normal
35   // temp names
36   //struct SESErecord_t* source;
37   //unsigned int         index;
38 } SESEvar;
39
40
41 typedef struct SESErecord_t {  
42   // the identifier for the class of sese's that
43   // are instances of one particular static code block
44   int classID;
45
46   // not globally unqiue, but each parent ensures that
47   // its children have unique identifiers, including to
48   // the parent itself
49   int instanceID;
50
51   // used to give out IDs to children
52   int childInstanceIDs;
53
54   // pointers to SESEs directly above or below
55   // in the heirarchy
56   struct SESErecord_t* parent;
57   struct Queue*        childrenList;
58
59   // for state of vars after issue
60   SESEvar* vars;
61   
62   // when this sese is ready to be invoked,
63   // allocate and fill in this structure, and
64   // the primitives will be passed out of the
65   // above var array at the call site
66   void* paramStruct;
67
68
69   pthread_cond_t*  startCondVar;
70   pthread_mutex_t* startCondVarLock;
71
72
73   // use a list of SESErecords and a lock to let
74   // consumers tell this SESE who wants values
75   // forwarded to it
76   pthread_mutex_t* forwardListLock;
77   struct Queue*    forwardList;
78   int doneExecuting;
79 } SESErecord;
80
81
82 typedef struct invokeSESEargs_t {
83   int classID;
84   SESErecord* invokee;
85   SESErecord* parent;
86 } invokeSESEargs;
87
88
89 // simple mechanical allocation and deallocation
90 // of SESE records
91 SESErecord* mlpCreateSESErecord( int         classID,
92                                  int         instanceID,
93                                  SESErecord* parent,
94                                  int         numVars,
95                                  void*       paramStruct
96                                  );
97
98 void mlpDestroySESErecord( SESErecord* sese );
99
100
101 // main library functions
102 void mlpInit();
103
104 SESErecord* mlpGetCurrent();
105 SESErecord* mlpSchedule();
106
107 void mlpIssue     ( SESErecord* sese );
108 void mlpStall     ( SESErecord* sese );
109 void mlpNotifyExit( SESErecord* sese );
110
111
112 extern SESErecord* rootsese;
113
114
115 #endif /* __MLP_RUNTIME__ */