improve thread signal support, still far from good
This commit is contained in:
		
							
								
								
									
										10
									
								
								C/pl-yap.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								C/pl-yap.c
									
									
									
									
									
								
							@@ -1297,6 +1297,16 @@ sysError(const char *fm, ...)
 | 
			
		||||
  PL_fail;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
raiseSignal(PL_local_data_t *ld, int sig)
 | 
			
		||||
{ if (sig == SIG_THREAD_SIGNAL) {
 | 
			
		||||
     Yap_signal(YAP_ITI_SIGNAL);
 | 
			
		||||
     return TRUE;    
 | 
			
		||||
  }
 | 
			
		||||
  fprintf(stderr, "Unsupported signal %d\n", sig);
 | 
			
		||||
  return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if THREADS
 | 
			
		||||
 
 | 
			
		||||
@@ -888,6 +888,7 @@ extern atom_t	lookupUCSAtom(const pl_wchar_t *s, size_t len);
 | 
			
		||||
extern int toIntegerNumber(Number n, int flags);
 | 
			
		||||
extern int get_atom_ptr_text(Atom a, PL_chars_t *text);
 | 
			
		||||
extern int warning(const char *fm, ...);
 | 
			
		||||
extern int raiseSignal(PL_local_data_t *ld, int sig);
 | 
			
		||||
 | 
			
		||||
/**** stuff from pl-files.c ****/
 | 
			
		||||
void initFiles(void);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								configure
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								configure
									
									
									
									
										vendored
									
									
								
							@@ -9675,6 +9675,7 @@ $as_echo_n "checking for $ac_word... " >&6; }
 | 
			
		||||
if ${ac_cv_prog_JAVAC+:} false; then :
 | 
			
		||||
  $as_echo_n "(cached) " >&6
 | 
			
		||||
else
 | 
			
		||||
echo $JAVAC
 | 
			
		||||
  if test -n "$JAVAC"; then
 | 
			
		||||
  ac_cv_prog_JAVAC="$JAVAC" # Let the user override the test.
 | 
			
		||||
else
 | 
			
		||||
@@ -9682,6 +9683,7 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 | 
			
		||||
for as_dir in $PATH
 | 
			
		||||
do
 | 
			
		||||
  IFS=$as_save_IFS
 | 
			
		||||
echo $as_dir/$ac_word$ac_exec_ext
 | 
			
		||||
  test -z "$as_dir" && as_dir=.
 | 
			
		||||
    for ac_exec_ext in '' $ac_executable_extensions; do
 | 
			
		||||
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@ extern "C" {
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if USE_GMP
 | 
			
		||||
#include <gmp.h>
 | 
			
		||||
#endif
 | 
			
		||||
@@ -57,6 +58,12 @@ extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef __WINDOWS__
 | 
			
		||||
#if defined(_MSC_VER) || defined(__MINGW32__)
 | 
			
		||||
#define __WINDOWS__ 1
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		 /*******************************
 | 
			
		||||
		 *	       EXPORT		*
 | 
			
		||||
@@ -577,6 +584,7 @@ extern X_API int  PL_unify_thread_id(term_t, int);
 | 
			
		||||
extern X_API int PL_thread_attach_engine(const PL_thread_attr_t *);
 | 
			
		||||
extern X_API int PL_thread_destroy_engine(void);
 | 
			
		||||
extern X_API int PL_thread_at_exit(void (*)(void *), void *, int);
 | 
			
		||||
extern X_API int PL_thread_raise(int tid, int sig);
 | 
			
		||||
extern X_API PL_engine_t PL_create_engine(const PL_thread_attr_t *);
 | 
			
		||||
extern X_API int PL_destroy_engine(PL_engine_t);
 | 
			
		||||
extern X_API int PL_set_engine(PL_engine_t,PL_engine_t *);
 | 
			
		||||
 
 | 
			
		||||
@@ -2479,6 +2479,41 @@ X_API int PL_thread_self(void)
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
alertThread(int tid)
 | 
			
		||||
{
 | 
			
		||||
  return pthread_kill(REMOTE_ThreadHandle(tid).pthread_handle, YAP_ALARM_SIGNAL) == 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
			
		||||
PL_thread_raise() is used  for  re-routing   interrupts  in  the Windows
 | 
			
		||||
version, where the signal handler is running  from a different thread as
 | 
			
		||||
Prolog.
 | 
			
		||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
PL_thread_raise(int tid, int sig)
 | 
			
		||||
{ 
 | 
			
		||||
  PL_LOCK(L_THREAD);
 | 
			
		||||
  if ( tid < 1  )
 | 
			
		||||
    { error:
 | 
			
		||||
      PL_UNLOCK(L_THREAD);
 | 
			
		||||
      return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
  if ( !REMOTE_ThreadHandle(tid).in_use )
 | 
			
		||||
    goto error;
 | 
			
		||||
 | 
			
		||||
  if ( !raiseSignal(tid, sig) ||
 | 
			
		||||
       !alertThread(tid) )
 | 
			
		||||
    goto error;
 | 
			
		||||
 | 
			
		||||
  PL_UNLOCK(L_THREAD);
 | 
			
		||||
 | 
			
		||||
  return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
X_API int PL_unify_thread_id(term_t t, int i)
 | 
			
		||||
{
 | 
			
		||||
  CACHE_REGS
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,6 @@ extern int recursiveMutexInit(recursiveMutex *m);
 | 
			
		||||
#define recursiveMutexTryLock(p) pthread_mutex_trylock(p)
 | 
			
		||||
#define recursiveMutexUnlock(p)  pthread_mutex_unlock(p)
 | 
			
		||||
 | 
			
		||||
#define IF_MT(id, g) if ( id == L_THREAD || GD->thread.enabled ) g
 | 
			
		||||
 | 
			
		||||
typedef struct counting_mutex
 | 
			
		||||
{ simpleMutex mutex;                    /* mutex itself */
 | 
			
		||||
@@ -82,7 +81,7 @@ We  assume  id  ==  L_THREAD  is  optimized  away  if  id  is  known  at
 | 
			
		||||
compile-time
 | 
			
		||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 | 
			
		||||
 | 
			
		||||
#define IF_MT(id, g) if ( id == L_THREAD || GD->thread.enabled ) g
 | 
			
		||||
#define IF_MT(id, g) if ( id == L_THREAD  ) g
 | 
			
		||||
 | 
			
		||||
#ifdef O_CONTENTION_STATISTICS
 | 
			
		||||
#define countingMutexLock(cm) \
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user