| rev |
line source |
|
Me@0
|
1 /*
|
|
Me@0
|
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
|
|
Me@0
|
3 * Licensed under GNU General Public License version 2
|
|
Me@0
|
4 *
|
|
Me@0
|
5 * Author: seanhalle@yahoo.com
|
|
Me@0
|
6 *
|
|
Me@0
|
7 */
|
|
Me@0
|
8
|
|
Me@0
|
9 #ifndef _VPThread_H
|
|
Me@0
|
10 #define _VPThread_H
|
|
Me@0
|
11
|
|
Me@0
|
12 #include "VMS/VMS.h"
|
|
Me@0
|
13 #include "VMS/Queue_impl/PrivateQueue.h"
|
|
Me@0
|
14 #include "VMS/DynArray/DynArray.h"
|
|
Me@0
|
15
|
|
Me@0
|
16
|
|
SeanHalle@1
|
17 /*This header defines everything specific to the VPThread semantic plug-in
|
|
SeanHalle@1
|
18 */
|
|
SeanHalle@1
|
19
|
|
SeanHalle@1
|
20
|
|
Me@0
|
21 //===========================================================================
|
|
Me@0
|
22 #define INIT_NUM_MUTEX 10000
|
|
Me@0
|
23 #define INIT_NUM_COND 10000
|
|
SeanHalle@1
|
24
|
|
SeanHalle@1
|
25 #define NUM_STRUCS_IN_SEM_ENV 1000
|
|
Me@0
|
26 //===========================================================================
|
|
Me@0
|
27
|
|
SeanHalle@1
|
28 //===========================================================================
|
|
SeanHalle@1
|
29 typedef struct _VPThreadSemReq VPThdSemReq;
|
|
SeanHalle@1
|
30 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
|
|
SeanHalle@1
|
31 //===========================================================================
|
|
Me@0
|
32
|
|
Me@0
|
33
|
|
Me@3
|
34 /*WARNING: assembly hard-codes position of endInstrAddr as first field
|
|
Me@3
|
35 */
|
|
Me@3
|
36 typedef struct
|
|
Me@3
|
37 {
|
|
Me@3
|
38 void *endInstrAddr;
|
|
Me@3
|
39 int32 hasBeenStarted;
|
|
Me@3
|
40 int32 hasFinished;
|
|
Me@3
|
41 PrivQueueStruc *waitQ;
|
|
Me@3
|
42 }
|
|
Me@3
|
43 VPThdSingleton;
|
|
Me@3
|
44
|
|
Me@0
|
45 /*Semantic layer-specific data sent inside a request from lib called in app
|
|
Me@0
|
46 * to request handler called in MasterLoop
|
|
Me@0
|
47 */
|
|
Me@0
|
48 enum VPThreadReqType
|
|
Me@0
|
49 {
|
|
Me@0
|
50 make_mutex = 1,
|
|
Me@0
|
51 mutex_lock,
|
|
Me@0
|
52 mutex_unlock,
|
|
Me@0
|
53 make_cond,
|
|
Me@0
|
54 cond_wait,
|
|
Me@0
|
55 cond_signal,
|
|
SeanHalle@1
|
56 make_procr,
|
|
SeanHalle@1
|
57 malloc_req,
|
|
SeanHalle@1
|
58 free_req,
|
|
Me@3
|
59 singleton_fn_start,
|
|
Me@3
|
60 singleton_fn_end,
|
|
Me@3
|
61 singleton_data_start,
|
|
Me@3
|
62 singleton_data_end,
|
|
SeanHalle@1
|
63 atomic,
|
|
SeanHalle@1
|
64 trans_start,
|
|
SeanHalle@1
|
65 trans_end
|
|
Me@0
|
66 };
|
|
Me@0
|
67
|
|
Me@0
|
68 struct _VPThreadSemReq
|
|
Me@0
|
69 { enum VPThreadReqType reqType;
|
|
Me@0
|
70 VirtProcr *requestingPr;
|
|
Me@0
|
71 int32 mutexIdx;
|
|
Me@0
|
72 int32 condIdx;
|
|
SeanHalle@1
|
73
|
|
Me@0
|
74 void *initData;
|
|
Me@0
|
75 VirtProcrFnPtr fnPtr;
|
|
SeanHalle@1
|
76 int32 coreToScheduleOnto;
|
|
SeanHalle@1
|
77
|
|
SeanHalle@1
|
78 int32 sizeToMalloc;
|
|
SeanHalle@1
|
79 void *ptrToFree;
|
|
SeanHalle@1
|
80
|
|
SeanHalle@1
|
81 int32 singletonID;
|
|
Me@3
|
82 VPThdSingleton **singletonPtrAddr;
|
|
SeanHalle@1
|
83
|
|
SeanHalle@1
|
84 PtrToAtomicFn fnToExecInMaster;
|
|
SeanHalle@1
|
85 void *dataForFn;
|
|
SeanHalle@1
|
86
|
|
SeanHalle@1
|
87 int32 transID;
|
|
Me@0
|
88 }
|
|
Me@0
|
89 /* VPThreadSemReq */;
|
|
Me@0
|
90
|
|
SeanHalle@1
|
91
|
|
SeanHalle@1
|
92 typedef struct
|
|
SeanHalle@1
|
93 {
|
|
SeanHalle@1
|
94 VirtProcr *VPCurrentlyExecuting;
|
|
SeanHalle@1
|
95 PrivQueueStruc *waitingVPQ;
|
|
SeanHalle@1
|
96 }
|
|
SeanHalle@1
|
97 VPThdTrans;
|
|
SeanHalle@1
|
98
|
|
Me@0
|
99
|
|
Me@0
|
100 typedef struct
|
|
Me@0
|
101 {
|
|
Me@0
|
102 int32 mutexIdx;
|
|
Me@0
|
103 VirtProcr *holderOfLock;
|
|
Me@0
|
104 PrivQueueStruc *waitingQueue;
|
|
Me@0
|
105 }
|
|
SeanHalle@1
|
106 VPThdMutex;
|
|
Me@0
|
107
|
|
Me@0
|
108
|
|
Me@0
|
109 typedef struct
|
|
Me@0
|
110 {
|
|
Me@0
|
111 int32 condIdx;
|
|
Me@0
|
112 PrivQueueStruc *waitingQueue;
|
|
SeanHalle@1
|
113 VPThdMutex *partnerMutex;
|
|
Me@0
|
114 }
|
|
SeanHalle@1
|
115 VPThdCond;
|
|
SeanHalle@1
|
116
|
|
SeanHalle@1
|
117 typedef struct _TransListElem TransListElem;
|
|
SeanHalle@1
|
118 struct _TransListElem
|
|
SeanHalle@1
|
119 {
|
|
SeanHalle@1
|
120 int32 transID;
|
|
SeanHalle@1
|
121 TransListElem *nextTrans;
|
|
SeanHalle@1
|
122 };
|
|
SeanHalle@1
|
123 //TransListElem
|
|
SeanHalle@1
|
124
|
|
SeanHalle@1
|
125 typedef struct
|
|
SeanHalle@1
|
126 {
|
|
SeanHalle@1
|
127 int32 highestTransEntered;
|
|
SeanHalle@1
|
128 TransListElem *lastTransEntered;
|
|
SeanHalle@1
|
129 }
|
|
SeanHalle@1
|
130 VPThdSemData;
|
|
Me@0
|
131
|
|
Me@0
|
132
|
|
Me@2
|
133 typedef struct
|
|
Me@2
|
134 {
|
|
Me@2
|
135 //Standard stuff will be in most every semantic env
|
|
Me@2
|
136 PrivQueueStruc **readyVPQs;
|
|
Me@2
|
137 int32 numVirtPr;
|
|
Me@2
|
138 int32 nextCoreToGetNewPr;
|
|
Me@2
|
139 int32 primitiveStartTime;
|
|
Me@2
|
140
|
|
Me@2
|
141 //Specific to this semantic layer
|
|
Me@2
|
142 VPThdMutex **mutexDynArray;
|
|
Me@2
|
143 PrivDynArrayInfo *mutexDynArrayInfo;
|
|
Me@2
|
144
|
|
Me@2
|
145 VPThdCond **condDynArray;
|
|
Me@2
|
146 PrivDynArrayInfo *condDynArrayInfo;
|
|
Me@2
|
147
|
|
Me@2
|
148 void *applicationGlobals;
|
|
Me@2
|
149
|
|
Me@2
|
150 //fix limit on num with dynArray
|
|
Me@3
|
151 VPThdSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
|
|
Me@2
|
152
|
|
Me@2
|
153 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
|
|
Me@2
|
154 }
|
|
Me@2
|
155 VPThdSemEnv;
|
|
Me@2
|
156
|
|
Me@2
|
157
|
|
Me@0
|
158 //===========================================================================
|
|
Me@0
|
159
|
|
SeanHalle@1
|
160 inline void
|
|
Me@0
|
161 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
|
|
Me@0
|
162
|
|
Me@0
|
163 //=======================
|
|
Me@0
|
164
|
|
Me@0
|
165 inline VirtProcr *
|
|
Me@0
|
166 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
|
|
Me@0
|
167 VirtProcr *creatingPr );
|
|
Me@0
|
168
|
|
SeanHalle@1
|
169 inline VirtProcr *
|
|
SeanHalle@1
|
170 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
|
|
SeanHalle@1
|
171 VirtProcr *creatingPr, int32 coreToScheduleOnto );
|
|
SeanHalle@1
|
172
|
|
SeanHalle@1
|
173 inline void
|
|
Me@0
|
174 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
|
|
Me@0
|
175
|
|
Me@0
|
176 //=======================
|
|
SeanHalle@1
|
177 inline void
|
|
Me@0
|
178 VPThread__set_globals_to( void *globals );
|
|
Me@0
|
179
|
|
SeanHalle@1
|
180 inline void *
|
|
Me@0
|
181 VPThread__give_globals();
|
|
Me@0
|
182
|
|
Me@0
|
183 //=======================
|
|
SeanHalle@1
|
184 inline int32
|
|
Me@0
|
185 VPThread__make_mutex( VirtProcr *animPr );
|
|
Me@0
|
186
|
|
SeanHalle@1
|
187 inline void
|
|
Me@0
|
188 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
|
|
Me@0
|
189
|
|
SeanHalle@1
|
190 inline void
|
|
Me@0
|
191 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
|
|
Me@0
|
192
|
|
Me@0
|
193
|
|
Me@0
|
194 //=======================
|
|
SeanHalle@1
|
195 inline int32
|
|
Me@0
|
196 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
|
|
Me@0
|
197
|
|
SeanHalle@1
|
198 inline void
|
|
Me@0
|
199 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
|
|
Me@0
|
200
|
|
SeanHalle@1
|
201 inline void *
|
|
Me@0
|
202 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
|
|
Me@0
|
203
|
|
Me@0
|
204
|
|
Me@2
|
205 //=======================
|
|
Me@3
|
206 void
|
|
Me@3
|
207 VPThread__start_fn_singleton( int32 singletonID, VirtProcr *animPr );
|
|
Me@2
|
208
|
|
Me@2
|
209 void
|
|
Me@3
|
210 VPThread__end_fn_singleton( int32 singletonID, VirtProcr *animPr );
|
|
Me@2
|
211
|
|
Me@3
|
212 void
|
|
Me@3
|
213 VPThread__start_data_singleton( VPThdSingleton **singeltonAddr, VirtProcr *animPr );
|
|
Me@3
|
214
|
|
Me@3
|
215 void
|
|
Me@3
|
216 VPThread__end_data_singleton( VPThdSingleton **singletonAddr, VirtProcr *animPr );
|
|
Me@2
|
217
|
|
Me@2
|
218 void
|
|
Me@2
|
219 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
|
|
Me@2
|
220 void *data, VirtProcr *animPr );
|
|
Me@2
|
221
|
|
Me@2
|
222 void
|
|
Me@2
|
223 VPThread__start_transaction( int32 transactionID, VirtProcr *animPr );
|
|
Me@2
|
224
|
|
Me@2
|
225 void
|
|
Me@2
|
226 VPThread__end_transaction( int32 transactionID, VirtProcr *animPr );
|
|
Me@2
|
227
|
|
Me@0
|
228
|
|
Me@0
|
229
|
|
Me@0
|
230 //========================= Internal use only =============================
|
|
SeanHalle@1
|
231 inline void
|
|
Me@0
|
232 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
|
|
Me@0
|
233
|
|
SeanHalle@1
|
234 inline VirtProcr *
|
|
Me@0
|
235 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
|
|
Me@0
|
236
|
|
Me@0
|
237 //=======================
|
|
SeanHalle@1
|
238 inline void
|
|
SeanHalle@1
|
239 VPThread__free_semantic_request( VPThdSemReq *semReq );
|
|
Me@0
|
240
|
|
Me@0
|
241 //=======================
|
|
Me@0
|
242
|
|
Me@0
|
243 void
|
|
Me@0
|
244 VPThread__init();
|
|
Me@0
|
245
|
|
Me@0
|
246 void
|
|
Me@0
|
247 VPThread__cleanup_after_shutdown();
|
|
Me@0
|
248
|
|
Me@3
|
249 void inline
|
|
Me@3
|
250 resume_procr( VirtProcr *procr, VPThdSemEnv *semEnv );
|
|
Me@3
|
251
|
|
Me@0
|
252 #endif /* _VPThread_H */
|
|
Me@0
|
253
|