view Vthread.h @ 27:e5d4d5871ac9

half-done update to common_ancesor VMS version.. in middle
author Some Random Person <seanhalle@yahoo.com>
date Thu, 01 Mar 2012 13:20:51 -0800
parents
children b3a881f25c5a
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 _VPThread_H
10 #define _VPThread_H
12 #include "VMS_impl/VMS.h"
13 #include "C_Libraries/Queue_impl/PrivateQueue.h"
14 #include "C_Libraries/DynArray/DynArray.h"
17 /*This header defines everything specific to the VPThread semantic plug-in
18 */
21 //===========================================================================
22 //turn on the counter measurements of language overhead -- comment to turn off
23 #define MEAS__TURN_ON_LANG_MEAS
25 #define INIT_NUM_MUTEX 10000
26 #define INIT_NUM_COND 10000
28 #define NUM_STRUCS_IN_SEM_ENV 1000
29 //===========================================================================
31 //===========================================================================
32 typedef struct _VPThreadSemReq VPThdSemReq;
33 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
34 //===========================================================================
37 /*WARNING: assembly hard-codes position of endInstrAddr as first field
38 */
39 typedef struct
40 {
41 void *endInstrAddr;
42 int32 hasBeenStarted;
43 int32 hasFinished;
44 PrivQueueStruc *waitQ;
45 }
46 VPThdSingleton;
48 /*Semantic layer-specific data sent inside a request from lib called in app
49 * to request handler called in MasterLoop
50 */
51 enum VPThreadReqType
52 {
53 make_mutex = 1,
54 mutex_lock,
55 mutex_unlock,
56 make_cond,
57 cond_wait,
58 cond_signal,
59 make_procr,
60 malloc_req,
61 free_req,
62 singleton_fn_start,
63 singleton_fn_end,
64 singleton_data_start,
65 singleton_data_end,
66 atomic,
67 trans_start,
68 trans_end
69 };
71 struct _VPThreadSemReq
72 { enum VPThreadReqType reqType;
73 SlaveVP *requestingVP;
74 int32 mutexIdx;
75 int32 condIdx;
77 void *initData;
78 TopLevelFnPtr fnPtr;
79 int32 coreToScheduleOnto;
81 size_t sizeToMalloc;
82 void *ptrToFree;
84 int32 singletonID;
85 VPThdSingleton **singletonPtrAddr;
87 PtrToAtomicFn fnToExecInMaster;
88 void *dataForFn;
90 int32 transID;
91 }
92 /* VPThreadSemReq */;
95 typedef struct
96 {
97 SlaveVP *VPCurrentlyExecuting;
98 PrivQueueStruc *waitingVPQ;
99 }
100 VPThdTrans;
103 typedef struct
104 {
105 int32 mutexIdx;
106 SlaveVP *holderOfLock;
107 PrivQueueStruc *waitingQueue;
108 }
109 VPThdMutex;
112 typedef struct
113 {
114 int32 condIdx;
115 PrivQueueStruc *waitingQueue;
116 VPThdMutex *partnerMutex;
117 }
118 VPThdCond;
120 typedef struct _TransListElem TransListElem;
121 struct _TransListElem
122 {
123 int32 transID;
124 TransListElem *nextTrans;
125 };
126 //TransListElem
128 typedef struct
129 {
130 int32 highestTransEntered;
131 TransListElem *lastTransEntered;
132 }
133 VPThdSemData;
136 typedef struct
137 {
138 //Standard stuff will be in most every semantic env
139 PrivQueueStruc **readyVPQs;
140 int32 numVirtVP;
141 int32 nextCoreToGetNewVP;
142 int32 primitiveStartTime;
144 //Specific to this semantic layer
145 VPThdMutex **mutexDynArray;
146 PrivDynArrayInfo *mutexDynArrayInfo;
148 VPThdCond **condDynArray;
149 PrivDynArrayInfo *condDynArrayInfo;
151 void *applicationGlobals;
153 //fix limit on num with dynArray
154 VPThdSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
156 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
157 }
158 VPThdSemEnv;
161 //===========================================================================
163 inline void
164 VPThread__create_seed_procr_and_do_work( TopLevelFnPtr fn, void *initData );
166 //=======================
168 inline SlaveVP *
169 VPThread__create_thread( TopLevelFnPtr fnPtr, void *initData,
170 SlaveVP *creatingVP );
172 inline SlaveVP *
173 VPThread__create_thread_with_affinity( TopLevelFnPtr fnPtr, void *initData,
174 SlaveVP *creatingVP, int32 coreToScheduleOnto );
176 inline void
177 VPThread__dissipate_thread( SlaveVP *procrToDissipate );
179 //=======================
180 inline void
181 VPThread__set_globals_to( void *globals );
183 inline void *
184 VPThread__give_globals();
186 //=======================
187 inline int32
188 VPThread__make_mutex( SlaveVP *animVP );
190 inline void
191 VPThread__mutex_lock( int32 mutexIdx, SlaveVP *acquiringVP );
193 inline void
194 VPThread__mutex_unlock( int32 mutexIdx, SlaveVP *releasingVP );
197 //=======================
198 inline int32
199 VPThread__make_cond( int32 ownedMutexIdx, SlaveVP *animPr);
201 inline void
202 VPThread__cond_wait( int32 condIdx, SlaveVP *waitingPr);
204 inline void *
205 VPThread__cond_signal( int32 condIdx, SlaveVP *signallingVP );
208 //=======================
209 void
210 VPThread__start_fn_singleton( int32 singletonID, SlaveVP *animVP );
212 void
213 VPThread__end_fn_singleton( int32 singletonID, SlaveVP *animVP );
215 void
216 VPThread__start_data_singleton( VPThdSingleton **singeltonAddr, SlaveVP *animVP );
218 void
219 VPThread__end_data_singleton( VPThdSingleton **singletonAddr, SlaveVP *animVP );
221 void
222 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
223 void *data, SlaveVP *animVP );
225 void
226 VPThread__start_transaction( int32 transactionID, SlaveVP *animVP );
228 void
229 VPThread__end_transaction( int32 transactionID, SlaveVP *animVP );
233 //========================= Internal use only =============================
234 inline void
235 VPThread__Request_Handler( SlaveVP *requestingVP, void *_semEnv );
237 inline SlaveVP *
238 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
240 //=======================
241 inline void
242 VPThread__free_semantic_request( VPThdSemReq *semReq );
244 //=======================
246 void *
247 VPThread__malloc( size_t sizeToMalloc, SlaveVP *animVP );
249 void
250 VPThread__init();
252 void
253 VPThread__cleanup_after_shutdown();
255 void inline
256 resume_procr( SlaveVP *procr, VPThdSemEnv *semEnv );
258 #endif /* _VPThread_H */