c8af40c28a481c0632bc77a5b5b034a7d8b2a98b
[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   // for signaling transition from issue 
69   // to execute
70   pthread_cond_t*  startCondVar;
71   pthread_mutex_t* startCondVarLock;
72   int startedExecuting;
73
74   // use a list of SESErecords and a lock to let
75   // consumers tell this SESE who wants values
76   // forwarded to it
77   pthread_mutex_t* forwardListLock;
78   struct Queue*    forwardList;
79   int doneExecuting;
80
81 } SESErecord;
82
83
84 typedef struct invokeSESEargs_t {
85   int classID;
86   SESErecord* invokee;
87   SESErecord* parent;
88 } invokeSESEargs;
89
90
91 // simple mechanical allocation and deallocation
92 // of SESE records
93 SESErecord* mlpCreateSESErecord( int         classID,
94                                  int         instanceID,
95                                  SESErecord* parent,
96                                  int         numVars,
97                                  void*       paramStruct
98                                  );
99
100 void mlpDestroySESErecord( SESErecord* sese );
101
102
103 // main library functions
104 void mlpInit();
105
106 SESErecord* mlpGetCurrent();
107 SESErecord* mlpSchedule();
108
109 void mlpIssue     ( SESErecord* sese );
110 void mlpStall     ( SESErecord* sese );
111 void mlpNotifyExit( SESErecord* sese );
112
113
114 extern SESErecord* rootsese;
115
116
117 #endif /* __MLP_RUNTIME__ */