MyBgworkerEntry->bgw_type)));
}
-/*
- * Standard SIGUSR1 handler for unconnected workers
- *
- * Here, we want to make sure an unconnected worker will at least heed
- * latch activity.
- */
-static void
-bgworker_sigusr1_handler(SIGNAL_ARGS)
-{
- int save_errno = errno;
-
- latch_sigusr1_handler();
-
- errno = save_errno;
-}
-
/*
* Start a new background worker
*
*/
if ((worker->bgw_flags & BGWORKER_SHMEM_ACCESS) == 0)
{
+ ShutdownLatchSupport();
dsm_detach_all();
PGSharedMemoryDetach();
}
else
{
pqsignal(SIGINT, SIG_IGN);
- pqsignal(SIGUSR1, bgworker_sigusr1_handler);
+ pqsignal(SIGUSR1, SIG_IGN);
pqsignal(SIGFPE, SIG_IGN);
}
pqsignal(SIGTERM, bgworker_die);
*
* When SetLatch is called from the same process that owns the latch,
* SetLatch writes the byte directly to the pipe. If it's owned by another
- * process, SIGUSR1 is sent and the signal handler in the waiting process
+ * process, SIGURG is sent and the signal handler in the waiting process
* writes the byte to the pipe on behalf of the signaling process.
*
* The Windows implementation uses Windows events that are inherited by all
static int selfpipe_owner_pid = 0;
/* Private function prototypes */
+static void latch_sigurg_handler(SIGNAL_ARGS);
static void sendSelfPipeByte(void);
static void drainSelfPipe(void);
#endif /* WIN32 */
/* Tell fd.c about these two long-lived FDs */
ReserveExternalFD();
ReserveExternalFD();
+
+ pqsignal(SIGURG, latch_sigurg_handler);
#else
/* currently, nothing to do here for Windows */
#endif
Assert(latch_pos == LatchWaitSetLatchPos);
}
+void
+ShutdownLatchSupport(void)
+{
+ pqsignal(SIGURG, SIG_IGN);
+
+ if (LatchWaitSet)
+ {
+ FreeWaitEventSet(LatchWaitSet);
+ LatchWaitSet = NULL;
+ }
+
+ close(selfpipe_readfd);
+ close(selfpipe_writefd);
+ selfpipe_readfd = -1;
+ selfpipe_writefd = -1;
+ selfpipe_owner_pid = InvalidPid;
+}
+
/*
* Initialize a process-local latch.
*/
* any sort of locking here, meaning that we could fail to detect the error
* if two processes try to own the same latch at about the same time. If
* there is any risk of that, caller must provide an interlock to prevent it.
- *
- * In any process that calls OwnLatch(), make sure that
- * latch_sigusr1_handler() is called from the SIGUSR1 signal handler,
- * as shared latches use SIGUSR1 for inter-process communication.
*/
void
OwnLatch(Latch *latch)
sendSelfPipeByte();
}
else
- kill(owner_pid, SIGUSR1);
+ kill(owner_pid, SIGURG);
#else
/*
* the pipe-buffer fill up we're still ok, because the pipe is in
* nonblocking mode. It's unlikely for that to happen, because the
* self pipe isn't filled unless we're blocking (waiting = true), or
- * from inside a signal handler in latch_sigusr1_handler().
+ * from inside a signal handler in latch_sigurg_handler().
*
* On windows, we'll also notice if there's a pending event for the
* latch when blocking, but there's no danger of anything filling up,
}
#endif
+#ifndef WIN32
/*
- * SetLatch uses SIGUSR1 to wake up the process waiting on the latch.
- *
- * Wake up WaitLatch, if we're waiting. (We might not be, since SIGUSR1 is
- * overloaded for multiple purposes; or we might not have reached WaitLatch
- * yet, in which case we don't need to fill the pipe either.)
+ * SetLatch uses SIGURG to wake up the process waiting on the latch.
*
- * NB: when calling this in a signal handler, be sure to save and restore
- * errno around it.
+ * Wake up WaitLatch, if we're waiting.
*/
-#ifndef WIN32
-void
-latch_sigusr1_handler(void)
+static void
+latch_sigurg_handler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
if (waiting)
sendSelfPipeByte();
+
+ errno = save_errno;
}
#endif /* !WIN32 */
extern void DisownLatch(Latch *latch);
extern void SetLatch(Latch *latch);
extern void ResetLatch(Latch *latch);
+extern void ShutdownLatchSupport(void);
extern WaitEventSet *CreateWaitEventSet(MemoryContext context, int nevents);
extern void FreeWaitEventSet(WaitEventSet *set);
pgsocket sock, long timeout, uint32 wait_event_info);
extern void InitializeLatchWaitSet(void);
-/*
- * Unix implementation uses SIGUSR1 for inter-process signaling.
- * Win32 doesn't need this.
- */
-#ifndef WIN32
-extern void latch_sigusr1_handler(void);
-#else
-#define latch_sigusr1_handler() ((void) 0)
-#endif
-
#endif /* LATCH_H */