diff --git a/src/engine/execcmd.h b/src/engine/execcmd.h index e3e4019e7..9698ce290 100644 --- a/src/engine/execcmd.h +++ b/src/engine/execcmd.h @@ -52,7 +52,7 @@ void exec_cmd char const * target ); -int exec_wait(); +void exec_wait(); /****************************************************************************** diff --git a/src/engine/execnt.c b/src/engine/execnt.c index 8f6dc5b1d..5d21033fb 100644 --- a/src/engine/execnt.c +++ b/src/engine/execnt.c @@ -113,7 +113,6 @@ static void reportWindowsError( char const * const apiName ); #define MAX_RAW_COMMAND_LENGTH 32766 static int intr_installed; -static int cmdsrunning; /* The list of commands we run. */ @@ -304,20 +303,11 @@ void exec_cmd exit( EXITBAD ); } - ++cmdsrunning; - /* Invoke the actual external process using the constructed command line. */ invoke_cmd( cmd_local->value, slot ); /* Free our local command string copy. */ string_free( cmd_local ); - - /* Wait until we are under the limit of concurrent commands. Do not trust - * globs.jobs alone. - */ - while ( ( cmdsrunning >= MAXJOBS ) || ( cmdsrunning >= globs.jobs ) ) - if ( !exec_wait() ) - break; } @@ -326,19 +316,12 @@ void exec_cmd * * wait and drive at most one execution completion. * * waits for one command to complete, while processing the i/o for all * ongoing commands. - * - * Returns 0 if called when there were no more commands being executed or 1 - * otherwise. */ -int exec_wait() +void exec_wait() { int i = -1; - /* Handle naive make1() which does not know if cmds are running. */ - if ( !cmdsrunning ) - return 0; - /* Wait for a command to complete, while snarfing up any output. */ do { @@ -354,7 +337,6 @@ int exec_wait() while ( i < 0 ); /* We have a command... process it. */ - --cmdsrunning; { timing_info time; int rstat; @@ -409,8 +391,6 @@ int exec_wait() cmdtab[ i ].exit_code = 0; cmdtab[ i ].exit_reason = EXIT_OK; } - - return 1; } diff --git a/src/engine/execunix.c b/src/engine/execunix.c index 647b394b5..84a10fe38 100644 --- a/src/engine/execunix.c +++ b/src/engine/execunix.c @@ -64,7 +64,6 @@ static int get_free_cmdtab_slot(); static clock_t tps; static int select_timeout; -static int cmdsrunning; static int old_time_initialized; static struct tms old_time; @@ -149,9 +148,6 @@ void exec_cmd printf( " argv[%d] = '%s'\n", i, argv[ i ] ); } - /* Increment jobs running. */ - ++cmdsrunning; - /* Save off actual command string. */ cmdtab[ slot ].command = BJAM_MALLOC_ATOMIC( command->size + 1 ); strcpy( cmdtab[ slot ].command, command->value ); @@ -301,13 +297,6 @@ void exec_cmd cmdtab[ slot ].action_length = 0; cmdtab[ slot ].target_length = 0; } - - /* Wait until we are under the limit of concurrent commands. Do not trust - * globs.jobs alone. - */ - while ( ( cmdsrunning >= MAXJOBS ) || ( cmdsrunning >= globs.jobs ) ) - if ( !exec_wait() ) - break; } #undef EXECCMD_PIPE_READ @@ -432,18 +421,14 @@ void populate_file_descriptors( int * const fmax, fd_set * const fds ) * at least one has been registered. */ -int exec_wait() +void exec_wait() { int fd_max; int finished = 0; fd_set fds; - /* Handle naive make1() which does not know if commands are running. */ - if ( !cmdsrunning ) - return 0; - /* Process children that signaled. */ - while ( !finished && cmdsrunning ) + while ( !finished ) { int i; int ret; @@ -525,8 +510,6 @@ int exec_wait() old_time = new_time; /* Drive the completion. */ - --cmdsrunning; - if ( interrupted() ) rstat = EXEC_CMD_INTR; else if ( status ) @@ -558,8 +541,6 @@ int exec_wait() } } } - - return 1; } diff --git a/src/engine/make1.c b/src/engine/make1.c index 36d06f916..f7e4fe59f 100644 --- a/src/engine/make1.c +++ b/src/engine/make1.c @@ -111,6 +111,9 @@ static stack state_stack = { NULL }; static state * state_freelist = NULL; +/* Currently running command counter. */ +static int cmdsrunning; + static state * alloc_state() { @@ -204,7 +207,7 @@ int make1( TARGET * t ) /* Recursively make the target and its dependencies. */ push_state( &state_stack, t, NULL, T_STATE_MAKE1A ); - do + while ( 1 ) { while ( ( pState = current_state( &state_stack ) ) ) { @@ -222,9 +225,11 @@ int make1( TARGET * t ) assert( !"make1(): Invalid state detected." ); } } + if ( !cmdsrunning ) + break; + /* Wait for outstanding commands to finish running. */ + exec_wait(); } - /* Wait for any outstanding commands to finish running. */ - while ( exec_wait() ); clear_state_freelist(); @@ -538,10 +543,21 @@ static void make1c( state * pState ) } else { - /* Pop state first because exec_cmd() could push state. */ + /* Pop state first because exec_wait() will push state. */ pop_state( &state_stack ); + + /* Execute the actual build command. */ exec_cmd( cmd->buf, make_closure, pState->t, cmd->shell, rule_name, target_name ); + + /* Increment the jobs running counter. */ + ++cmdsrunning; + + /* Wait until we are under the concurrent command count limit. */ + assert( 0 < globs.jobs ); + assert( globs.jobs <= MAXJOBS ); + while ( cmdsrunning >= globs.jobs ) + exec_wait(); } } else @@ -814,6 +830,8 @@ static void make_closure { TARGET * built = (TARGET *)closure; + --cmdsrunning; + call_timing_rule( built, time ); if ( DEBUG_EXECCMD ) printf( "%f sec system; %f sec user\n", time->system, time->user );