[project @ 2004-10-02 07:32:25 by dons]
authordons <unknown>
Sat, 2 Oct 2004 07:32:29 +0000 (07:32 +0000)
committerdons <unknown>
Sat, 2 Oct 2004 07:32:29 +0000 (07:32 +0000)
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
ghc/rts/RtsUtils.c
ghc/rts/RtsUtils.h

index 71f076b..d263363 100644 (file)
@@ -414,6 +414,7 @@ typedef struct _RtsSymbolVal {
       SymX(gcdIntegerIntzh_fast)               \
       SymX(gcdIntzh_fast)                      \
       SymX(genSymZh)                           \
+      SymX(genericRaise)                       \
       SymX(getProgArgv)                                \
       SymX(getStablePtr)                       \
       SymX(initLinker)                         \
index 89a8af1..f4d61b1 100644 (file)
 #include <stdarg.h>
 #include <stdio.h>
 
+#if defined(openbsd_TARGET_OS)
+# ifdef HAVE_SIGNAL_H
+#  include <signal.h>
+# endif
+# ifdef HAVE_PTHREAD_H
+#  include <pthread.h>
+# 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
index 97769b9..3ee5971 100644 (file)
@@ -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