Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff VMS.c @ 25:c556193f7211
Linux Version -- first set of mods changing from win to linux
| author | Me |
|---|---|
| date | Sat, 24 Jul 2010 08:58:47 -0700 |
| parents | 2b161e1a50ee |
| children | 668278fa7a63 |
line diff
1.1 --- a/VMS.c Wed Jul 07 13:15:54 2010 -0700 1.2 +++ b/VMS.c Sat Jul 24 08:58:47 2010 -0700 1.3 @@ -81,27 +81,33 @@ 1.4 1.5 //======================================================================== 1.6 // Create the Threads 1.7 - int coreIdx; 1.8 + int coreIdx, retCode; 1.9 + #define thdAttrs NULL 1.10 1.11 + _VMSMasterEnv->setupComplete = 0; 1.12 + _VMSMasterEnv->suspend_mutex = PTHREAD_MUTEX_INITIALIZER; 1.13 + _VMSMasterEnv->suspend_cond = PTHREAD_COND_INITIALIZER; 1.14 + 1.15 + //Need the threads to be created suspended, and wait for a signal 1.16 + // before proceeding -- gives time after creating to initialize other 1.17 + // stuff before the coreLoops set off. 1.18 + 1.19 //Make params given to the win threads that animate the core loops 1.20 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 1.21 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) ); 1.22 coreLoopThdParams[coreIdx]->coreNum = coreIdx; 1.23 1.24 - //make the core loop threads, born in suspended state 1.25 - coreLoopThdHandles[ coreIdx ] = 1.26 - CreateThread ( NULL, // Security attributes 1.27 - 0, // Stack size 1.28 - coreLoop, 1.29 - coreLoopThdParams[coreIdx], 1.30 - CREATE_SUSPENDED, 1.31 - &(coreLoopThdIds[coreIdx]) 1.32 - ); 1.33 + retCode = 1.34 + pthread_create( &(coreLoopThdHandles[coreIdx]), 1.35 + thdAttrs, 1.36 + &coreLoop, 1.37 + (void *)(coreLoopThdParams[coreIdx]) ); 1.38 + if(!retCode){printf("ERROR creating thread: %d\n", retCode); exit();} 1.39 } 1.40 1.41 + 1.42 } 1.43 1.44 - 1.45 void 1.46 create_sched_slots( MasterEnv *masterEnv ) 1.47 { SchedSlot **schedSlots, **filledSlots; 1.48 @@ -132,37 +138,39 @@ 1.49 { int coreIdx; 1.50 //Start the core loops running 1.51 //=========================================================================== 1.52 - LARGE_INTEGER stPerfCount, endPerfCount, countFreq; 1.53 + TSCount startCount, endCount; 1.54 unsigned long long count = 0, freq = 0; 1.55 - double runTime; 1.56 + double runTime; 1.57 1.58 - QueryPerformanceCounter( &stPerfCount ); 1.59 - 1.60 - //start them running 1.61 - for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 1.62 - { //Create the threads 1.63 - ResumeThread( coreLoopThdHandles[coreIdx] ); //starts thread 1.64 - } 1.65 - 1.66 + startCount = getTSCount(); 1.67 + 1.68 + //tell the core loop threads that setup is complete 1.69 + //get lock, to lock out any threads still starting up -- they'll see 1.70 + // that setupComplete is true before entering while loop, and so never 1.71 + // wait on the condition 1.72 + pthread_mutex_lock( _VMSMasterEnv->suspend_mutex ); 1.73 + _VMSMasterEnv->setupComplete = 1; 1.74 + pthread_mutex_unlock( _VMSMasterEnv->suspend_mutex ); 1.75 + pthread_cond_broadcast( _VMSMasterEnv->suspend_cond ); 1.76 + 1.77 + 1.78 //wait for all to complete 1.79 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 1.80 { 1.81 - WaitForSingleObject(coreLoopThdHandles[coreIdx], INFINITE); 1.82 + pthread_join( coreLoopThdHandles[coreIdx], NULL ); 1.83 } 1.84 - 1.85 + 1.86 //NOTE: do not clean up VMS env here -- semantic layer has to have 1.87 // a chance to clean up its environment first, then do a call to free 1.88 // the Master env and rest of VMS locations 1.89 1.90 - QueryPerformanceCounter( &endPerfCount ); 1.91 - count = endPerfCount.QuadPart - stPerfCount.QuadPart; 1.92 1.93 - QueryPerformanceFrequency( &countFreq ); 1.94 - freq = countFreq.QuadPart; 1.95 - runTime = (double)count / (double)freq; 1.96 + endCount = getTSCount(); 1.97 + count = endCount - startCount; 1.98 1.99 - printf("\n Time startup to shutdown: %f\n", runTime); 1.100 - fflush( stdin ); 1.101 + runTime = (double)count / (double)TSCOUNT_FREQ; 1.102 + 1.103 + printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin ); 1.104 } 1.105 1.106
