libs/stream_message/src/startprocess.cxx
// ===========================================================================
// Returns the status from the awaited process.  Success is 0.
//
Returns the status from the awaited process.  Success is 0.
Returns the status from the awaited process . Success is 0 .
int MBDriver::wait_process(MBDriver::pid_t pid)
{
    int status = 0;
    if (pid == null_pid) {
	return 0;
    }
#ifdef _WIN32
    DWORD dstatus = 0;
    WaitForSingleObject(pid, INFINITE);
    GetExitCodeProcess(pid, &dstatus);
    status = dstatus;
#else 
#ifndef MULTITHREADED
    MBDriver::pid_t ready_pid = null_pid;
    while (ready_pid != pid) {
	ready_pid = ::wait(&status);
	if (status == EINTR) {  
	    ready_pid = null_pid;
	}
    }
#else 
    {
	Exclusion s(guard_awaited);
	if (awaited == NULL) {
	    awaited = new set<MBDriver::pid_t>;
	}
	if (awaited->find(pid) != awaited->end()) {
	    return 1;
	}
	awaited->insert(pid);
    }
    {
	Exclusion s(guard_process);
	while (ready_pid != pid) {
	    if (ready_pid == null_pid) {
		MBDriver::pid_t done_pid = ::wait(&status);
		if (status == EINTR) {  
		    done_pid = null_pid;
		}
		{
		    Exclusion s(guard_awaited);
		    if (awaited->find(done_pid) != awaited->end()) {
			ready_pid = done_pid;
			ready_status = status;
		    }
		}
		if (ready_pid != pid && ready_pid != null_pid) {
		    guard_process.notify();
		}
	    }
	    else {
		guard_process.wait();
	    }
	}
	status = ready_status;
	ready_pid = null_pid;
	guard_process.notify();
    }
    {
	Exclusion s(guard_awaited);
	awaited->erase(pid);
    }
#endif 
#endif 
    return status;
}
int MBDriver :: wait_process ( MBDriver :: pid_t pid ) { int status = 0 ; if ( pid == null_pid ) { return 0 ; } #ifdef _WIN32 DWORD dstatus = 0 ; WaitForSingleObject ( pid , INFINITE ) ; GetExitCodeProcess ( pid , & dstatus ) ; status = dstatus ; #else #ifndef MULTITHREADED MBDriver :: pid_t ready_pid = null_pid ; while ( ready_pid != pid ) { ready_pid = :: wait ( & status ) ; if ( status == EINTR ) { ready_pid = null_pid ; } } #else { Exclusion s ( guard_awaited ) ; if ( awaited == NULL ) { awaited = new set < MBDriver :: pid_t > ; } if ( awaited -> find ( pid ) != awaited -> end ( ) ) { return 1 ; } awaited -> insert ( pid ) ; } { Exclusion s ( guard_process ) ; while ( ready_pid != pid ) { if ( ready_pid == null_pid ) { MBDriver :: pid_t done_pid = :: wait ( & status ) ; if ( status == EINTR ) { done_pid = null_pid ; } { Exclusion s ( guard_awaited ) ; if ( awaited -> find ( done_pid ) != awaited -> end ( ) ) { ready_pid = done_pid ; ready_status = status ; } } if ( ready_pid != pid && ready_pid != null_pid ) { guard_process . notify ( ) ; } } else { guard_process . wait ( ) ; } } status = ready_status ; ready_pid = null_pid ; guard_process . notify ( ) ; } { Exclusion s ( guard_awaited ) ; awaited -> erase ( pid ) ; } #endif #endif return status ; }
Returns the status from the awaited process.
Returns the status from the awaited process .
// Unix, not NT // just an interrupt; no process done // MULTITHREADED // !!! This is not tested. !!! // Since Unix 'wait' returns when _any_ child process terminates, // it is necessary to coordinate all waiters.  It is an error if // more than one thread waits on the same child process. // Only one thread will call ::wait.  The others wait on the monitor. // internal error: 2 threads await 1 child. // just an interrupt; no process done // a process we were waiting for // MULTITHREADED // Unix, not NT