Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 7:c6b65a94790f | 8:0aad63472e71 |
|---|---|
| 79 | 79 |
| 80 numProcrsCreated = 1; | 80 numProcrsCreated = 1; |
| 81 | 81 |
| 82 //======================================================================== | 82 //======================================================================== |
| 83 // Create the Threads | 83 // Create the Threads |
| 84 int coreIdx; | 84 int coreIdx, retCode; |
| 85 | 85 #define thdAttrs NULL |
| 86 | |
| 87 _VMSMasterEnv->setupComplete = 0; | |
| 88 _VMSMasterEnv->suspend_mutex = PTHREAD_MUTEX_INITIALIZER; | |
| 89 _VMSMasterEnv->suspend_cond = PTHREAD_COND_INITIALIZER; | |
| 90 | |
| 91 //Need the threads to be created suspended, and wait for a signal | |
| 92 // before proceeding -- gives time after creating to initialize other | |
| 93 // stuff before the coreLoops set off. | |
| 94 | |
| 86 //Make params given to the win threads that animate the core loops | 95 //Make params given to the win threads that animate the core loops |
| 87 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 96 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 88 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) ); | 97 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) ); |
| 89 coreLoopThdParams[coreIdx]->coreNum = coreIdx; | 98 coreLoopThdParams[coreIdx]->coreNum = coreIdx; |
| 90 | 99 |
| 91 //make the core loop threads, born in suspended state | 100 retCode = |
| 92 coreLoopThdHandles[ coreIdx ] = | 101 pthread_create( &(coreLoopThdHandles[coreIdx]), |
| 93 CreateThread ( NULL, // Security attributes | 102 thdAttrs, |
| 94 0, // Stack size | 103 &coreLoop, |
| 95 coreLoop, | 104 (void *)(coreLoopThdParams[coreIdx]) ); |
| 96 coreLoopThdParams[coreIdx], | 105 if(!retCode){printf("ERROR creating thread: %d\n", retCode); exit();} |
| 97 CREATE_SUSPENDED, | |
| 98 &(coreLoopThdIds[coreIdx]) | |
| 99 ); | |
| 100 } | 106 } |
| 101 | 107 |
| 102 } | 108 |
| 103 | 109 } |
| 104 | 110 |
| 105 void | 111 void |
| 106 create_sched_slots( MasterEnv *masterEnv ) | 112 create_sched_slots( MasterEnv *masterEnv ) |
| 107 { SchedSlot **schedSlots, **filledSlots; | 113 { SchedSlot **schedSlots, **filledSlots; |
| 108 int i; | 114 int i; |
| 130 void | 136 void |
| 131 VMS__start_the_work_then_wait_until_done() | 137 VMS__start_the_work_then_wait_until_done() |
| 132 { int coreIdx; | 138 { int coreIdx; |
| 133 //Start the core loops running | 139 //Start the core loops running |
| 134 //=========================================================================== | 140 //=========================================================================== |
| 135 LARGE_INTEGER stPerfCount, endPerfCount, countFreq; | 141 TSCount startCount, endCount; |
| 136 unsigned long long count = 0, freq = 0; | 142 unsigned long long count = 0, freq = 0; |
| 137 double runTime; | 143 double runTime; |
| 138 | 144 |
| 139 QueryPerformanceCounter( &stPerfCount ); | 145 startCount = getTSCount(); |
| 140 | 146 |
| 141 //start them running | 147 //tell the core loop threads that setup is complete |
| 142 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 148 //get lock, to lock out any threads still starting up -- they'll see |
| 143 { //Create the threads | 149 // that setupComplete is true before entering while loop, and so never |
| 144 ResumeThread( coreLoopThdHandles[coreIdx] ); //starts thread | 150 // wait on the condition |
| 145 } | 151 pthread_mutex_lock( _VMSMasterEnv->suspend_mutex ); |
| 146 | 152 _VMSMasterEnv->setupComplete = 1; |
| 153 pthread_mutex_unlock( _VMSMasterEnv->suspend_mutex ); | |
| 154 pthread_cond_broadcast( _VMSMasterEnv->suspend_cond ); | |
| 155 | |
| 156 | |
| 147 //wait for all to complete | 157 //wait for all to complete |
| 148 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 158 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 149 { | 159 { |
| 150 WaitForSingleObject(coreLoopThdHandles[coreIdx], INFINITE); | 160 pthread_join( coreLoopThdHandles[coreIdx], NULL ); |
| 151 } | 161 } |
| 152 | 162 |
| 153 //NOTE: do not clean up VMS env here -- semantic layer has to have | 163 //NOTE: do not clean up VMS env here -- semantic layer has to have |
| 154 // a chance to clean up its environment first, then do a call to free | 164 // a chance to clean up its environment first, then do a call to free |
| 155 // the Master env and rest of VMS locations | 165 // the Master env and rest of VMS locations |
| 156 | 166 |
| 157 QueryPerformanceCounter( &endPerfCount ); | 167 |
| 158 count = endPerfCount.QuadPart - stPerfCount.QuadPart; | 168 endCount = getTSCount(); |
| 159 | 169 count = endCount - startCount; |
| 160 QueryPerformanceFrequency( &countFreq ); | 170 |
| 161 freq = countFreq.QuadPart; | 171 runTime = (double)count / (double)TSCOUNT_FREQ; |
| 162 runTime = (double)count / (double)freq; | 172 |
| 163 | 173 printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin ); |
| 164 printf("\n Time startup to shutdown: %f\n", runTime); | |
| 165 fflush( stdin ); | |
| 166 } | 174 } |
| 167 | 175 |
| 168 | 176 |
| 169 | 177 |
| 170 /*Create stack, then create __cdecl structure on it and put initialData and | 178 /*Create stack, then create __cdecl structure on it and put initialData and |
