Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison PR.c @ 276:1d7ea1b0f176
Dev_ML Working in sequential mode
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Mon, 04 Mar 2013 00:40:38 -0800 |
| parents | 40e7625e57bd |
| children | 2fc69e6c14ea |
comparison
equal
deleted
inserted
replaced
| 0:ecce74f7a9eb | 1:22e43a3402bb |
|---|---|
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <malloc.h> | 10 #include <malloc.h> |
| 11 #include <inttypes.h> | 11 #include <inttypes.h> |
| 12 #include <sys/time.h> | 12 #include <sys/time.h> |
| 13 #include <pthread.h> | |
| 14 | 13 |
| 15 #include "PR.h" | 14 #include "PR.h" |
| 16 | 15 |
| 17 | 16 |
| 18 #define thdAttrs NULL | 17 #define thdAttrs NULL |
| 115 (PRLangEnv **)PR_int__make_collection_of_size( NUM_IN_COLLECTION ); | 114 (PRLangEnv **)PR_int__make_collection_of_size( NUM_IN_COLLECTION ); |
| 116 langEnvsList = PR_WL__malloc( NUM_IN_COLLECTION * sizeof(PRCollElem *) ); | 115 langEnvsList = PR_WL__malloc( NUM_IN_COLLECTION * sizeof(PRCollElem *) ); |
| 117 process->langEnvs = langEnvs; | 116 process->langEnvs = langEnvs; |
| 118 process->protoLangEnvsList = langEnvsList; | 117 process->protoLangEnvsList = langEnvsList; |
| 119 process->numLangEnvs = 0; | 118 process->numLangEnvs = 0; |
| 120 | 119 process->hasWaitingToEnd = FALSE; |
| 120 | |
| 121 //A Process starts with one slave, the seed slave | 121 //A Process starts with one slave, the seed slave |
| 122 seedSlv = PR_int__create_slaveVP( seed_Fn, seedData, process ); | 122 seedSlv = PR_int__create_slaveVP( seed_Fn, seedData, process ); |
| 123 seedSlv->typeOfVP = SeedSlv; | 123 seedSlv->typeOfVP = SeedSlv; |
| 124 seedSlv->processSlaveIsIn = process; | 124 seedSlv->processSlaveIsIn = process; |
| 125 process->numLiveGenericSlvs = 1; //count the seed | 125 process->numLiveGenericSlvs = 1; //count the seed |
| 210 // first lock? Can see some rare code that creates a bunch, before getting | 210 // first lock? Can see some rare code that creates a bunch, before getting |
| 211 // to waiting.. leave for now.. pain to fix.. | 211 // to waiting.. leave for now.. pain to fix.. |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 /*This should only be called from main. It makes the OS thread that is animating | |
| 216 * main to suspend until the process completes shutdown. | |
| 217 */ | |
| 215 void | 218 void |
| 216 PR__wait_for_process_to_end( PRProcess *process ) | 219 PR__wait_for_process_to_end( PRProcess *process ) |
| 217 { | 220 { |
| 221 process->hasWaitingToEnd = TRUE; | |
| 222 | |
| 218 #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE | 223 #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE |
| 219 // call the one and only core ctlr (sequential version), in the main thread. | 224 // call the one and only core ctlr (sequential version), in the main thread. |
| 220 coreCtlr_Seq( NULL ); | 225 if( process->executionIsComplete ) |
| 221 flushRegisters(); //Not sure why here, but leaving to be safe | 226 return; |
| 222 | 227 else |
| 228 { coreCtlr_Seq( NULL ); | |
| 229 flushRegisters(); //Not sure why here, but leaving to be safe | |
| 230 process->executionIsComplete = TRUE; | |
| 231 } | |
| 223 #else | 232 #else |
| 224 //First get the "ACK" lock, then do normal wait for signal, then release | 233 //First get the "ACK" lock, then do normal wait for signal, then release |
| 225 // ACK lock, to let end-process know it can free the process struct | 234 // ACK lock, to let end-process know it can free the process struct |
| 226 pthread_mutex_lock( &(process->doneAckLock) ); | 235 pthread_mutex_lock( &(process->doneAckLock) ); |
| 227 pthread_mutex_lock( &(process->doneLock) ); | 236 pthread_mutex_lock( &(process->doneLock) ); |
| 242 | 251 |
| 243 | 252 |
| 244 void | 253 void |
| 245 PR__wait_for_all_activity_to_end() | 254 PR__wait_for_all_activity_to_end() |
| 246 { | 255 { |
| 256 #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE | |
| 257 //In sequential mode, can't reach this call unless all activity has | |
| 258 // already completed, so just return. | |
| 259 return; | |
| 260 #else | |
| 247 pthread_mutex_lock( &(_PRTopEnv->activityDoneLock) ); | 261 pthread_mutex_lock( &(_PRTopEnv->activityDoneLock) ); |
| 248 while( !(_PRTopEnv->allActivityIsDone) ) | 262 while( !(_PRTopEnv->allActivityIsDone) ) |
| 249 { | 263 { |
| 250 pthread_cond_wait( &(_PRTopEnv->activityDoneCond), | 264 pthread_cond_wait( &(_PRTopEnv->activityDoneCond), |
| 251 &(_PRTopEnv->activityDoneLock) ); | 265 &(_PRTopEnv->activityDoneLock) ); |
| 252 } | 266 } |
| 253 pthread_mutex_unlock( &(_PRTopEnv->activityDoneLock) ); | 267 pthread_mutex_unlock( &(_PRTopEnv->activityDoneLock) ); |
| 268 #endif | |
| 254 } | 269 } |
| 255 | 270 |
| 256 | 271 |
| 257 /*This info is retrieved by PRServ's "give environ string" function | 272 /*This info is retrieved by PRServ's "give environ string" function |
| 258 *These Fn s are meant to be called from main, or possibly the seed slave. | 273 *These Fn s are meant to be called from main, or possibly the seed slave. |
