Ne pas utiliser sigprocmask() dans mlraise() si nous sommes en threads POSIX

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2138 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1998-11-02 15:08:40 +00:00
parent b9be2d540c
commit edce8eb8e8
3 changed files with 31 additions and 6 deletions

View File

@ -33,13 +33,9 @@ typedef char caml_generated_constant[256];
extern caml_generated_constant Out_of_memory, Sys_error, Failure, extern caml_generated_constant Out_of_memory, Sys_error, Failure,
Invalid_argument, End_of_file, Division_by_zero, Not_found, Match_failure; Invalid_argument, End_of_file, Division_by_zero, Not_found, Match_failure;
/* Exception raising */ /* Resetting the signal mask when raising an exception from C */
extern void raise_caml_exception (value bucket) Noreturn; static void default_reset_sigmask(void)
char * caml_exception_pointer = NULL;
void mlraise(value v)
{ {
#ifdef POSIX_SIGNALS #ifdef POSIX_SIGNALS
sigset_t mask; sigset_t mask;
@ -50,6 +46,19 @@ void mlraise(value v)
sigsetmask(0); sigsetmask(0);
#endif #endif
#endif #endif
}
void (*caml_reset_sigmask)(void) = default_reset_sigmask;
/* Exception raising */
extern void raise_caml_exception (value bucket) Noreturn;
char * caml_exception_pointer = NULL;
void mlraise(value v)
{
(*caml_reset_sigmask)();
Unlock_exn(); Unlock_exn();
if (caml_exception_pointer == NULL) fatal_uncaught_exception(v); if (caml_exception_pointer == NULL) fatal_uncaught_exception(v);

View File

@ -59,4 +59,6 @@ void raise_not_found (void) Noreturn;
void fatal_uncaught_exception (value) Noreturn; void fatal_uncaught_exception (value) Noreturn;
void init_exceptions (void); void init_exceptions (void);
extern void (*caml_reset_sigmask)(void);
#endif /* _fail_ */ #endif /* _fail_ */

View File

@ -225,6 +225,17 @@ static void caml_io_mutex_unlock_exn(void)
if (chan != NULL) caml_io_mutex_unlock(chan); if (chan != NULL) caml_io_mutex_unlock(chan);
} }
/* Hook for resetting signals in mlraise() (in native-code only) */
#ifdef NATIVE_CODE
static void caml_thread_reset_sigmask(void)
{
sigset_t mask;
sigemptyset(&mask);
pthread_sigmask(SIG_SETMASK, &mask, NULL);
}
#endif
/* The "tick" thread fakes a SIGVTALRM signal at regular intervals. */ /* The "tick" thread fakes a SIGVTALRM signal at regular intervals. */
static void * caml_thread_tick(void * arg) static void * caml_thread_tick(void * arg)
@ -301,6 +312,9 @@ value caml_thread_initialize(value unit) /* ML */
channel_mutex_lock = caml_io_mutex_lock; channel_mutex_lock = caml_io_mutex_lock;
channel_mutex_unlock = caml_io_mutex_unlock; channel_mutex_unlock = caml_io_mutex_unlock;
channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; channel_mutex_unlock_exn = caml_io_mutex_unlock_exn;
#ifdef NATIVE_CODE
caml_reset_sigmask = caml_thread_reset_sigmask;
#endif
/* Fork the tick thread */ /* Fork the tick thread */
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);