Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
int
sanei_thread_sendsig( SANE_Pid pid, int sig )
{
	DBG(2, "sanei_thread_sendsig() %d to thread (id=%ld)\n", sig,
	    sanei_thread_pid_to_long(pid));
#ifdef USE_PTHREAD
	return pthread_kill( (pthread_t)pid, sig );
#else
	return kill( pid, sig );
#endif
}
Ejemplo n.º 3
0
int
sanei_thread_kill( SANE_Pid pid )
{
	DBG(2, "sanei_thread_kill() will kill %ld\n",
	    sanei_thread_pid_to_long(pid));
#ifdef USE_PTHREAD
#if defined (__APPLE__) && defined (__MACH__)
	return pthread_kill((pthread_t)pid, SIGUSR2);
#else
	return pthread_cancel((pthread_t)pid);
#endif
#elif defined HAVE_OS2_H
	return DosKillThread(pid);
#else
	return kill( pid, SIGTERM );
#endif
}