summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/procsignal.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2013-08-28 14:08:13 -0400
committerRobert Haas <rhaas@postgresql.org>2013-08-28 14:08:13 -0400
commit090d0f2050647958865cb495dff74af7257d2bb4 (patch)
treebcebc38e72a0c90d8cf3c94d00b026e48887075e /src/backend/storage/ipc/procsignal.c
parentc9e2e2db5c2090a880028fd8c1debff474640f50 (diff)
Allow discovery of whether a dynamic background worker is running.
Using the infrastructure provided by this patch, it's possible either to wait for the startup of a dynamically-registered background worker, or to poll the status of such a worker without waiting. In either case, the current PID of the worker process can also be obtained. As usual, worker_spi is updated to demonstrate the new functionality. Patch by me. Review by Andres Freund.
Diffstat (limited to 'src/backend/storage/ipc/procsignal.c')
-rw-r--r--src/backend/storage/ipc/procsignal.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index a6f77c105c2..c4b5d0196b3 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -21,6 +21,7 @@
#include "miscadmin.h"
#include "storage/latch.h"
#include "storage/ipc.h"
+#include "storage/proc.h"
#include "storage/shmem.h"
#include "storage/sinval.h"
#include "tcop/tcopprot.h"
@@ -57,6 +58,14 @@ typedef struct
*/
#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
+/*
+ * If this flag is set, the process latch will be set whenever SIGUSR1
+ * is received. This is useful when waiting for a signal from the postmaster.
+ * Spurious wakeups must be expected. Make sure that the flag is cleared
+ * in the error path.
+ */
+bool set_latch_on_sigusr1;
+
static ProcSignalSlot *ProcSignalSlots = NULL;
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
@@ -276,6 +285,9 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
+ if (set_latch_on_sigusr1)
+ SetLatch(&MyProc->procLatch);
+
latch_sigusr1_handler();
errno = save_errno;