RTS tidyup sweep, first phase
[ghc-hetmet.git] / rts / posix / Signals.c
index 8268e6f..6600657 100644 (file)
@@ -6,18 +6,15 @@
  *
  * ---------------------------------------------------------------------------*/
 
-/* This is non-Posix-compliant.
-   #include "PosixSource.h" 
-*/
+#include "PosixSource.h" 
 #include "Rts.h"
-#include "SchedAPI.h"
+
 #include "Schedule.h"
 #include "RtsSignals.h"
-#include "posix/Signals.h"
+#include "Signals.h"
 #include "RtsUtils.h"
-#include "RtsFlags.h"
 #include "Prelude.h"
-#include "ThrIOManager.h"
+#include "Stable.h"
 
 #ifdef alpha_HOST_ARCH
 # if defined(linux_HOST_OS)
@@ -95,27 +92,33 @@ setIOManagerPipe (int fd)
 {
     // only called when THREADED_RTS, but unconditionally
     // compiled here because GHC.Conc depends on it.
-    io_manager_pipe = fd;
+    if (io_manager_pipe < 0) {
+        io_manager_pipe = fd;
+    }
 }
 
 #if defined(THREADED_RTS)
 void
 ioManagerWakeup (void)
 {
+    int r;
     // Wake up the IO Manager thread by sending a byte down its pipe
     if (io_manager_pipe >= 0) {
        StgWord8 byte = (StgWord8)IO_MANAGER_WAKEUP;
-       write(io_manager_pipe, &byte, 1);
+       r = write(io_manager_pipe, &byte, 1);
+        if (r == -1) { sysErrorBelch("ioManagerWakeup: write"); }
     }
 }
 
 void
 ioManagerDie (void)
 {
+    int r;
     // Ask the IO Manager thread to exit
     if (io_manager_pipe >= 0) {
        StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
-       write(io_manager_pipe, &byte, 1);
+       r = write(io_manager_pipe, &byte, 1);
+        if (r == -1) { sysErrorBelch("ioManagerDie: write"); }
         close(io_manager_pipe);
         io_manager_pipe = -1;
     }
@@ -214,7 +217,7 @@ generic_handler(int sig USED_IF_THREADS,
        stg_exit(EXIT_FAILURE);
     }
     
-    MainCapability.context_switch = 1;
+    contextSwitchCapability(&MainCapability);
 
 #endif /* THREADED_RTS */
 }