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