Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > Vthread_impls > Vthread_MC_shared_impl
view VPThread.h @ 2:e960a8d18f7c
Added singleton, atomic, transactions -- don't think it's working singletons yet
| author | Me |
|---|---|
| date | Tue, 16 Nov 2010 16:04:29 +0100 |
| parents | 1d3157ac56c4 |
| children | 505d3c674ce8 |
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/VMS.h"
13 #include "VMS/Queue_impl/PrivateQueue.h"
14 #include "VMS/DynArray/DynArray.h"
17 /*This header defines everything specific to the VPThread semantic plug-in
18 */
21 //===========================================================================
22 #define INIT_NUM_MUTEX 10000
23 #define INIT_NUM_COND 10000
25 #define NUM_STRUCS_IN_SEM_ENV 1000
26 //===========================================================================
28 //===========================================================================
29 typedef struct _VPThreadSemReq VPThdSemReq;
30 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
31 //===========================================================================
34 /*Semantic layer-specific data sent inside a request from lib called in app
35 * to request handler called in MasterLoop
36 */
37 enum VPThreadReqType
38 {
39 make_mutex = 1,
40 mutex_lock,
41 mutex_unlock,
42 make_cond,
43 cond_wait,
44 cond_signal,
45 make_procr,
46 malloc_req,
47 free_req,
48 singleton_start,
49 singleton_end,
50 atomic,
51 trans_start,
52 trans_end
53 };
55 struct _VPThreadSemReq
56 { enum VPThreadReqType reqType;
57 VirtProcr *requestingPr;
58 int32 mutexIdx;
59 int32 condIdx;
61 void *initData;
62 VirtProcrFnPtr fnPtr;
63 int32 coreToScheduleOnto;
65 int32 sizeToMalloc;
66 void *ptrToFree;
68 int32 singletonID;
69 void *endJumpPt;
71 PtrToAtomicFn fnToExecInMaster;
72 void *dataForFn;
74 int32 transID;
75 }
76 /* VPThreadSemReq */;
79 typedef struct
80 {
81 VirtProcr *VPCurrentlyExecuting;
82 PrivQueueStruc *waitingVPQ;
83 }
84 VPThdTrans;
86 typedef struct
87 {
88 int32 hasBeenStarted;
89 int32 hasFinished;
90 void *endInstrAddr;
91 PrivQueueStruc *waitQ;
92 }
93 VPThdSingleton;
95 typedef struct
96 {
97 int32 mutexIdx;
98 VirtProcr *holderOfLock;
99 PrivQueueStruc *waitingQueue;
100 }
101 VPThdMutex;
104 typedef struct
105 {
106 int32 condIdx;
107 PrivQueueStruc *waitingQueue;
108 VPThdMutex *partnerMutex;
109 }
110 VPThdCond;
112 typedef struct _TransListElem TransListElem;
113 struct _TransListElem
114 {
115 int32 transID;
116 TransListElem *nextTrans;
117 };
118 //TransListElem
120 typedef struct
121 {
122 int32 highestTransEntered;
123 TransListElem *lastTransEntered;
124 }
125 VPThdSemData;
128 typedef struct
129 {
130 //Standard stuff will be in most every semantic env
131 PrivQueueStruc **readyVPQs;
132 int32 numVirtPr;
133 int32 nextCoreToGetNewPr;
134 int32 primitiveStartTime;
136 //Specific to this semantic layer
137 VPThdMutex **mutexDynArray;
138 PrivDynArrayInfo *mutexDynArrayInfo;
140 VPThdCond **condDynArray;
141 PrivDynArrayInfo *condDynArrayInfo;
143 void *applicationGlobals;
145 //fix limit on num with dynArray
146 VPThdSingleton singletons[NUM_STRUCS_IN_SEM_ENV];
147 void *singletonEndInstrAddr;
149 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
150 }
151 VPThdSemEnv;
154 //===========================================================================
156 inline void
157 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
159 //=======================
161 inline VirtProcr *
162 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
163 VirtProcr *creatingPr );
165 inline VirtProcr *
166 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
167 VirtProcr *creatingPr, int32 coreToScheduleOnto );
169 inline void
170 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
172 //=======================
173 inline void
174 VPThread__set_globals_to( void *globals );
176 inline void *
177 VPThread__give_globals();
179 //=======================
180 inline int32
181 VPThread__make_mutex( VirtProcr *animPr );
183 inline void
184 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
186 inline void
187 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
190 //=======================
191 inline int32
192 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
194 inline void
195 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
197 inline void *
198 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
201 //=======================
203 void
204 VPThread__end_singleton( int32 singletonID, VirtProcr *animPr );
206 inline void
207 VPThread__start_singleton( int32 singletonID, VirtProcr *animPr );
209 void
210 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
211 void *data, VirtProcr *animPr );
213 void
214 VPThread__start_transaction( int32 transactionID, VirtProcr *animPr );
216 void
217 VPThread__end_transaction( int32 transactionID, VirtProcr *animPr );
221 //========================= Internal use only =============================
222 inline void
223 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
225 inline VirtProcr *
226 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
228 //=======================
229 inline void
230 VPThread__free_semantic_request( VPThdSemReq *semReq );
232 //=======================
234 void
235 VPThread__init();
237 void
238 VPThread__cleanup_after_shutdown();
240 #endif /* _VPThread_H */
