Me@0: /* Me@0: * Copyright 2009 OpenSourceStewardshipFoundation.org Me@0: * Licensed under GNU General Public License version 2 Me@0: * Me@0: * Author: seanhalle@yahoo.com Me@0: * Me@0: */ Me@0: Me@0: #ifndef _VPThread_H Me@0: #define _VPThread_H Me@0: Me@0: #include "VMS/VMS.h" Me@0: #include "VMS/Queue_impl/PrivateQueue.h" Me@0: #include "VMS/DynArray/DynArray.h" Me@0: Me@0: SeanHalle@1: /*This header defines everything specific to the VPThread semantic plug-in SeanHalle@1: */ SeanHalle@1: SeanHalle@1: Me@0: //=========================================================================== Me@0: #define INIT_NUM_MUTEX 10000 Me@0: #define INIT_NUM_COND 10000 SeanHalle@1: SeanHalle@1: #define NUM_STRUCS_IN_SEM_ENV 1000 Me@0: //=========================================================================== Me@0: SeanHalle@1: //=========================================================================== SeanHalle@1: typedef struct _VPThreadSemReq VPThdSemReq; SeanHalle@1: typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master SeanHalle@1: //=========================================================================== Me@0: Me@0: Me@0: /*Semantic layer-specific data sent inside a request from lib called in app Me@0: * to request handler called in MasterLoop Me@0: */ Me@0: enum VPThreadReqType Me@0: { Me@0: make_mutex = 1, Me@0: mutex_lock, Me@0: mutex_unlock, Me@0: make_cond, Me@0: cond_wait, Me@0: cond_signal, SeanHalle@1: make_procr, SeanHalle@1: malloc_req, SeanHalle@1: free_req, Me@2: singleton_start, Me@2: singleton_end, SeanHalle@1: atomic, SeanHalle@1: trans_start, SeanHalle@1: trans_end Me@0: }; Me@0: Me@0: struct _VPThreadSemReq Me@0: { enum VPThreadReqType reqType; Me@0: VirtProcr *requestingPr; Me@0: int32 mutexIdx; Me@0: int32 condIdx; SeanHalle@1: Me@0: void *initData; Me@0: VirtProcrFnPtr fnPtr; SeanHalle@1: int32 coreToScheduleOnto; SeanHalle@1: SeanHalle@1: int32 sizeToMalloc; SeanHalle@1: void *ptrToFree; SeanHalle@1: SeanHalle@1: int32 singletonID; SeanHalle@1: void *endJumpPt; SeanHalle@1: SeanHalle@1: PtrToAtomicFn fnToExecInMaster; SeanHalle@1: void *dataForFn; SeanHalle@1: SeanHalle@1: int32 transID; Me@0: } Me@0: /* VPThreadSemReq */; Me@0: SeanHalle@1: SeanHalle@1: typedef struct SeanHalle@1: { SeanHalle@1: VirtProcr *VPCurrentlyExecuting; SeanHalle@1: PrivQueueStruc *waitingVPQ; SeanHalle@1: } SeanHalle@1: VPThdTrans; SeanHalle@1: Me@0: typedef struct Me@0: { Me@2: int32 hasBeenStarted; Me@2: int32 hasFinished; Me@2: void *endInstrAddr; Me@2: PrivQueueStruc *waitQ; Me@0: } Me@2: VPThdSingleton; Me@0: Me@0: typedef struct Me@0: { Me@0: int32 mutexIdx; Me@0: VirtProcr *holderOfLock; Me@0: PrivQueueStruc *waitingQueue; Me@0: } SeanHalle@1: VPThdMutex; Me@0: Me@0: Me@0: typedef struct Me@0: { Me@0: int32 condIdx; Me@0: PrivQueueStruc *waitingQueue; SeanHalle@1: VPThdMutex *partnerMutex; Me@0: } SeanHalle@1: VPThdCond; SeanHalle@1: SeanHalle@1: typedef struct _TransListElem TransListElem; SeanHalle@1: struct _TransListElem SeanHalle@1: { SeanHalle@1: int32 transID; SeanHalle@1: TransListElem *nextTrans; SeanHalle@1: }; SeanHalle@1: //TransListElem SeanHalle@1: SeanHalle@1: typedef struct SeanHalle@1: { SeanHalle@1: int32 highestTransEntered; SeanHalle@1: TransListElem *lastTransEntered; SeanHalle@1: } SeanHalle@1: VPThdSemData; Me@0: Me@0: Me@2: typedef struct Me@2: { Me@2: //Standard stuff will be in most every semantic env Me@2: PrivQueueStruc **readyVPQs; Me@2: int32 numVirtPr; Me@2: int32 nextCoreToGetNewPr; Me@2: int32 primitiveStartTime; Me@2: Me@2: //Specific to this semantic layer Me@2: VPThdMutex **mutexDynArray; Me@2: PrivDynArrayInfo *mutexDynArrayInfo; Me@2: Me@2: VPThdCond **condDynArray; Me@2: PrivDynArrayInfo *condDynArrayInfo; Me@2: Me@2: void *applicationGlobals; Me@2: Me@2: //fix limit on num with dynArray Me@2: VPThdSingleton singletons[NUM_STRUCS_IN_SEM_ENV]; Me@2: void *singletonEndInstrAddr; Me@2: Me@2: VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV]; Me@2: } Me@2: VPThdSemEnv; Me@2: Me@2: Me@0: //=========================================================================== Me@0: SeanHalle@1: inline void Me@0: VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData ); Me@0: Me@0: //======================= Me@0: Me@0: inline VirtProcr * Me@0: VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData, Me@0: VirtProcr *creatingPr ); Me@0: SeanHalle@1: inline VirtProcr * SeanHalle@1: VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData, SeanHalle@1: VirtProcr *creatingPr, int32 coreToScheduleOnto ); SeanHalle@1: SeanHalle@1: inline void Me@0: VPThread__dissipate_thread( VirtProcr *procrToDissipate ); Me@0: Me@0: //======================= SeanHalle@1: inline void Me@0: VPThread__set_globals_to( void *globals ); Me@0: SeanHalle@1: inline void * Me@0: VPThread__give_globals(); Me@0: Me@0: //======================= SeanHalle@1: inline int32 Me@0: VPThread__make_mutex( VirtProcr *animPr ); Me@0: SeanHalle@1: inline void Me@0: VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr ); Me@0: SeanHalle@1: inline void Me@0: VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr ); Me@0: Me@0: Me@0: //======================= SeanHalle@1: inline int32 Me@0: VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr); Me@0: SeanHalle@1: inline void Me@0: VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr); Me@0: SeanHalle@1: inline void * Me@0: VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr ); Me@0: Me@0: Me@2: //======================= Me@2: Me@2: void Me@2: VPThread__end_singleton( int32 singletonID, VirtProcr *animPr ); Me@2: Me@2: inline void Me@2: VPThread__start_singleton( int32 singletonID, VirtProcr *animPr ); Me@2: Me@2: void Me@2: VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, Me@2: void *data, VirtProcr *animPr ); Me@2: Me@2: void Me@2: VPThread__start_transaction( int32 transactionID, VirtProcr *animPr ); Me@2: Me@2: void Me@2: VPThread__end_transaction( int32 transactionID, VirtProcr *animPr ); Me@2: Me@0: Me@0: Me@0: //========================= Internal use only ============================= SeanHalle@1: inline void Me@0: VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv ); Me@0: SeanHalle@1: inline VirtProcr * Me@0: VPThread__schedule_virt_procr( void *_semEnv, int coreNum ); Me@0: Me@0: //======================= SeanHalle@1: inline void SeanHalle@1: VPThread__free_semantic_request( VPThdSemReq *semReq ); Me@0: Me@0: //======================= Me@0: Me@0: void Me@0: VPThread__init(); Me@0: Me@0: void Me@0: VPThread__cleanup_after_shutdown(); Me@0: Me@0: #endif /* _VPThread_H */ Me@0: