VMS/VMS_Implementations/Vthread_impls/Vthread_MC_shared_impl

view Vthread.h @ 29:b94dc57e4455

refactored many files -- chgd names, moved code around -- doesn't compile
author Some Random Person <seanhalle@yahoo.com>
date Wed, 09 May 2012 13:24:19 -0700
parents b3a881f25c5a
children
line source
1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef _Vthread_H
10 #define _Vthread_H
12 #define _LANG_NAME_ "Vthread"
14 #include "VMS_impl/VMS.h"
15 #include "C_Libraries/Queue_impl/PrivateQueue.h"
16 #include "C_Libraries/DynArray/DynArray.h"
19 /*This header defines everything specific to the Vthread semantic plug-in
20 */
23 //===========================================================================
24 //turn on the counter measurements of language overhead -- comment to turn off
25 #define MEAS__TURN_ON_LANG_MEAS
26 #include "Vthread__Measurement.h"
28 #define INIT_NUM_MUTEX 10000
29 #define INIT_NUM_COND 10000
31 #define NUM_STRUCS_IN_SEM_ENV 1000
32 //===========================================================================
34 //===========================================================================
35 typedef struct _VthreadSemReq VthdSemReq;
36 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
37 //===========================================================================
40 /*WARNING: assembly hard-codes position of endInstrAddr as first field
41 */
42 typedef struct
43 {
44 void *savedRetAddr;
45 int32 hasBeenStarted;
46 int32 hasFinished;
47 PrivQueueStruc *waitQ;
48 }
49 VthdSingleton;
51 /*Semantic layer-specific data sent inside a request from lib called in app
52 * to request handler called in MasterLoop
53 */
54 enum VthreadReqType
55 {
56 make_mutex = 1,
57 mutex_lock,
58 mutex_unlock,
59 make_cond,
60 cond_wait,
61 cond_signal,
62 make_slaveVP,
63 malloc_req,
64 free_req,
65 singleton_fn_start,
66 singleton_fn_end,
67 singleton_data_start,
68 singleton_data_end,
69 atomic,
70 trans_start,
71 trans_end
72 };
74 struct _VthreadSemReq
75 { enum VthreadReqType reqType;
76 SlaveVP *requestingSlv;
77 int32 mutexIdx;
78 int32 condIdx;
80 void *initData;
81 TopLevelFnPtr fnPtr;
82 int32 coreToScheduleOnto;
84 size_t sizeToMalloc;
85 void *ptrToFree;
87 int32 singletonID;
88 VthdSingleton *singleton;
90 PtrToAtomicFn fnToExecInMaster;
91 void *dataForFn;
93 int32 transID;
94 }
95 /* VthreadSemReq */;
98 typedef struct
99 {
100 SlaveVP *SlvCurrentlyExecuting;
101 PrivQueueStruc *waitingSlvQ;
102 }
103 VthdTrans;
106 typedef struct
107 {
108 int32 mutexIdx;
109 SlaveVP *holderOfLock;
110 PrivQueueStruc *waitingQueue;
111 }
112 VthdMutex;
115 typedef struct
116 {
117 int32 condIdx;
118 PrivQueueStruc *waitingQueue;
119 VthdMutex *partnerMutex;
120 }
121 VthdCond;
123 typedef struct _TransListElem TransListElem;
124 struct _TransListElem
125 {
126 int32 transID;
127 TransListElem *nextTrans;
128 };
129 //TransListElem
131 typedef struct
132 {
133 int32 highestTransEntered;
134 TransListElem *lastTransEntered;
135 }
136 VthdSemData;
139 typedef struct
140 {
141 //Standard stuff will be in most every semantic env
142 PrivQueueStruc **readySlvQs;
143 int32 nextCoreToGetNewSlv;
144 int32 primitiveStartTime;
146 //Specific to this semantic layer
147 VthdMutex **mutexDynArray;
148 PrivDynArrayInfo *mutexDynArrayInfo;
150 VthdCond **condDynArray;
151 PrivDynArrayInfo *condDynArrayInfo;
153 void *applicationGlobals;
155 //fix limit on num with dynArray
156 VthdSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
158 VthdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
159 }
160 VthdSemEnv;
162 //==========================================================================
164 void
165 Vthread__init();
167 void
168 Vthread__init_Seq();
170 void
171 Vthread__init_Helper();
174 //===========================================================================
176 inline void
177 Vthread__create_seed_slaveVP_and_do_work( TopLevelFnPtr fn, void *initData );
179 inline SlaveVP *
180 Vthread__create_slaveVP_helper( TopLevelFnPtr fnPtr, void *initData,
181 VthdSemEnv *semEnv, int32 coreToScheduleOnto );
183 //=======================
185 inline SlaveVP *
186 Vthread__create_thread( TopLevelFnPtr fnPtr, void *initData,
187 SlaveVP *creatingSlv );
189 inline SlaveVP *
190 Vthread__create_thread_with_affinity( TopLevelFnPtr fnPtr, void *initData,
191 SlaveVP *creatingSlv, int32 coreToScheduleOnto );
193 inline void
194 Vthread__dissipate_thread( SlaveVP *procrToDissipate );
196 //=======================
197 inline void
198 Vthread__set_globals_to( void *globals );
200 inline void *
201 Vthread__give_globals();
203 //=======================
204 inline int32
205 Vthread__make_mutex( SlaveVP *animSlv );
207 inline void
208 Vthread__mutex_lock( int32 mutexIdx, SlaveVP *acquiringSlv );
210 inline void
211 Vthread__mutex_unlock( int32 mutexIdx, SlaveVP *releasingSlv );
214 //=======================
215 inline int32
216 Vthread__make_cond( int32 ownedMutexIdx, SlaveVP *animSlv);
218 inline void
219 Vthread__cond_wait( int32 condIdx, SlaveVP *waitingSlv);
221 inline void *
222 Vthread__cond_signal( int32 condIdx, SlaveVP *signallingSlv );
225 //=======================
226 void
227 Vthread__start_fn_singleton( int32 singletonID, SlaveVP *animSlv );
229 void
230 Vthread__end_fn_singleton( int32 singletonID, SlaveVP *animSlv );
232 void
233 Vthread__start_data_singleton( VthdSingleton *singelton, SlaveVP *animSlv );
235 void
236 Vthread__end_data_singleton( VthdSingleton *singleton, SlaveVP *animSlv );
238 void
239 Vthread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
240 void *data, SlaveVP *animSlv );
242 void
243 Vthread__start_transaction( int32 transactionID, SlaveVP *animSlv );
245 void
246 Vthread__end_transaction( int32 transactionID, SlaveVP *animSlv );
250 //========================= Internal use only =============================
251 inline void
252 Vthread__Request_Handler( SlaveVP *requestingSlv, void *_semEnv );
254 inline SlaveVP *
255 Vthread__schedule_slaveVP( void *_semEnv, int coreNum );
257 //=======================
258 inline void
259 Vthread__free_semantic_request( VthdSemReq *semReq );
261 //=======================
263 void *
264 Vthread__malloc( size_t sizeToMalloc, SlaveVP *animSlv );
266 void
267 Vthread__init();
269 void
270 Vthread__cleanup_after_shutdown();
272 void inline
273 resume_slaveVP( SlaveVP *procr, VthdSemEnv *semEnv );
275 #endif /* _Vthread_H */