summaryrefslogtreecommitdiff
path: root/rts/posix/Signals.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/posix/Signals.c')
-rw-r--r--rts/posix/Signals.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c
index d5129f0996..ba4a8b75ea 100644
--- a/rts/posix/Signals.c
+++ b/rts/posix/Signals.c
@@ -127,28 +127,27 @@ more_handlers(int sig)
// Here's the pipe into which we will send our signals
static int io_manager_wakeup_fd = -1;
-static int io_manager_control_fd = -1;
+static int timer_manager_control_wr_fd = -1;
#define IO_MANAGER_WAKEUP 0xff
#define IO_MANAGER_DIE 0xfe
#define IO_MANAGER_SYNC 0xfd
-void
-setIOManagerWakeupFd (int fd)
-{
- // only called when THREADED_RTS, but unconditionally
- // compiled here because GHC.Event.Control depends on it.
- io_manager_wakeup_fd = fd;
+void setTimerManagerControlFd(int fd) {
+ timer_manager_control_wr_fd = fd;
}
void
-setIOManagerControlFd (int fd)
+setIOManagerWakeupFd (int fd)
{
// only called when THREADED_RTS, but unconditionally
// compiled here because GHC.Event.Control depends on it.
- io_manager_control_fd = fd;
+ io_manager_wakeup_fd = fd;
}
+/* -----------------------------------------------------------------------------
+ * Wake up at least one IO or timer manager HS thread.
+ * -------------------------------------------------------------------------- */
void
ioManagerWakeup (void)
{
@@ -170,14 +169,24 @@ ioManagerWakeup (void)
void
ioManagerDie (void)
{
+ StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
+ nat i;
+ int fd;
int r;
- // Ask the IO Manager thread to exit
- if (io_manager_control_fd >= 0) {
- StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
- r = write(io_manager_control_fd, &byte, 1);
+
+ if (0 <= timer_manager_control_wr_fd) {
+ r = write(timer_manager_control_wr_fd, &byte, 1);
if (r == -1) { sysErrorBelch("ioManagerDie: write"); }
- io_manager_control_fd = -1;
- io_manager_wakeup_fd = -1;
+ timer_manager_control_wr_fd = -1;
+ }
+
+ for (i=0; i < n_capabilities; i++) {
+ fd = capabilities[i]->io_manager_control_wr_fd;
+ if (0 <= fd) {
+ r = write(fd, &byte, 1);
+ if (r == -1) { sysErrorBelch("ioManagerDie: write"); }
+ capabilities[i]->io_manager_control_wr_fd = -1;
+ }
}
}
@@ -192,7 +201,7 @@ ioManagerStart (void)
{
// Make sure the IO manager thread is running
Capability *cap;
- if (io_manager_control_fd < 0 || io_manager_wakeup_fd < 0) {
+ if (timer_manager_control_wr_fd < 0 || io_manager_wakeup_fd < 0) {
cap = rts_lock();
ioManagerStartCap(&cap);
rts_unlock(cap);
@@ -223,26 +232,37 @@ generic_handler(int sig USED_IF_THREADS,
{
#if defined(THREADED_RTS)
- if (io_manager_control_fd != -1)
- {
- StgWord8 buf[sizeof(siginfo_t) + 1];
- int r;
+ StgWord8 buf[sizeof(siginfo_t) + 1];
+ int r;
- buf[0] = sig;
+ buf[0] = sig;
+ if (info == NULL) {
+ // info may be NULL on Solaris (see #3790)
+ memset(buf+1, 0, sizeof(siginfo_t));
+ } else {
+ memcpy(buf+1, info, sizeof(siginfo_t));
+ }
- if (info == NULL) {
- // info may be NULL on Solaris (see #3790)
- memset(buf+1, 0, sizeof(siginfo_t));
- } else {
- memcpy(buf+1, info, sizeof(siginfo_t));
+ if (0 <= timer_manager_control_wr_fd)
+ {
+ r = write(timer_manager_control_wr_fd, buf, sizeof(siginfo_t)+1);
+ if (r == -1 && errno == EAGAIN) {
+ errorBelch("lost signal due to full pipe: %d\n", sig);
}
+ }
- r = write(io_manager_control_fd, buf, sizeof(siginfo_t)+1);
- if (r == -1 && errno == EAGAIN)
- {
- errorBelch("lost signal due to full pipe: %d\n", sig);
+ nat i;
+ int fd;
+ for (i=0; i < n_capabilities; i++) {
+ fd = capabilities[i]->io_manager_control_wr_fd;
+ if (0 <= fd) {
+ r = write(fd, buf, sizeof(siginfo_t)+1);
+ if (r == -1 && errno == EAGAIN) {
+ errorBelch("lost signal due to full pipe: %d\n", sig);
+ }
}
}
+
// If the IO manager hasn't told us what the FD of the write end
// of its pipe is, there's not much we can do here, so just ignore
// the signal..