Allow the signal multiplexing facility to transfer one sig_atomic_t
authorAndres Freund <[email protected]>
Tue, 12 Jan 2010 02:21:18 +0000 (03:21 +0100)
committerAndres Freund <[email protected]>
Tue, 12 Jan 2010 02:21:18 +0000 (03:21 +0100)
worth of data. This is usefull e.g. for making operations idempotent
or more precise.

src/backend/commands/async.c
src/backend/storage/ipc/procsignal.c
src/backend/storage/ipc/sinvaladt.c
src/include/storage/procsignal.h

index 8fb68fff0ce5cdbdfb96093b4718440e949f8bf1..5dd54b309792153ed0c251791cb2b74466000215 100644 (file)
@@ -646,7 +646,7 @@ Send_Notify(Relation lRel)
             * probably not worth worrying about.
             */
            if (SendProcSignal(listenerPID, PROCSIG_NOTIFY_INTERRUPT,
-                              InvalidBackendId) < 0)
+                              InvalidBackendId, true) < 0)
            {
                /*
                 * Get rid of pg_listener entry if it refers to a PID that no
index 70644b46a3175f615fc944f5994159ab7529db1b..2892727ee17567363dd2f4134b415596771593ad 100644 (file)
@@ -60,7 +60,7 @@ typedef struct
 static ProcSignalSlot *ProcSignalSlots = NULL;
 static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
 
-static bool CheckProcSignal(ProcSignalReason reason);
+static sig_atomic_t CheckProcSignal(ProcSignalReason reason);
 static void CleanupProcSignalState(int status, Datum arg);
 
 /*
@@ -164,10 +164,13 @@ CleanupProcSignalState(int status, Datum arg)
  * On success (a signal was sent), zero is returned.
  * On error, -1 is returned, and errno is set (typically to ESRCH or EPERM).
  *
+ * The data value may contain any value except 0
+ *
  * Not to be confused with ProcSendSignal
  */
 int
-SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
+SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId,
+              sig_atomic_t data)
 {
    volatile ProcSignalSlot *slot;
 
@@ -186,7 +189,7 @@ SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
        if (slot->pss_pid == pid)
        {
            /* Atomically set the proper flag */
-           slot->pss_signalFlags[reason] = true;
+           slot->pss_signalFlags[reason] = data;
            /* Send signal */
            return kill(pid, SIGUSR1);
        }
@@ -210,7 +213,7 @@ SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
                /* the above note about race conditions applies here too */
 
                /* Atomically set the proper flag */
-               slot->pss_signalFlags[reason] = true;
+               slot->pss_signalFlags[reason] = data;
                /* Send signal */
                return kill(pid, SIGUSR1);
            }
@@ -226,7 +229,7 @@ SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
  * signaled, and clear the signal flag.  Should be called after receiving
  * SIGUSR1.
  */
-static bool
+static sig_atomic_t
 CheckProcSignal(ProcSignalReason reason)
 {
    volatile ProcSignalSlot *slot = MyProcSignalSlot;
@@ -236,12 +239,13 @@ CheckProcSignal(ProcSignalReason reason)
        /* Careful here --- don't clear flag if we haven't seen it set */
        if (slot->pss_signalFlags[reason])
        {
-           slot->pss_signalFlags[reason] = false;
-           return true;
+           sig_atomic_t retval = slot->pss_signalFlags[reason];
+           slot->pss_signalFlags[reason] = 0;
+           return retval;
        }
    }
 
-   return false;
+   return 0;
 }
 
 /*
index 4bb91444c10537d1ffdd73c39b8fb2bb5ddd24e7..414c32ad3ebf18ec551823f77c61dce64568f6b5 100644 (file)
@@ -668,7 +668,7 @@ SICleanupQueue(bool callerHasWriteLock, int minFree)
        LWLockRelease(SInvalReadLock);
        LWLockRelease(SInvalWriteLock);
        elog(DEBUG4, "sending sinval catchup signal to PID %d", (int) his_pid);
-       SendProcSignal(his_pid, PROCSIG_CATCHUP_INTERRUPT, his_backendId);
+       SendProcSignal(his_pid, PROCSIG_CATCHUP_INTERRUPT, his_backendId, true);
        if (callerHasWriteLock)
            LWLockAcquire(SInvalWriteLock, LW_EXCLUSIVE);
    }
index 5d60f974a3c0a1e046b32236bca0e884bd26155b..3b0d56df3e8a6d9441d87e8475628007c9fdbad3 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef PROCSIGNAL_H
 #define PROCSIGNAL_H
 
+#include <signal.h>
 #include "storage/backendid.h"
 
 
@@ -43,7 +44,7 @@ extern void ProcSignalShmemInit(void);
 
 extern void ProcSignalInit(int pss_idx);
 extern int  SendProcSignal(pid_t pid, ProcSignalReason reason,
-                          BackendId backendId);
+                          BackendId backendId, sig_atomic_t data);
 
 extern void procsignal_sigusr1_handler(SIGNAL_ARGS);