add a phtread implementation of semaphores for general runtime use
[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   // the value when it is known will be placed
16   // in this location, which can be accessed
17   // as a variety of types
18   union {
19     char      sesetype_byte;
20     int       sesetype_boolean;
21     short     sesetype_short;
22     int       sesetype_int;
23     long long sesetype_long;
24     short     sesetype_char;
25     float     sesetype_float;
26     double    sesetype_double;
27     void*     sesetype_object;
28   };  
29 } SESEvar;
30
31
32 typedef struct SESErecord_t {  
33   // the identifier for the class of sese's that
34   // are instances of one particular static code block
35   int classID;
36
37   // pointers to SESEs directly above or below
38   // in the heirarchy
39   //struct SESErecord_t* parent;
40   //struct Queue*        childrenList;
41   // IMPLEMENT THIS LIKE STALLS--EVERY PARENTS EXIT MUST
42   // "STALL" on COMPLETETION OF ALL ISSUED CHILDREN, SO
43   // ALWAYS GIVE A CHILD A SEMAPHORE THAT IS ON YOUR LIST
44   // OF THINGS TO BLOCK ON AT EXIT
45
46   // for state of vars after issue
47   SESEvar* vars;
48   
49   // when this sese is ready to be invoked,
50   // allocate and fill in this structure, and
51   // the primitives will be passed out of the
52   // above var array at the call site
53   void* paramStruct;
54
55   // for signaling transition from issue 
56   // to execute
57   pthread_cond_t*  startCondVar;
58   pthread_mutex_t* startCondVarLock;
59   int startedExecuting;
60
61   // use a list of SESErecords and a lock to let
62   // consumers tell this SESE who wants values
63   // forwarded to it
64   pthread_mutex_t* forwardListLock;
65   struct Queue*    forwardList;
66   int doneExecuting;
67
68 } SESErecord;
69
70
71 typedef struct invokeSESEargs_t {
72   int classID;
73   SESErecord* invokee;
74   SESErecord* parent;
75 } invokeSESEargs;
76
77
78 // simple mechanical allocation and deallocation
79 // of SESE records
80 SESErecord* mlpCreateSESErecord( int         classID,
81                                  int         instanceID,
82                                  SESErecord* parent,
83                                  int         numVars,
84                                  void*       paramStruct
85                                  );
86
87 void mlpDestroySESErecord( SESErecord* sese );
88
89
90 // main library functions
91 void mlpInit();
92
93 SESErecord* mlpGetCurrent();
94 SESErecord* mlpSchedule();
95
96 void mlpIssue     ( SESErecord* sese );
97 void mlpStall     ( SESErecord* sese );
98 void mlpNotifyExit( SESErecord* sese );
99
100
101 extern SESErecord* rootsese;
102
103
104 #endif /* __MLP_RUNTIME__ */