SANE_Pid sanei_thread_waitpid( SANE_Pid pid, int *status ) { #ifdef USE_PTHREAD int *ls; #else int ls; #endif SANE_Pid result; int stat; stat = 0; DBG(2, "sanei_thread_waitpid() - %ld\n", sanei_thread_pid_to_long(pid)); #ifdef USE_PTHREAD int rc; rc = pthread_join( (pthread_t)pid, (void*)&ls ); if( 0 == rc ) { if( PTHREAD_CANCELED == ls ) { DBG(2, "* thread has been canceled!\n" ); stat = SANE_STATUS_GOOD; } else { stat = *ls; } DBG(2, "* result = %d (%p)\n", stat, (void*)status ); result = pid; } if ( EDEADLK == rc ) { if ( (pthread_t)pid != pthread_self() ) { /* call detach in any case to make sure that the thread resources * will be freed, when the thread has terminated */ DBG(2, "* detaching thread(%ld)\n", pid ); pthread_detach((pthread_t)pid); } } if (status) *status = stat; restore_sigpipe(); #else result = waitpid( pid, &ls, 0 ); if((result < 0) && (errno == ECHILD)) { stat = SANE_STATUS_GOOD; result = pid; } else { stat = eval_wp_result( pid, result, ls ); DBG(2, "* result = %d (%p)\n", stat, (void*)status ); } if( status ) *status = stat; #endif return result; }
SANE_Status sanei_thread_get_status( SANE_Pid pid ) { #if defined USE_PTHREAD || defined HAVE_OS2_H || defined __BEOS__ _VAR_NOT_USED( pid ); return td.status; #else int ls, stat, result; stat = SANE_STATUS_IO_ERROR; if( pid > 0 ) { result = waitpid( pid, &ls, WNOHANG ); stat = eval_wp_result( pid, result, ls ); } return stat; #endif }