diff 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
line diff
     1.1 --- a/PR.c	Sat Mar 02 09:54:19 2013 -0800
     1.2 +++ b/PR.c	Mon Mar 04 00:40:38 2013 -0800
     1.3 @@ -10,7 +10,6 @@
     1.4  #include <malloc.h>
     1.5  #include <inttypes.h>
     1.6  #include <sys/time.h>
     1.7 -#include <pthread.h>
     1.8  
     1.9  #include "PR.h"
    1.10  
    1.11 @@ -117,7 +116,8 @@
    1.12     process->langEnvs     = langEnvs;
    1.13     process->protoLangEnvsList = langEnvsList;
    1.14     process->numLangEnvs  = 0;
    1.15 -   
    1.16 +   process->hasWaitingToEnd = FALSE;
    1.17 +
    1.18        //A Process starts with one slave, the seed slave
    1.19     seedSlv = PR_int__create_slaveVP( seed_Fn, seedData, process );
    1.20     seedSlv->typeOfVP           = SeedSlv;
    1.21 @@ -212,14 +212,23 @@
    1.22   }
    1.23  
    1.24  
    1.25 +/*This should only be called from main.  It makes the OS thread that is animating
    1.26 + * main to suspend until the process completes shutdown.
    1.27 + */
    1.28  void
    1.29  PR__wait_for_process_to_end( PRProcess *process )
    1.30   { 
    1.31 +   process->hasWaitingToEnd = TRUE;
    1.32 +   
    1.33    #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE
    1.34        // call the one and only core ctlr (sequential version), in the main thread.
    1.35 -   coreCtlr_Seq( NULL );
    1.36 -   flushRegisters();  //Not sure why here, but leaving to be safe
    1.37 -
    1.38 +   if( process->executionIsComplete )
    1.39 +      return;
    1.40 +   else
    1.41 +    { coreCtlr_Seq( NULL );
    1.42 +      flushRegisters();  //Not sure why here, but leaving to be safe
    1.43 +      process->executionIsComplete = TRUE;
    1.44 +    }
    1.45    #else
    1.46        //First get the "ACK" lock, then do normal wait for signal, then release
    1.47        // ACK lock, to let end-process know it can free the process struct
    1.48 @@ -244,6 +253,11 @@
    1.49  void
    1.50  PR__wait_for_all_activity_to_end()
    1.51   { 
    1.52 +  #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE
    1.53 +      //In sequential mode, can't reach this call unless all activity has
    1.54 +      // already completed, so just return.
    1.55 +   return;
    1.56 +  #else
    1.57     pthread_mutex_lock( &(_PRTopEnv->activityDoneLock) );
    1.58     while( !(_PRTopEnv->allActivityIsDone) )
    1.59      {
    1.60 @@ -251,6 +265,7 @@
    1.61                           &(_PRTopEnv->activityDoneLock) );
    1.62      }
    1.63     pthread_mutex_unlock( &(_PRTopEnv->activityDoneLock) );
    1.64 +  #endif
    1.65   }
    1.66  
    1.67