| 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@0
|
34 /*Semantic layer-specific data sent inside a request from lib called in app
|
|
Me@0
|
35 * to request handler called in MasterLoop
|
|
Me@0
|
36 */
|
|
Me@0
|
37 enum VPThreadReqType
|
|
Me@0
|
38 {
|
|
Me@0
|
39 make_mutex = 1,
|
|
Me@0
|
40 mutex_lock,
|
|
Me@0
|
41 mutex_unlock,
|
|
Me@0
|
42 make_cond,
|
|
Me@0
|
43 cond_wait,
|
|
Me@0
|
44 cond_signal,
|
|
SeanHalle@1
|
45 make_procr,
|
|
SeanHalle@1
|
46 malloc_req,
|
|
SeanHalle@1
|
47 free_req,
|
|
SeanHalle@1
|
48 singleton,
|
|
SeanHalle@1
|
49 atomic,
|
|
SeanHalle@1
|
50 trans_start,
|
|
SeanHalle@1
|
51 trans_end
|
|
Me@0
|
52 };
|
|
Me@0
|
53
|
|
Me@0
|
54 struct _VPThreadSemReq
|
|
Me@0
|
55 { enum VPThreadReqType reqType;
|
|
Me@0
|
56 VirtProcr *requestingPr;
|
|
Me@0
|
57 int32 mutexIdx;
|
|
Me@0
|
58 int32 condIdx;
|
|
SeanHalle@1
|
59
|
|
Me@0
|
60 void *initData;
|
|
Me@0
|
61 VirtProcrFnPtr fnPtr;
|
|
SeanHalle@1
|
62 int32 coreToScheduleOnto;
|
|
SeanHalle@1
|
63
|
|
SeanHalle@1
|
64 int32 sizeToMalloc;
|
|
SeanHalle@1
|
65 void *ptrToFree;
|
|
SeanHalle@1
|
66
|
|
SeanHalle@1
|
67 int32 singletonID;
|
|
SeanHalle@1
|
68 void *endJumpPt;
|
|
SeanHalle@1
|
69
|
|
SeanHalle@1
|
70 PtrToAtomicFn fnToExecInMaster;
|
|
SeanHalle@1
|
71 void *dataForFn;
|
|
SeanHalle@1
|
72
|
|
SeanHalle@1
|
73 int32 transID;
|
|
Me@0
|
74 }
|
|
Me@0
|
75 /* VPThreadSemReq */;
|
|
Me@0
|
76
|
|
SeanHalle@1
|
77
|
|
SeanHalle@1
|
78 typedef struct
|
|
SeanHalle@1
|
79 {
|
|
SeanHalle@1
|
80 VirtProcr *VPCurrentlyExecuting;
|
|
SeanHalle@1
|
81 PrivQueueStruc *waitingVPQ;
|
|
SeanHalle@1
|
82 }
|
|
SeanHalle@1
|
83 VPThdTrans;
|
|
SeanHalle@1
|
84
|
|
SeanHalle@1
|
85
|
|
Me@0
|
86 typedef struct
|
|
Me@0
|
87 {
|
|
Me@0
|
88 //Standard stuff will be in most every semantic env
|
|
SeanHalle@1
|
89 PrivQueueStruc **readyVPQs;
|
|
SeanHalle@1
|
90 int32 numVirtPr;
|
|
SeanHalle@1
|
91 int32 nextCoreToGetNewPr;
|
|
SeanHalle@1
|
92 int32 primitiveStartTime;
|
|
Me@0
|
93
|
|
Me@0
|
94 //Specific to this semantic layer
|
|
SeanHalle@1
|
95 VPThdMutex **mutexDynArray;
|
|
SeanHalle@1
|
96 PrivDynArrayInfo *mutexDynArrayInfo;
|
|
Me@0
|
97
|
|
SeanHalle@1
|
98 VPThdCond **condDynArray;
|
|
SeanHalle@1
|
99 PrivDynArrayInfo *condDynArrayInfo;
|
|
SeanHalle@1
|
100
|
|
SeanHalle@1
|
101 void *applicationGlobals;
|
|
SeanHalle@1
|
102
|
|
SeanHalle@1
|
103 //fix limit on num with dynArray
|
|
SeanHalle@1
|
104 int32 singletonHasBeenExecutedFlags[NUM_STRUCS_IN_SEM_ENV];
|
|
SeanHalle@1
|
105 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
|
|
Me@0
|
106 }
|
|
SeanHalle@1
|
107 VPThdSemEnv;
|
|
Me@0
|
108
|
|
Me@0
|
109
|
|
Me@0
|
110 typedef struct
|
|
Me@0
|
111 {
|
|
Me@0
|
112 int32 mutexIdx;
|
|
Me@0
|
113 VirtProcr *holderOfLock;
|
|
Me@0
|
114 PrivQueueStruc *waitingQueue;
|
|
Me@0
|
115 }
|
|
SeanHalle@1
|
116 VPThdMutex;
|
|
Me@0
|
117
|
|
Me@0
|
118
|
|
Me@0
|
119 typedef struct
|
|
Me@0
|
120 {
|
|
Me@0
|
121 int32 condIdx;
|
|
Me@0
|
122 PrivQueueStruc *waitingQueue;
|
|
SeanHalle@1
|
123 VPThdMutex *partnerMutex;
|
|
Me@0
|
124 }
|
|
SeanHalle@1
|
125 VPThdCond;
|
|
SeanHalle@1
|
126
|
|
SeanHalle@1
|
127 typedef struct _TransListElem TransListElem;
|
|
SeanHalle@1
|
128 struct _TransListElem
|
|
SeanHalle@1
|
129 {
|
|
SeanHalle@1
|
130 int32 transID;
|
|
SeanHalle@1
|
131 TransListElem *nextTrans;
|
|
SeanHalle@1
|
132 };
|
|
SeanHalle@1
|
133 //TransListElem
|
|
SeanHalle@1
|
134
|
|
SeanHalle@1
|
135 typedef struct
|
|
SeanHalle@1
|
136 {
|
|
SeanHalle@1
|
137 int32 highestTransEntered;
|
|
SeanHalle@1
|
138 TransListElem *lastTransEntered;
|
|
SeanHalle@1
|
139 }
|
|
SeanHalle@1
|
140 VPThdSemData;
|
|
Me@0
|
141
|
|
Me@0
|
142
|
|
Me@0
|
143 //===========================================================================
|
|
Me@0
|
144
|
|
SeanHalle@1
|
145 inline void
|
|
Me@0
|
146 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
|
|
Me@0
|
147
|
|
Me@0
|
148 //=======================
|
|
Me@0
|
149
|
|
Me@0
|
150 inline VirtProcr *
|
|
Me@0
|
151 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
|
|
Me@0
|
152 VirtProcr *creatingPr );
|
|
Me@0
|
153
|
|
SeanHalle@1
|
154 inline VirtProcr *
|
|
SeanHalle@1
|
155 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
|
|
SeanHalle@1
|
156 VirtProcr *creatingPr, int32 coreToScheduleOnto );
|
|
SeanHalle@1
|
157
|
|
SeanHalle@1
|
158 inline void
|
|
Me@0
|
159 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
|
|
Me@0
|
160
|
|
Me@0
|
161 //=======================
|
|
SeanHalle@1
|
162 inline void
|
|
Me@0
|
163 VPThread__set_globals_to( void *globals );
|
|
Me@0
|
164
|
|
SeanHalle@1
|
165 inline void *
|
|
Me@0
|
166 VPThread__give_globals();
|
|
Me@0
|
167
|
|
Me@0
|
168 //=======================
|
|
SeanHalle@1
|
169 inline int32
|
|
Me@0
|
170 VPThread__make_mutex( VirtProcr *animPr );
|
|
Me@0
|
171
|
|
SeanHalle@1
|
172 inline void
|
|
Me@0
|
173 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
|
|
Me@0
|
174
|
|
SeanHalle@1
|
175 inline void
|
|
Me@0
|
176 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
|
|
Me@0
|
177
|
|
Me@0
|
178
|
|
Me@0
|
179 //=======================
|
|
SeanHalle@1
|
180 inline int32
|
|
Me@0
|
181 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
|
|
Me@0
|
182
|
|
SeanHalle@1
|
183 inline void
|
|
Me@0
|
184 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
|
|
Me@0
|
185
|
|
SeanHalle@1
|
186 inline void *
|
|
Me@0
|
187 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
|
|
Me@0
|
188
|
|
Me@0
|
189
|
|
Me@0
|
190
|
|
Me@0
|
191
|
|
Me@0
|
192 //========================= Internal use only =============================
|
|
SeanHalle@1
|
193 inline void
|
|
Me@0
|
194 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
|
|
Me@0
|
195
|
|
SeanHalle@1
|
196 inline VirtProcr *
|
|
Me@0
|
197 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
|
|
Me@0
|
198
|
|
Me@0
|
199 //=======================
|
|
SeanHalle@1
|
200 inline void
|
|
SeanHalle@1
|
201 VPThread__free_semantic_request( VPThdSemReq *semReq );
|
|
Me@0
|
202
|
|
Me@0
|
203 //=======================
|
|
Me@0
|
204
|
|
Me@0
|
205 void
|
|
Me@0
|
206 VPThread__init();
|
|
Me@0
|
207
|
|
Me@0
|
208 void
|
|
Me@0
|
209 VPThread__cleanup_after_shutdown();
|
|
Me@0
|
210
|
|
Me@0
|
211 #endif /* _VPThread_H */
|
|
Me@0
|
212
|