From 0bc246eb325dfd4f9738f6b6937a145b3092214c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Sun, 24 Jun 2012 10:42:19 +0000 Subject: [PATCH] Boost Jam code cleanup - extracted functions for finding a free running tables command slot in execnt.c & execunix.c modules. [SVN r79051] --- src/engine/execnt.c | 29 ++++++++++++++++++----------- src/engine/execunix.c | 33 +++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/engine/execnt.c b/src/engine/execnt.c index a9430f275..087f479e1 100644 --- a/src/engine/execnt.c +++ b/src/engine/execnt.c @@ -95,6 +95,8 @@ static void close_alert( HANDLE ); static void close_alerts(); /* returns a string's value buffer if not empty or 0 if empty */ static char const * null_if_empty( string const * str ); +/* find a free slot in the running commands table */ +static int get_free_cmdtab_slot(); /* Reports the last failed Windows API related error message. */ static void reportWindowsError( char const * const apiName ); @@ -197,20 +199,10 @@ void exec_cmd char const * target ) { - int slot; + int const slot = get_free_cmdtab_slot(); int raw_cmd = 0 ; string cmd_local[ 1 ]; - /* Find a free slot in the running commands table. */ - for ( slot = 0; slot < MAXJOBS; ++slot ) - if ( !cmdtab[ slot ].pi.hProcess ) - break; - if ( slot == MAXJOBS ) - { - printf( "no slots for child!\n" ); - exit( EXITBAD ); - } - /* Trim all leading and trailing leading whitespace. */ string_new_trimmed( cmd_local, cmd_orig ); @@ -1261,6 +1253,21 @@ static char const * null_if_empty( string const * str ) } +/* + * Find a free slot in the running commands table. + */ + +static int get_free_cmdtab_slot() +{ + int slot; + for ( slot = 0; slot < MAXJOBS; ++slot ) + if ( !cmdtab[ slot ].pi.hProcess ) + return slot; + printf( "no slots for child!\n" ); + exit( EXITBAD ); +} + + /* * Reports the last failed Windows API related error message. */ diff --git a/src/engine/execunix.c b/src/engine/execunix.c index 362b910e6..a7b4c453d 100644 --- a/src/engine/execunix.c +++ b/src/engine/execunix.c @@ -57,6 +57,11 @@ * exec_wait() - wait for any of the async command processes to terminate. */ +/* find a free slot in the running commands table */ +static int get_free_cmdtab_slot(); + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + static clock_t tps; static int select_timeout; static int intr; @@ -125,23 +130,12 @@ void exec_cmd char const * target ) { - int slot; + int const slot = get_free_cmdtab_slot(); int out[ 2 ]; int err[ 2 ]; int len; char const * argv[ MAXARGC + 1 ]; /* +1 for NULL */ - /* Find a slot in the running commands table for this one. */ - for ( slot = 0; slot < MAXJOBS; ++slot ) - if ( !cmdtab[ slot ].pid ) - break; - - if ( slot == MAXJOBS ) - { - printf( "no slots for child!\n" ); - exit( EXITBAD ); - } - /* Forumulate argv. If shell was defined, be prepared for % and ! subs. * Otherwise, use stock /bin/sh. */ @@ -592,6 +586,21 @@ int exec_wait() } +/* + * Find a free slot in the running commands table. + */ + +static int get_free_cmdtab_slot() +{ + int slot; + for ( slot = 0; slot < MAXJOBS; ++slot ) + if ( !cmdtab[ slot ].pid ) + return slot; + printf( "no slots for child!\n" ); + exit( EXITBAD ); +} + + void exec_done( void ) { int slot;