| 781 | */ |
| 782 | |
| 783 | static int try_wait( int const timeoutMillis ) |
| 784 | { |
| 785 | int i; |
| 786 | int num_active; |
| 787 | int wait_api_result; |
| 788 | HANDLE active_handles[ MAXJOBS ]; |
| 789 | int active_procs[ MAXJOBS ]; |
| 790 | |
| 791 | /* Prepare a list of all active processes to wait for. */ |
| 792 | for ( num_active = 0, i = 0; i < globs.jobs; ++i ) |
| 793 | if ( cmdtab[ i ].pi.hProcess ) |
| 794 | { |
| 795 | active_handles[ num_active ] = cmdtab[ i ].pi.hProcess; |
| 796 | active_procs[ num_active ] = i; |
| 797 | ++num_active; |
| 798 | } |
| 799 | |
| 800 | /* Wait for a child to complete, or for our timeout window to expire. */ |
| 801 | wait_api_result = WaitForMultipleObjects( num_active, active_handles, |
| 802 | FALSE, timeoutMillis ); |
| 803 | if ( ( WAIT_OBJECT_0 <= wait_api_result ) && |
| 804 | ( wait_api_result < WAIT_OBJECT_0 + num_active ) ) |
| 805 | { |
| 806 | /* Terminated process detected - return its index. */ |
| 807 | return active_procs[ wait_api_result - WAIT_OBJECT_0 ]; |
| 808 | } |
| 809 | |
| 810 | /* Timeout. */ |
| 811 | return -1; |
| 812 | } |
| 813 | |
| 814 | |
| 815 | static int try_kill_one() |