comparison VPThread.h @ 1:1d3157ac56c4

Updated to Nov 8 version of VMS -- added singleton, trans, etc
author SeanHalle
date Thu, 11 Nov 2010 04:29:10 -0800
parents 4aca264971b5
children e960a8d18f7c
comparison
equal deleted inserted replaced
0:42d8405922fb 1:3e4a0a56c597
12 #include "VMS/VMS.h" 12 #include "VMS/VMS.h"
13 #include "VMS/Queue_impl/PrivateQueue.h" 13 #include "VMS/Queue_impl/PrivateQueue.h"
14 #include "VMS/DynArray/DynArray.h" 14 #include "VMS/DynArray/DynArray.h"
15 15
16 16
17 /*This header defines everything specific to the VPThread semantic plug-in
18 */
19
20
17 //=========================================================================== 21 //===========================================================================
18 #define INIT_NUM_MUTEX 10000 22 #define INIT_NUM_MUTEX 10000
19 #define INIT_NUM_COND 10000 23 #define INIT_NUM_COND 10000
20 //=========================================================================== 24
21 25 #define NUM_STRUCS_IN_SEM_ENV 1000
22 /*This header defines everything specific to the VPThread semantic plug-in 26 //===========================================================================
23 */ 27
24 typedef struct _VPThreadSemReq VPThreadSemReq; 28 //===========================================================================
29 typedef struct _VPThreadSemReq VPThdSemReq;
30 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
31 //===========================================================================
25 32
26 33
27 /*Semantic layer-specific data sent inside a request from lib called in app 34 /*Semantic layer-specific data sent inside a request from lib called in app
28 * to request handler called in MasterLoop 35 * to request handler called in MasterLoop
29 */ 36 */
33 mutex_lock, 40 mutex_lock,
34 mutex_unlock, 41 mutex_unlock,
35 make_cond, 42 make_cond,
36 cond_wait, 43 cond_wait,
37 cond_signal, 44 cond_signal,
38 make_procr 45 make_procr,
46 malloc_req,
47 free_req,
48 singleton,
49 atomic,
50 trans_start,
51 trans_end
39 }; 52 };
40 53
41 struct _VPThreadSemReq 54 struct _VPThreadSemReq
42 { enum VPThreadReqType reqType; 55 { enum VPThreadReqType reqType;
43 VirtProcr *requestingPr; 56 VirtProcr *requestingPr;
44 int32 mutexIdx; 57 int32 mutexIdx;
45 int32 condIdx; 58 int32 condIdx;
59
46 void *initData; 60 void *initData;
47 VirtProcrFnPtr fnPtr; 61 VirtProcrFnPtr fnPtr;
62 int32 coreToScheduleOnto;
63
64 int32 sizeToMalloc;
65 void *ptrToFree;
66
67 int32 singletonID;
68 void *endJumpPt;
69
70 PtrToAtomicFn fnToExecInMaster;
71 void *dataForFn;
72
73 int32 transID;
48 } 74 }
49 /* VPThreadSemReq */; 75 /* VPThreadSemReq */;
50 76
77
78 typedef struct
79 {
80 VirtProcr *VPCurrentlyExecuting;
81 PrivQueueStruc *waitingVPQ;
82 }
83 VPThdTrans;
84
85
51 typedef struct 86 typedef struct
52 { 87 {
53 //Standard stuff will be in most every semantic env 88 //Standard stuff will be in most every semantic env
54 PrivQueueStruc **readyVPQs; 89 PrivQueueStruc **readyVPQs;
55 int32 numVirtPr; 90 int32 numVirtPr;
56 int32 nextCoreToGetNewPr; 91 int32 nextCoreToGetNewPr;
92 int32 primitiveStartTime;
57 93
58 //Specific to this semantic layer 94 //Specific to this semantic layer
59 int32 currMutexIdx; 95 VPThdMutex **mutexDynArray;
60 DynArray32 *mutexDynArray; 96 PrivDynArrayInfo *mutexDynArrayInfo;
61 97
62 int32 currCondIdx; 98 VPThdCond **condDynArray;
63 DynArray32 *condDynArray; 99 PrivDynArrayInfo *condDynArrayInfo;
64 100
65 void *applicationGlobals; 101 void *applicationGlobals;
66 } 102
67 VPThreadSemEnv; 103 //fix limit on num with dynArray
104 int32 singletonHasBeenExecutedFlags[NUM_STRUCS_IN_SEM_ENV];
105 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
106 }
107 VPThdSemEnv;
68 108
69 109
70 typedef struct 110 typedef struct
71 { 111 {
72 int32 mutexIdx; 112 int32 mutexIdx;
73 VirtProcr *holderOfLock; 113 VirtProcr *holderOfLock;
74 PrivQueueStruc *waitingQueue; 114 PrivQueueStruc *waitingQueue;
75 } 115 }
76 VPTMutex; 116 VPThdMutex;
77 117
78 118
79 typedef struct 119 typedef struct
80 { 120 {
81 int32 condIdx; 121 int32 condIdx;
82 PrivQueueStruc *waitingQueue; 122 PrivQueueStruc *waitingQueue;
83 VPTMutex *partnerMutex; 123 VPThdMutex *partnerMutex;
84 } 124 }
85 VPTCond; 125 VPThdCond;
86 126
87 127 typedef struct _TransListElem TransListElem;
88 //=========================================================================== 128 struct _TransListElem
89 129 {
90 void 130 int32 transID;
131 TransListElem *nextTrans;
132 };
133 //TransListElem
134
135 typedef struct
136 {
137 int32 highestTransEntered;
138 TransListElem *lastTransEntered;
139 }
140 VPThdSemData;
141
142
143 //===========================================================================
144
145 inline void
91 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData ); 146 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
92 147
93 //======================= 148 //=======================
94 149
95 inline VirtProcr * 150 inline VirtProcr *
96 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData, 151 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
97 VirtProcr *creatingPr ); 152 VirtProcr *creatingPr );
98 153
99 void 154 inline VirtProcr *
155 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
156 VirtProcr *creatingPr, int32 coreToScheduleOnto );
157
158 inline void
100 VPThread__dissipate_thread( VirtProcr *procrToDissipate ); 159 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
101 160
102 //======================= 161 //=======================
103 void 162 inline void
104 VPThread__set_globals_to( void *globals ); 163 VPThread__set_globals_to( void *globals );
105 164
106 void * 165 inline void *
107 VPThread__give_globals(); 166 VPThread__give_globals();
108 167
109 //======================= 168 //=======================
110 int32 169 inline int32
111 VPThread__make_mutex( VirtProcr *animPr ); 170 VPThread__make_mutex( VirtProcr *animPr );
112 171
113 void 172 inline void
114 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr ); 173 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
115 174
116 void 175 inline void
117 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr ); 176 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
118 177
119 178
120 //======================= 179 //=======================
121 int32 180 inline int32
122 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr); 181 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
123 182
124 void 183 inline void
125 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr); 184 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
126 185
127 void * 186 inline void *
128 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr ); 187 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
129 188
130 189
131 190
132 191
133 //========================= Internal use only ============================= 192 //========================= Internal use only =============================
134 void 193 inline void
135 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv ); 194 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
136 195
137 VirtProcr * 196 inline VirtProcr *
138 VPThread__schedule_virt_procr( void *_semEnv, int coreNum ); 197 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
139 198
140 //======================= 199 //=======================
141 void 200 inline void
142 VPThread__free_semantic_request( VPThreadSemReq *semReq ); 201 VPThread__free_semantic_request( VPThdSemReq *semReq );
143 202
144 //======================= 203 //=======================
145 204
146 void 205 void
147 VPThread__init(); 206 VPThread__init();