From 20d697a1c300663df2c1472e222e57c84c4385fc Mon Sep 17 00:00:00 2001 From: dons Date: Sat, 2 Oct 2004 07:32:29 +0000 Subject: [PATCH] [project @ 2004-10-02 07:32:25 by dons] When linking against libpthreads, raise(3) can behave strangely on some platforms (OpenBSD at least, maybe other BSDs, not Linux). So use pthread_kill() to generate signals when running the threaded rts, instead of raise(), when System.Posix.Signals.raiseSignal is called. raiseSignal will call genericRaise, in the rts, which knows which function to use. --- ghc/rts/Linker.c | 1 + ghc/rts/RtsUtils.c | 25 +++++++++++++++++++++++++ ghc/rts/RtsUtils.h | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/ghc/rts/Linker.c b/ghc/rts/Linker.c index 71f076b..d263363 100644 --- a/ghc/rts/Linker.c +++ b/ghc/rts/Linker.c @@ -414,6 +414,7 @@ typedef struct _RtsSymbolVal { SymX(gcdIntegerIntzh_fast) \ SymX(gcdIntzh_fast) \ SymX(genSymZh) \ + SymX(genericRaise) \ SymX(getProgArgv) \ SymX(getStablePtr) \ SymX(initLinker) \ diff --git a/ghc/rts/RtsUtils.c b/ghc/rts/RtsUtils.c index 89a8af1..f4d61b1 100644 --- a/ghc/rts/RtsUtils.c +++ b/ghc/rts/RtsUtils.c @@ -32,6 +32,15 @@ #include #include +#if defined(openbsd_TARGET_OS) +# ifdef HAVE_SIGNAL_H +# include +# endif +# ifdef HAVE_PTHREAD_H +# include +# endif +#endif + /* ----------------------------------------------------------------------------- Result-checking malloc wrappers. -------------------------------------------------------------------------- */ @@ -288,3 +297,19 @@ heapCheckFail( void ) } #endif +/* + * It seems that pthreads and signals interact oddly in OpenBSD + * pthreads (and possibly FreeBSD). When linking with -lpthreads, we + * have to use pthread_kill to send blockable signals. So use that + * when we have a threaded rts. So System.Posix.Signals will call + * genericRaise(), rather than raise(3). + */ +#if defined(openbsd_TARGET_OS) +int genericRaise(int sig) { +# if defined(THREADED_RTS) + return pthread_kill(pthread_self(), sig); +# else + return raise(sig); +# endif +} +#endif diff --git a/ghc/rts/RtsUtils.h b/ghc/rts/RtsUtils.h index 97769b9..3ee5971 100644 --- a/ghc/rts/RtsUtils.h +++ b/ghc/rts/RtsUtils.h @@ -50,4 +50,8 @@ extern void heapCheckFail( void ); extern void* __hscore_get_saved_termios(int fd); extern void __hscore_set_saved_termios(int fd, void* ts); +#if defined(openbsd_TARGET_OS) +extern int genericRaise(int sig); +#endif + #endif // RTSUTILS_H -- 1.7.10.4