annotate 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
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,
Me@2 48 singleton_start,
Me@2 49 singleton_end,
SeanHalle@1 50 atomic,
SeanHalle@1 51 trans_start,
SeanHalle@1 52 trans_end
Me@0 53 };
Me@0 54
Me@0 55 struct _VPThreadSemReq
Me@0 56 { enum VPThreadReqType reqType;
Me@0 57 VirtProcr *requestingPr;
Me@0 58 int32 mutexIdx;
Me@0 59 int32 condIdx;
SeanHalle@1 60
Me@0 61 void *initData;
Me@0 62 VirtProcrFnPtr fnPtr;
SeanHalle@1 63 int32 coreToScheduleOnto;
SeanHalle@1 64
SeanHalle@1 65 int32 sizeToMalloc;
SeanHalle@1 66 void *ptrToFree;
SeanHalle@1 67
SeanHalle@1 68 int32 singletonID;
SeanHalle@1 69 void *endJumpPt;
SeanHalle@1 70
SeanHalle@1 71 PtrToAtomicFn fnToExecInMaster;
SeanHalle@1 72 void *dataForFn;
SeanHalle@1 73
SeanHalle@1 74 int32 transID;
Me@0 75 }
Me@0 76 /* VPThreadSemReq */;
Me@0 77
SeanHalle@1 78
SeanHalle@1 79 typedef struct
SeanHalle@1 80 {
SeanHalle@1 81 VirtProcr *VPCurrentlyExecuting;
SeanHalle@1 82 PrivQueueStruc *waitingVPQ;
SeanHalle@1 83 }
SeanHalle@1 84 VPThdTrans;
SeanHalle@1 85
Me@0 86 typedef struct
Me@0 87 {
Me@2 88 int32 hasBeenStarted;
Me@2 89 int32 hasFinished;
Me@2 90 void *endInstrAddr;
Me@2 91 PrivQueueStruc *waitQ;
Me@0 92 }
Me@2 93 VPThdSingleton;
Me@0 94
Me@0 95 typedef struct
Me@0 96 {
Me@0 97 int32 mutexIdx;
Me@0 98 VirtProcr *holderOfLock;
Me@0 99 PrivQueueStruc *waitingQueue;
Me@0 100 }
SeanHalle@1 101 VPThdMutex;
Me@0 102
Me@0 103
Me@0 104 typedef struct
Me@0 105 {
Me@0 106 int32 condIdx;
Me@0 107 PrivQueueStruc *waitingQueue;
SeanHalle@1 108 VPThdMutex *partnerMutex;
Me@0 109 }
SeanHalle@1 110 VPThdCond;
SeanHalle@1 111
SeanHalle@1 112 typedef struct _TransListElem TransListElem;
SeanHalle@1 113 struct _TransListElem
SeanHalle@1 114 {
SeanHalle@1 115 int32 transID;
SeanHalle@1 116 TransListElem *nextTrans;
SeanHalle@1 117 };
SeanHalle@1 118 //TransListElem
SeanHalle@1 119
SeanHalle@1 120 typedef struct
SeanHalle@1 121 {
SeanHalle@1 122 int32 highestTransEntered;
SeanHalle@1 123 TransListElem *lastTransEntered;
SeanHalle@1 124 }
SeanHalle@1 125 VPThdSemData;
Me@0 126
Me@0 127
Me@2 128 typedef struct
Me@2 129 {
Me@2 130 //Standard stuff will be in most every semantic env
Me@2 131 PrivQueueStruc **readyVPQs;
Me@2 132 int32 numVirtPr;
Me@2 133 int32 nextCoreToGetNewPr;
Me@2 134 int32 primitiveStartTime;
Me@2 135
Me@2 136 //Specific to this semantic layer
Me@2 137 VPThdMutex **mutexDynArray;
Me@2 138 PrivDynArrayInfo *mutexDynArrayInfo;
Me@2 139
Me@2 140 VPThdCond **condDynArray;
Me@2 141 PrivDynArrayInfo *condDynArrayInfo;
Me@2 142
Me@2 143 void *applicationGlobals;
Me@2 144
Me@2 145 //fix limit on num with dynArray
Me@2 146 VPThdSingleton singletons[NUM_STRUCS_IN_SEM_ENV];
Me@2 147 void *singletonEndInstrAddr;
Me@2 148
Me@2 149 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
Me@2 150 }
Me@2 151 VPThdSemEnv;
Me@2 152
Me@2 153
Me@0 154 //===========================================================================
Me@0 155
SeanHalle@1 156 inline void
Me@0 157 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
Me@0 158
Me@0 159 //=======================
Me@0 160
Me@0 161 inline VirtProcr *
Me@0 162 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
Me@0 163 VirtProcr *creatingPr );
Me@0 164
SeanHalle@1 165 inline VirtProcr *
SeanHalle@1 166 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
SeanHalle@1 167 VirtProcr *creatingPr, int32 coreToScheduleOnto );
SeanHalle@1 168
SeanHalle@1 169 inline void
Me@0 170 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
Me@0 171
Me@0 172 //=======================
SeanHalle@1 173 inline void
Me@0 174 VPThread__set_globals_to( void *globals );
Me@0 175
SeanHalle@1 176 inline void *
Me@0 177 VPThread__give_globals();
Me@0 178
Me@0 179 //=======================
SeanHalle@1 180 inline int32
Me@0 181 VPThread__make_mutex( VirtProcr *animPr );
Me@0 182
SeanHalle@1 183 inline void
Me@0 184 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
Me@0 185
SeanHalle@1 186 inline void
Me@0 187 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
Me@0 188
Me@0 189
Me@0 190 //=======================
SeanHalle@1 191 inline int32
Me@0 192 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
Me@0 193
SeanHalle@1 194 inline void
Me@0 195 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
Me@0 196
SeanHalle@1 197 inline void *
Me@0 198 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
Me@0 199
Me@0 200
Me@2 201 //=======================
Me@2 202
Me@2 203 void
Me@2 204 VPThread__end_singleton( int32 singletonID, VirtProcr *animPr );
Me@2 205
Me@2 206 inline void
Me@2 207 VPThread__start_singleton( int32 singletonID, VirtProcr *animPr );
Me@2 208
Me@2 209 void
Me@2 210 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
Me@2 211 void *data, VirtProcr *animPr );
Me@2 212
Me@2 213 void
Me@2 214 VPThread__start_transaction( int32 transactionID, VirtProcr *animPr );
Me@2 215
Me@2 216 void
Me@2 217 VPThread__end_transaction( int32 transactionID, VirtProcr *animPr );
Me@2 218
Me@0 219
Me@0 220
Me@0 221 //========================= Internal use only =============================
SeanHalle@1 222 inline void
Me@0 223 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
Me@0 224
SeanHalle@1 225 inline VirtProcr *
Me@0 226 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
Me@0 227
Me@0 228 //=======================
SeanHalle@1 229 inline void
SeanHalle@1 230 VPThread__free_semantic_request( VPThdSemReq *semReq );
Me@0 231
Me@0 232 //=======================
Me@0 233
Me@0 234 void
Me@0 235 VPThread__init();
Me@0 236
Me@0 237 void
Me@0 238 VPThread__cleanup_after_shutdown();
Me@0 239
Me@0 240 #endif /* _VPThread_H */
Me@0 241