PostgreSQL Source Code  git master
latch.h File Reference
#include <signal.h>
Include dependency graph for latch.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Latch
 
struct  WaitEvent
 

Macros

#define WL_LATCH_SET   (1 << 0)
 
#define WL_SOCKET_READABLE   (1 << 1)
 
#define WL_SOCKET_WRITEABLE   (1 << 2)
 
#define WL_TIMEOUT   (1 << 3) /* not for WaitEventSetWait() */
 
#define WL_POSTMASTER_DEATH   (1 << 4)
 
#define WL_EXIT_ON_PM_DEATH   (1 << 5)
 
#define WL_SOCKET_CONNECTED   WL_SOCKET_WRITEABLE
 
#define WL_SOCKET_CLOSED   (1 << 7)
 
#define WL_SOCKET_ACCEPT   WL_SOCKET_READABLE
 
#define WL_SOCKET_MASK
 

Typedefs

typedef struct Latch Latch
 
typedef struct WaitEvent WaitEvent
 
typedef struct WaitEventSet WaitEventSet
 

Functions

void InitializeLatchSupport (void)
 
void InitLatch (Latch *latch)
 
void InitSharedLatch (Latch *latch)
 
void OwnLatch (Latch *latch)
 
void DisownLatch (Latch *latch)
 
void SetLatch (Latch *latch)
 
void ResetLatch (Latch *latch)
 
void ShutdownLatchSupport (void)
 
WaitEventSetCreateWaitEventSet (MemoryContext context, int nevents)
 
void FreeWaitEventSet (WaitEventSet *set)
 
void FreeWaitEventSetAfterFork (WaitEventSet *set)
 
int AddWaitEventToSet (WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
 
void ModifyWaitEvent (WaitEventSet *set, int pos, uint32 events, Latch *latch)
 
int WaitEventSetWait (WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
 
int WaitLatch (Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
 
int WaitLatchOrSocket (Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info)
 
void InitializeLatchWaitSet (void)
 
int GetNumRegisteredWaitEvents (WaitEventSet *set)
 
bool WaitEventSetCanReportClosed (void)
 

Macro Definition Documentation

◆ WL_EXIT_ON_PM_DEATH

#define WL_EXIT_ON_PM_DEATH   (1 << 5)

Definition at line 130 of file latch.h.

◆ WL_LATCH_SET

#define WL_LATCH_SET   (1 << 0)

Definition at line 125 of file latch.h.

◆ WL_POSTMASTER_DEATH

#define WL_POSTMASTER_DEATH   (1 << 4)

Definition at line 129 of file latch.h.

◆ WL_SOCKET_ACCEPT

#define WL_SOCKET_ACCEPT   WL_SOCKET_READABLE

Definition at line 142 of file latch.h.

◆ WL_SOCKET_CLOSED

#define WL_SOCKET_CLOSED   (1 << 7)

Definition at line 137 of file latch.h.

◆ WL_SOCKET_CONNECTED

#define WL_SOCKET_CONNECTED   WL_SOCKET_WRITEABLE

Definition at line 135 of file latch.h.

◆ WL_SOCKET_MASK

#define WL_SOCKET_MASK
Value:
WL_SOCKET_WRITEABLE | \
WL_SOCKET_CONNECTED | \
WL_SOCKET_ACCEPT | \
WL_SOCKET_CLOSED)
#define WL_SOCKET_READABLE
Definition: latch.h:126

Definition at line 144 of file latch.h.

◆ WL_SOCKET_READABLE

#define WL_SOCKET_READABLE   (1 << 1)

Definition at line 126 of file latch.h.

◆ WL_SOCKET_WRITEABLE

#define WL_SOCKET_WRITEABLE   (1 << 2)

Definition at line 127 of file latch.h.

◆ WL_TIMEOUT

#define WL_TIMEOUT   (1 << 3) /* not for WaitEventSetWait() */

Definition at line 128 of file latch.h.

Typedef Documentation

◆ Latch

typedef struct Latch Latch

◆ WaitEvent

typedef struct WaitEvent WaitEvent

◆ WaitEventSet

typedef struct WaitEventSet WaitEventSet

Definition at line 1 of file latch.h.

Function Documentation

◆ AddWaitEventToSet()

int AddWaitEventToSet ( WaitEventSet set,
uint32  events,
pgsocket  fd,
Latch latch,
void *  user_data 
)

Definition at line 920 of file latch.c.

922 {
923  WaitEvent *event;
924 
925  /* not enough space */
926  Assert(set->nevents < set->nevents_space);
927 
928  if (events == WL_EXIT_ON_PM_DEATH)
929  {
930  events = WL_POSTMASTER_DEATH;
931  set->exit_on_postmaster_death = true;
932  }
933 
934  if (latch)
935  {
936  if (latch->owner_pid != MyProcPid)
937  elog(ERROR, "cannot wait on a latch owned by another process");
938  if (set->latch)
939  elog(ERROR, "cannot wait on more than one latch");
940  if ((events & WL_LATCH_SET) != WL_LATCH_SET)
941  elog(ERROR, "latch events only support being set");
942  }
943  else
944  {
945  if (events & WL_LATCH_SET)
946  elog(ERROR, "cannot wait on latch without a specified latch");
947  }
948 
949  /* waiting for socket readiness without a socket indicates a bug */
950  if (fd == PGINVALID_SOCKET && (events & WL_SOCKET_MASK))
951  elog(ERROR, "cannot wait on socket event without a socket");
952 
953  event = &set->events[set->nevents];
954  event->pos = set->nevents++;
955  event->fd = fd;
956  event->events = events;
957  event->user_data = user_data;
958 #ifdef WIN32
959  event->reset = false;
960 #endif
961 
962  if (events == WL_LATCH_SET)
963  {
964  set->latch = latch;
965  set->latch_pos = event->pos;
966 #if defined(WAIT_USE_SELF_PIPE)
967  event->fd = selfpipe_readfd;
968 #elif defined(WAIT_USE_SIGNALFD)
969  event->fd = signal_fd;
970 #else
971  event->fd = PGINVALID_SOCKET;
972 #ifdef WAIT_USE_EPOLL
973  return event->pos;
974 #endif
975 #endif
976  }
977  else if (events == WL_POSTMASTER_DEATH)
978  {
979 #ifndef WIN32
981 #endif
982  }
983 
984  /* perform wait primitive specific initialization, if needed */
985 #if defined(WAIT_USE_EPOLL)
986  WaitEventAdjustEpoll(set, event, EPOLL_CTL_ADD);
987 #elif defined(WAIT_USE_KQUEUE)
988  WaitEventAdjustKqueue(set, event, 0);
989 #elif defined(WAIT_USE_POLL)
990  WaitEventAdjustPoll(set, event);
991 #elif defined(WAIT_USE_WIN32)
992  WaitEventAdjustWin32(set, event);
993 #endif
994 
995  return event->pos;
996 }
#define ERROR
Definition: elog.h:39
int MyProcPid
Definition: globals.c:44
static int selfpipe_readfd
Definition: latch.c:170
static void WaitEventAdjustPoll(WaitEventSet *set, WaitEvent *event)
Definition: latch.c:1133
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:130
#define WL_LATCH_SET
Definition: latch.h:125
#define WL_POSTMASTER_DEATH
Definition: latch.h:129
#define WL_SOCKET_MASK
Definition: latch.h:144
Assert(fmt[strlen(fmt) - 1] !='\n')
#define PGINVALID_SOCKET
Definition: port.h:31
int postmaster_alive_fds[2]
Definition: postmaster.c:575
#define POSTMASTER_FD_WATCH
Definition: postmaster.h:46
static int fd(const char *x, int i)
Definition: preproc-init.c:105
int owner_pid
Definition: latch.h:115
Latch * latch
Definition: latch.c:119
bool exit_on_postmaster_death
Definition: latch.c:127
int nevents
Definition: latch.c:104
int latch_pos
Definition: latch.c:120
int nevents_space
Definition: latch.c:105
WaitEvent * events
Definition: latch.c:111
int pos
Definition: latch.h:152

References Assert(), elog(), ERROR, WaitEventSet::events, WaitEventSet::exit_on_postmaster_death, fd(), WaitEventSet::latch, WaitEventSet::latch_pos, MyProcPid, WaitEventSet::nevents, WaitEventSet::nevents_space, Latch::owner_pid, PGINVALID_SOCKET, WaitEvent::pos, postmaster_alive_fds, POSTMASTER_FD_WATCH, selfpipe_readfd, WaitEventAdjustPoll(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_MASK.

Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), InitializeLatchWaitSet(), postgresForeignAsyncConfigureWait(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().

◆ CreateWaitEventSet()

WaitEventSet* CreateWaitEventSet ( MemoryContext  context,
int  nevents 
)

Definition at line 721 of file latch.c.

722 {
723  WaitEventSet *set;
724  char *data;
725  Size sz = 0;
726 
727  /*
728  * Use MAXALIGN size/alignment to guarantee that later uses of memory are
729  * aligned correctly. E.g. epoll_event might need 8 byte alignment on some
730  * platforms, but earlier allocations like WaitEventSet and WaitEvent
731  * might not be sized to guarantee that when purely using sizeof().
732  */
733  sz += MAXALIGN(sizeof(WaitEventSet));
734  sz += MAXALIGN(sizeof(WaitEvent) * nevents);
735 
736 #if defined(WAIT_USE_EPOLL)
737  sz += MAXALIGN(sizeof(struct epoll_event) * nevents);
738 #elif defined(WAIT_USE_KQUEUE)
739  sz += MAXALIGN(sizeof(struct kevent) * nevents);
740 #elif defined(WAIT_USE_POLL)
741  sz += MAXALIGN(sizeof(struct pollfd) * nevents);
742 #elif defined(WAIT_USE_WIN32)
743  /* need space for the pgwin32_signal_event */
744  sz += MAXALIGN(sizeof(HANDLE) * (nevents + 1));
745 #endif
746 
747  data = (char *) MemoryContextAllocZero(context, sz);
748 
749  set = (WaitEventSet *) data;
750  data += MAXALIGN(sizeof(WaitEventSet));
751 
752  set->events = (WaitEvent *) data;
753  data += MAXALIGN(sizeof(WaitEvent) * nevents);
754 
755 #if defined(WAIT_USE_EPOLL)
756  set->epoll_ret_events = (struct epoll_event *) data;
757  data += MAXALIGN(sizeof(struct epoll_event) * nevents);
758 #elif defined(WAIT_USE_KQUEUE)
759  set->kqueue_ret_events = (struct kevent *) data;
760  data += MAXALIGN(sizeof(struct kevent) * nevents);
761 #elif defined(WAIT_USE_POLL)
762  set->pollfds = (struct pollfd *) data;
763  data += MAXALIGN(sizeof(struct pollfd) * nevents);
764 #elif defined(WAIT_USE_WIN32)
765  set->handles = (HANDLE) data;
766  data += MAXALIGN(sizeof(HANDLE) * nevents);
767 #endif
768 
769  set->latch = NULL;
770  set->nevents_space = nevents;
771  set->exit_on_postmaster_death = false;
772 
773 #if defined(WAIT_USE_EPOLL)
774  if (!AcquireExternalFD())
775  {
776  /* treat this as though epoll_create1 itself returned EMFILE */
777  elog(ERROR, "epoll_create1 failed: %m");
778  }
779  set->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
780  if (set->epoll_fd < 0)
781  {
783  elog(ERROR, "epoll_create1 failed: %m");
784  }
785 #elif defined(WAIT_USE_KQUEUE)
786  if (!AcquireExternalFD())
787  {
788  /* treat this as though kqueue itself returned EMFILE */
789  elog(ERROR, "kqueue failed: %m");
790  }
791  set->kqueue_fd = kqueue();
792  if (set->kqueue_fd < 0)
793  {
795  elog(ERROR, "kqueue failed: %m");
796  }
797  if (fcntl(set->kqueue_fd, F_SETFD, FD_CLOEXEC) == -1)
798  {
799  int save_errno = errno;
800 
801  close(set->kqueue_fd);
803  errno = save_errno;
804  elog(ERROR, "fcntl(F_SETFD) failed on kqueue descriptor: %m");
805  }
806  set->report_postmaster_not_running = false;
807 #elif defined(WAIT_USE_WIN32)
808 
809  /*
810  * To handle signals while waiting, we need to add a win32 specific event.
811  * We accounted for the additional event at the top of this routine. See
812  * port/win32/signal.c for more details.
813  *
814  * Note: pgwin32_signal_event should be first to ensure that it will be
815  * reported when multiple events are set. We want to guarantee that
816  * pending signals are serviced.
817  */
818  set->handles[0] = pgwin32_signal_event;
819  StaticAssertStmt(WSA_INVALID_EVENT == NULL, "");
820 #endif
821 
822  return set;
823 }
#define MAXALIGN(LEN)
Definition: c.h:800
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:927
size_t Size
Definition: c.h:594
void ReleaseExternalFD(void)
Definition: fd.c:1191
bool AcquireExternalFD(void)
Definition: fd.c:1138
#define close(a)
Definition: win32.h:12
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1064
const void * data
HANDLE pgwin32_signal_event
Definition: signal.c:27
struct pollfd * pollfds
Definition: latch.c:140

References AcquireExternalFD(), close, data, elog(), ERROR, WaitEventSet::events, WaitEventSet::exit_on_postmaster_death, WaitEventSet::latch, MAXALIGN, MemoryContextAllocZero(), WaitEventSet::nevents_space, pgwin32_signal_event, WaitEventSet::pollfds, ReleaseExternalFD(), and StaticAssertStmt.

Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), InitializeLatchWaitSet(), pq_init(), SysLoggerMain(), and WaitLatchOrSocket().

◆ DisownLatch()

void DisownLatch ( Latch latch)

Definition at line 462 of file latch.c.

463 {
464  Assert(latch->is_shared);
465  Assert(latch->owner_pid == MyProcPid);
466 
467  latch->owner_pid = 0;
468 }
bool is_shared
Definition: latch.h:114

References Assert(), Latch::is_shared, MyProcPid, and Latch::owner_pid.

Referenced by AuxiliaryProcKill(), ProcKill(), and ShutdownWalRecovery().

◆ FreeWaitEventSet()

void FreeWaitEventSet ( WaitEventSet set)

Definition at line 835 of file latch.c.

836 {
837 #if defined(WAIT_USE_EPOLL)
838  close(set->epoll_fd);
840 #elif defined(WAIT_USE_KQUEUE)
841  close(set->kqueue_fd);
843 #elif defined(WAIT_USE_WIN32)
844  WaitEvent *cur_event;
845 
846  for (cur_event = set->events;
847  cur_event < (set->events + set->nevents);
848  cur_event++)
849  {
850  if (cur_event->events & WL_LATCH_SET)
851  {
852  /* uses the latch's HANDLE */
853  }
854  else if (cur_event->events & WL_POSTMASTER_DEATH)
855  {
856  /* uses PostmasterHandle */
857  }
858  else
859  {
860  /* Clean up the event object we created for the socket */
861  WSAEventSelect(cur_event->fd, NULL, 0);
862  WSACloseEvent(set->handles[cur_event->pos + 1]);
863  }
864  }
865 #endif
866 
867  pfree(set);
868 }
void pfree(void *pointer)
Definition: mcxt.c:1456
pgsocket fd
Definition: latch.h:154
uint32 events
Definition: latch.h:153

References close, WaitEventSet::events, WaitEvent::events, WaitEvent::fd, WaitEventSet::nevents, pfree(), WaitEvent::pos, ReleaseExternalFD(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.

Referenced by ConfigurePostmasterWaitSet(), ExecAppendAsyncEventWait(), ShutdownLatchSupport(), and WaitLatchOrSocket().

◆ FreeWaitEventSetAfterFork()

void FreeWaitEventSetAfterFork ( WaitEventSet set)

Definition at line 874 of file latch.c.

875 {
876 #if defined(WAIT_USE_EPOLL)
877  close(set->epoll_fd);
879 #elif defined(WAIT_USE_KQUEUE)
880  /* kqueues are not normally inherited by child processes */
882 #endif
883 
884  pfree(set);
885 }

References close, pfree(), and ReleaseExternalFD().

Referenced by ClosePostmasterPorts().

◆ GetNumRegisteredWaitEvents()

int GetNumRegisteredWaitEvents ( WaitEventSet set)

Definition at line 2187 of file latch.c.

2188 {
2189  return set->nevents;
2190 }

References WaitEventSet::nevents.

Referenced by ExecAppendAsyncEventWait(), and postgresForeignAsyncConfigureWait().

◆ InitializeLatchSupport()

void InitializeLatchSupport ( void  )

Definition at line 205 of file latch.c.

206 {
207 #if defined(WAIT_USE_SELF_PIPE)
208  int pipefd[2];
209 
210  if (IsUnderPostmaster)
211  {
212  /*
213  * We might have inherited connections to a self-pipe created by the
214  * postmaster. It's critical that child processes create their own
215  * self-pipes, of course, and we really want them to close the
216  * inherited FDs for safety's sake.
217  */
218  if (selfpipe_owner_pid != 0)
219  {
220  /* Assert we go through here but once in a child process */
222  /* Release postmaster's pipe FDs; ignore any error */
223  (void) close(selfpipe_readfd);
224  (void) close(selfpipe_writefd);
225  /* Clean up, just for safety's sake; we'll set these below */
227  selfpipe_owner_pid = 0;
228  /* Keep fd.c's accounting straight */
231  }
232  else
233  {
234  /*
235  * Postmaster didn't create a self-pipe ... or else we're in an
236  * EXEC_BACKEND build, in which case it doesn't matter since the
237  * postmaster's pipe FDs were closed by the action of FD_CLOEXEC.
238  * fd.c won't have state to clean up, either.
239  */
240  Assert(selfpipe_readfd == -1);
241  }
242  }
243  else
244  {
245  /* In postmaster or standalone backend, assert we do this but once */
246  Assert(selfpipe_readfd == -1);
248  }
249 
250  /*
251  * Set up the self-pipe that allows a signal handler to wake up the
252  * poll()/epoll_wait() in WaitLatch. Make the write-end non-blocking, so
253  * that SetLatch won't block if the event has already been set many times
254  * filling the kernel buffer. Make the read-end non-blocking too, so that
255  * we can easily clear the pipe by reading until EAGAIN or EWOULDBLOCK.
256  * Also, make both FDs close-on-exec, since we surely do not want any
257  * child processes messing with them.
258  */
259  if (pipe(pipefd) < 0)
260  elog(FATAL, "pipe() failed: %m");
261  if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) == -1)
262  elog(FATAL, "fcntl(F_SETFL) failed on read-end of self-pipe: %m");
263  if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) == -1)
264  elog(FATAL, "fcntl(F_SETFL) failed on write-end of self-pipe: %m");
265  if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1)
266  elog(FATAL, "fcntl(F_SETFD) failed on read-end of self-pipe: %m");
267  if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1)
268  elog(FATAL, "fcntl(F_SETFD) failed on write-end of self-pipe: %m");
269 
270  selfpipe_readfd = pipefd[0];
271  selfpipe_writefd = pipefd[1];
273 
274  /* Tell fd.c about these two long-lived FDs */
277 
279 #endif
280 
281 #ifdef WAIT_USE_SIGNALFD
282  sigset_t signalfd_mask;
283 
284  if (IsUnderPostmaster)
285  {
286  /*
287  * It would probably be safe to re-use the inherited signalfd since
288  * signalfds only see the current process's pending signals, but it
289  * seems less surprising to close it and create our own.
290  */
291  if (signal_fd != -1)
292  {
293  /* Release postmaster's signal FD; ignore any error */
294  (void) close(signal_fd);
295  signal_fd = -1;
297  }
298  }
299 
300  /* Block SIGURG, because we'll receive it through a signalfd. */
301  sigaddset(&UnBlockSig, SIGURG);
302 
303  /* Set up the signalfd to receive SIGURG notifications. */
304  sigemptyset(&signalfd_mask);
305  sigaddset(&signalfd_mask, SIGURG);
306  signal_fd = signalfd(-1, &signalfd_mask, SFD_NONBLOCK | SFD_CLOEXEC);
307  if (signal_fd < 0)
308  elog(FATAL, "signalfd() failed");
310 #endif
311 
312 #ifdef WAIT_USE_KQUEUE
313  /* Ignore SIGURG, because we'll receive it via kqueue. */
314  pqsignal(SIGURG, SIG_IGN);
315 #endif
316 }
sigset_t UnBlockSig
Definition: pqsignal.c:22
#define FATAL
Definition: elog.h:41
void ReserveExternalFD(void)
Definition: fd.c:1173
bool IsUnderPostmaster
Definition: globals.c:113
static void latch_sigurg_handler(SIGNAL_ARGS)
Definition: latch.c:2200
static int selfpipe_owner_pid
Definition: latch.c:174
static int selfpipe_writefd
Definition: latch.c:171
pqsigfunc pqsignal(int signo, pqsigfunc func)
#define SIG_IGN
Definition: win32_port.h:165

References Assert(), close, elog(), FATAL, IsUnderPostmaster, latch_sigurg_handler(), MyProcPid, pqsignal(), ReleaseExternalFD(), ReserveExternalFD(), selfpipe_owner_pid, selfpipe_readfd, selfpipe_writefd, SIG_IGN, and UnBlockSig.

Referenced by InitPostmasterChild(), InitStandaloneProcess(), and PostmasterMain().

◆ InitializeLatchWaitSet()

void InitializeLatchWaitSet ( void  )

Definition at line 319 of file latch.c.

320 {
321  int latch_pos PG_USED_FOR_ASSERTS_ONLY;
322 
323  Assert(LatchWaitSet == NULL);
324 
325  /* Set up the WaitEventSet used by WaitLatch(). */
328  MyLatch, NULL);
329  if (IsUnderPostmaster)
331  PGINVALID_SOCKET, NULL, NULL);
332 
333  Assert(latch_pos == LatchWaitSetLatchPos);
334 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:171
struct Latch * MyLatch
Definition: globals.c:58
#define LatchWaitSetLatchPos
Definition: latch.c:156
WaitEventSet * CreateWaitEventSet(MemoryContext context, int nevents)
Definition: latch.c:721
static WaitEventSet * LatchWaitSet
Definition: latch.c:153
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
Definition: latch.c:920
MemoryContext TopMemoryContext
Definition: mcxt.c:141

References AddWaitEventToSet(), Assert(), CreateWaitEventSet(), IsUnderPostmaster, LatchWaitSet, LatchWaitSetLatchPos, MyLatch, PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, TopMemoryContext, WL_EXIT_ON_PM_DEATH, and WL_LATCH_SET.

Referenced by InitPostmasterChild(), and InitStandaloneProcess().

◆ InitLatch()

void InitLatch ( Latch latch)

Definition at line 367 of file latch.c.

368 {
369  latch->is_set = false;
370  latch->maybe_sleeping = false;
371  latch->owner_pid = MyProcPid;
372  latch->is_shared = false;
373 
374 #if defined(WAIT_USE_SELF_PIPE)
375  /* Assert InitializeLatchSupport has been called in this process */
377 #elif defined(WAIT_USE_SIGNALFD)
378  /* Assert InitializeLatchSupport has been called in this process */
379  Assert(signal_fd >= 0);
380 #elif defined(WAIT_USE_WIN32)
381  latch->event = CreateEvent(NULL, TRUE, FALSE, NULL);
382  if (latch->event == NULL)
383  elog(ERROR, "CreateEvent failed: error code %lu", GetLastError());
384 #endif /* WIN32 */
385 }
sig_atomic_t is_set
Definition: latch.h:112
sig_atomic_t maybe_sleeping
Definition: latch.h:113

References Assert(), elog(), ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, selfpipe_owner_pid, and selfpipe_readfd.

Referenced by InitProcessLocalLatch().

◆ InitSharedLatch()

void InitSharedLatch ( Latch latch)

Definition at line 403 of file latch.c.

404 {
405 #ifdef WIN32
406  SECURITY_ATTRIBUTES sa;
407 
408  /*
409  * Set up security attributes to specify that the events are inherited.
410  */
411  ZeroMemory(&sa, sizeof(sa));
412  sa.nLength = sizeof(sa);
413  sa.bInheritHandle = TRUE;
414 
415  latch->event = CreateEvent(&sa, TRUE, FALSE, NULL);
416  if (latch->event == NULL)
417  elog(ERROR, "CreateEvent failed: error code %lu", GetLastError());
418 #endif
419 
420  latch->is_set = false;
421  latch->maybe_sleeping = false;
422  latch->owner_pid = 0;
423  latch->is_shared = true;
424 }

References elog(), ERROR, Latch::is_set, Latch::is_shared, Latch::maybe_sleeping, and Latch::owner_pid.

Referenced by InitProcGlobal(), and XLogRecoveryShmemInit().

◆ ModifyWaitEvent()

void ModifyWaitEvent ( WaitEventSet set,
int  pos,
uint32  events,
Latch latch 
)

Definition at line 1006 of file latch.c.

1007 {
1008  WaitEvent *event;
1009 #if defined(WAIT_USE_KQUEUE)
1010  int old_events;
1011 #endif
1012 
1013  Assert(pos < set->nevents);
1014 
1015  event = &set->events[pos];
1016 #if defined(WAIT_USE_KQUEUE)
1017  old_events = event->events;
1018 #endif
1019 
1020  /*
1021  * If neither the event mask nor the associated latch changes, return
1022  * early. That's an important optimization for some sockets, where
1023  * ModifyWaitEvent is frequently used to switch from waiting for reads to
1024  * waiting on writes.
1025  */
1026  if (events == event->events &&
1027  (!(event->events & WL_LATCH_SET) || set->latch == latch))
1028  return;
1029 
1030  if (event->events & WL_LATCH_SET &&
1031  events != event->events)
1032  {
1033  elog(ERROR, "cannot modify latch event");
1034  }
1035 
1036  if (event->events & WL_POSTMASTER_DEATH)
1037  {
1038  elog(ERROR, "cannot modify postmaster death event");
1039  }
1040 
1041  /* FIXME: validate event mask */
1042  event->events = events;
1043 
1044  if (events == WL_LATCH_SET)
1045  {
1046  if (latch && latch->owner_pid != MyProcPid)
1047  elog(ERROR, "cannot wait on a latch owned by another process");
1048  set->latch = latch;
1049 
1050  /*
1051  * On Unix, we don't need to modify the kernel object because the
1052  * underlying pipe (if there is one) is the same for all latches so we
1053  * can return immediately. On Windows, we need to update our array of
1054  * handles, but we leave the old one in place and tolerate spurious
1055  * wakeups if the latch is disabled.
1056  */
1057 #if defined(WAIT_USE_WIN32)
1058  if (!latch)
1059  return;
1060 #else
1061  return;
1062 #endif
1063  }
1064 
1065 #if defined(WAIT_USE_EPOLL)
1066  WaitEventAdjustEpoll(set, event, EPOLL_CTL_MOD);
1067 #elif defined(WAIT_USE_KQUEUE)
1068  WaitEventAdjustKqueue(set, event, old_events);
1069 #elif defined(WAIT_USE_POLL)
1070  WaitEventAdjustPoll(set, event);
1071 #elif defined(WAIT_USE_WIN32)
1072  WaitEventAdjustWin32(set, event);
1073 #endif
1074 }

References Assert(), elog(), ERROR, WaitEventSet::events, WaitEvent::events, WaitEventSet::latch, MyProcPid, Latch::owner_pid, WaitEventAdjustPoll(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.

Referenced by pq_check_connection(), secure_read(), secure_write(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), WaitLatch(), and WalSndWait().

◆ OwnLatch()

void OwnLatch ( Latch latch)

Definition at line 436 of file latch.c.

437 {
438  int owner_pid;
439 
440  /* Sanity checks */
441  Assert(latch->is_shared);
442 
443 #if defined(WAIT_USE_SELF_PIPE)
444  /* Assert InitializeLatchSupport has been called in this process */
446 #elif defined(WAIT_USE_SIGNALFD)
447  /* Assert InitializeLatchSupport has been called in this process */
448  Assert(signal_fd >= 0);
449 #endif
450 
451  owner_pid = latch->owner_pid;
452  if (owner_pid != 0)
453  elog(PANIC, "latch already owned by PID %d", owner_pid);
454 
455  latch->owner_pid = MyProcPid;
456 }
#define PANIC
Definition: elog.h:42

References Assert(), elog(), Latch::is_shared, MyProcPid, Latch::owner_pid, PANIC, selfpipe_owner_pid, and selfpipe_readfd.

Referenced by InitAuxiliaryProcess(), InitProcess(), and InitWalRecovery().

◆ ResetLatch()

void ResetLatch ( Latch latch)

Definition at line 697 of file latch.c.

698 {
699  /* Only the owner should reset the latch */
700  Assert(latch->owner_pid == MyProcPid);
701  Assert(latch->maybe_sleeping == false);
702 
703  latch->is_set = false;
704 
705  /*
706  * Ensure that the write to is_set gets flushed to main memory before we
707  * examine any flag variables. Otherwise a concurrent SetLatch might
708  * falsely conclude that it needn't signal us, even though we have missed
709  * seeing some flag updates that SetLatch was supposed to inform us of.
710  */
712 }
#define pg_memory_barrier()
Definition: atomics.h:140

References Assert(), Latch::is_set, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, and pg_memory_barrier.

Referenced by ApplyLauncherMain(), autoprewarm_main(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CheckpointWriteDelay(), ConditionVariableTimedSleep(), copy_read_data(), do_pg_backup_stop(), gather_readnext(), lazy_truncate_heap(), libpqrcv_PQgetResult(), libpqsrv_connect_internal(), LogicalParallelApplyLoop(), logicalrep_worker_stop_internal(), LogicalRepApplyLoop(), mq_putmessage(), pa_send_data(), pa_wait_for_xact_state(), pg_promote(), pg_sleep(), pg_wait_until_termination(), pgarch_MainLoop(), pgfdw_get_cleanup_result(), pgfdw_get_result(), pq_check_connection(), ProcessPendingWrites(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), secure_read(), secure_write(), ServerLoop(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), SyncRepWaitForLSN(), SysLoggerMain(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), WalReceiverMain(), WalSndLoop(), WalSndWaitForWal(), WalWriterMain(), and worker_spi_main().

◆ SetLatch()

void SetLatch ( Latch latch)

Definition at line 605 of file latch.c.

606 {
607 #ifndef WIN32
608  pid_t owner_pid;
609 #else
610  HANDLE handle;
611 #endif
612 
613  /*
614  * The memory barrier has to be placed here to ensure that any flag
615  * variables possibly changed by this process have been flushed to main
616  * memory, before we check/set is_set.
617  */
619 
620  /* Quick exit if already set */
621  if (latch->is_set)
622  return;
623 
624  latch->is_set = true;
625 
627  if (!latch->maybe_sleeping)
628  return;
629 
630 #ifndef WIN32
631 
632  /*
633  * See if anyone's waiting for the latch. It can be the current process if
634  * we're in a signal handler. We use the self-pipe or SIGURG to ourselves
635  * to wake up WaitEventSetWaitBlock() without races in that case. If it's
636  * another process, send a signal.
637  *
638  * Fetch owner_pid only once, in case the latch is concurrently getting
639  * owned or disowned. XXX: This assumes that pid_t is atomic, which isn't
640  * guaranteed to be true! In practice, the effective range of pid_t fits
641  * in a 32 bit integer, and so should be atomic. In the worst case, we
642  * might end up signaling the wrong process. Even then, you're very
643  * unlucky if a process with that bogus pid exists and belongs to
644  * Postgres; and PG database processes should handle excess SIGUSR1
645  * interrupts without a problem anyhow.
646  *
647  * Another sort of race condition that's possible here is for a new
648  * process to own the latch immediately after we look, so we don't signal
649  * it. This is okay so long as all callers of ResetLatch/WaitLatch follow
650  * the standard coding convention of waiting at the bottom of their loops,
651  * not the top, so that they'll correctly process latch-setting events
652  * that happen before they enter the loop.
653  */
654  owner_pid = latch->owner_pid;
655  if (owner_pid == 0)
656  return;
657  else if (owner_pid == MyProcPid)
658  {
659 #if defined(WAIT_USE_SELF_PIPE)
660  if (waiting)
662 #else
663  if (waiting)
664  kill(MyProcPid, SIGURG);
665 #endif
666  }
667  else
668  kill(owner_pid, SIGURG);
669 
670 #else
671 
672  /*
673  * See if anyone's waiting for the latch. It can be the current process if
674  * we're in a signal handler.
675  *
676  * Use a local variable here just in case somebody changes the event field
677  * concurrently (which really should not happen).
678  */
679  handle = latch->event;
680  if (handle)
681  {
682  SetEvent(handle);
683 
684  /*
685  * Note that we silently ignore any errors. We might be in a signal
686  * handler or other critical path where it's not safe to call elog().
687  */
688  }
689 #endif
690 }
static void sendSelfPipeByte(void)
Definition: latch.c:2212
static volatile sig_atomic_t waiting
Definition: latch.c:160
#define kill(pid, sig)
Definition: win32_port.h:485

References Latch::is_set, kill, Latch::maybe_sleeping, MyProcPid, Latch::owner_pid, pg_memory_barrier, sendSelfPipeByte(), and waiting.

Referenced by avl_sigusr2_handler(), CheckDeadLockAlert(), ClientCheckTimeoutHandler(), ConditionVariableBroadcast(), ConditionVariableSignal(), die(), ForwardSyncRequest(), handle_pm_child_exit_signal(), handle_pm_pmsignal_signal(), handle_pm_reload_request_signal(), handle_pm_shutdown_request_signal(), handle_sig_alarm(), HandleCatchupInterrupt(), HandleNotifyInterrupt(), HandleParallelApplyMessageInterrupt(), HandleParallelMessageInterrupt(), IdleInTransactionSessionTimeoutHandler(), IdleSessionTimeoutHandler(), IdleStatsUpdateTimeoutHandler(), logicalrep_worker_wakeup_ptr(), pgarch_waken_stop(), PgArchWakeup(), ProcessClientReadInterrupt(), ProcessClientWriteInterrupt(), ProcessPendingWrites(), ProcSendSignal(), procsignal_sigusr1_handler(), ProcWakeup(), ReqCheckpointHandler(), RequestXLogStreaming(), shm_mq_detach_internal(), shm_mq_inc_bytes_read(), shm_mq_send_bytes(), shm_mq_sendv(), shm_mq_set_receiver(), shm_mq_set_sender(), SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), sigUsr1Handler(), StatementCancelHandler(), StrategyGetBuffer(), SwitchBackToLocalLatch(), SwitchToSharedLatch(), SyncRepWakeQueue(), test_shm_mq_main(), WakeupRecovery(), WalRcvForceReply(), WalSndLastCycleHandler(), WalSndWaitForWal(), and XLogSetAsyncXactLSN().

◆ ShutdownLatchSupport()

void ShutdownLatchSupport ( void  )

Definition at line 337 of file latch.c.

338 {
339 #if defined(WAIT_USE_POLL)
340  pqsignal(SIGURG, SIG_IGN);
341 #endif
342 
343  if (LatchWaitSet)
344  {
346  LatchWaitSet = NULL;
347  }
348 
349 #if defined(WAIT_USE_SELF_PIPE)
352  selfpipe_readfd = -1;
353  selfpipe_writefd = -1;
355 #endif
356 
357 #if defined(WAIT_USE_SIGNALFD)
358  close(signal_fd);
359  signal_fd = -1;
360 #endif
361 }
void FreeWaitEventSet(WaitEventSet *set)
Definition: latch.c:835
#define InvalidPid
Definition: miscadmin.h:32

References close, FreeWaitEventSet(), InvalidPid, LatchWaitSet, pqsignal(), selfpipe_owner_pid, selfpipe_readfd, selfpipe_writefd, and SIG_IGN.

◆ WaitEventSetCanReportClosed()

bool WaitEventSetCanReportClosed ( void  )

Definition at line 2172 of file latch.c.

2173 {
2174 #if (defined(WAIT_USE_POLL) && defined(POLLRDHUP)) || \
2175  defined(WAIT_USE_EPOLL) || \
2176  defined(WAIT_USE_KQUEUE)
2177  return true;
2178 #else
2179  return false;
2180 #endif
2181 }

Referenced by check_client_connection_check_interval().

◆ WaitEventSetWait()

int WaitEventSetWait ( WaitEventSet set,
long  timeout,
WaitEvent occurred_events,
int  nevents,
uint32  wait_event_info 
)

Definition at line 1381 of file latch.c.

1384 {
1385  int returned_events = 0;
1387  instr_time cur_time;
1388  long cur_timeout = -1;
1389 
1390  Assert(nevents > 0);
1391 
1392  /*
1393  * Initialize timeout if requested. We must record the current time so
1394  * that we can determine the remaining timeout if interrupted.
1395  */
1396  if (timeout >= 0)
1397  {
1399  Assert(timeout >= 0 && timeout <= INT_MAX);
1400  cur_timeout = timeout;
1401  }
1402  else
1404 
1405  pgstat_report_wait_start(wait_event_info);
1406 
1407 #ifndef WIN32
1408  waiting = true;
1409 #else
1410  /* Ensure that signals are serviced even if latch is already set */
1412 #endif
1413  while (returned_events == 0)
1414  {
1415  int rc;
1416 
1417  /*
1418  * Check if the latch is set already. If so, leave the loop
1419  * immediately, avoid blocking again. We don't attempt to report any
1420  * other events that might also be satisfied.
1421  *
1422  * If someone sets the latch between this and the
1423  * WaitEventSetWaitBlock() below, the setter will write a byte to the
1424  * pipe (or signal us and the signal handler will do that), and the
1425  * readiness routine will return immediately.
1426  *
1427  * On unix, If there's a pending byte in the self pipe, we'll notice
1428  * whenever blocking. Only clearing the pipe in that case avoids
1429  * having to drain it every time WaitLatchOrSocket() is used. Should
1430  * the pipe-buffer fill up we're still ok, because the pipe is in
1431  * nonblocking mode. It's unlikely for that to happen, because the
1432  * self pipe isn't filled unless we're blocking (waiting = true), or
1433  * from inside a signal handler in latch_sigurg_handler().
1434  *
1435  * On windows, we'll also notice if there's a pending event for the
1436  * latch when blocking, but there's no danger of anything filling up,
1437  * as "Setting an event that is already set has no effect.".
1438  *
1439  * Note: we assume that the kernel calls involved in latch management
1440  * will provide adequate synchronization on machines with weak memory
1441  * ordering, so that we cannot miss seeing is_set if a notification
1442  * has already been queued.
1443  */
1444  if (set->latch && !set->latch->is_set)
1445  {
1446  /* about to sleep on a latch */
1447  set->latch->maybe_sleeping = true;
1449  /* and recheck */
1450  }
1451 
1452  if (set->latch && set->latch->is_set)
1453  {
1454  occurred_events->fd = PGINVALID_SOCKET;
1455  occurred_events->pos = set->latch_pos;
1456  occurred_events->user_data =
1457  set->events[set->latch_pos].user_data;
1458  occurred_events->events = WL_LATCH_SET;
1459  occurred_events++;
1460  returned_events++;
1461 
1462  /* could have been set above */
1463  set->latch->maybe_sleeping = false;
1464 
1465  break;
1466  }
1467 
1468  /*
1469  * Wait for events using the readiness primitive chosen at the top of
1470  * this file. If -1 is returned, a timeout has occurred, if 0 we have
1471  * to retry, everything >= 1 is the number of returned events.
1472  */
1473  rc = WaitEventSetWaitBlock(set, cur_timeout,
1474  occurred_events, nevents);
1475 
1476  if (set->latch)
1477  {
1478  Assert(set->latch->maybe_sleeping);
1479  set->latch->maybe_sleeping = false;
1480  }
1481 
1482  if (rc == -1)
1483  break; /* timeout occurred */
1484  else
1485  returned_events = rc;
1486 
1487  /* If we're not done, update cur_timeout for next iteration */
1488  if (returned_events == 0 && timeout >= 0)
1489  {
1490  INSTR_TIME_SET_CURRENT(cur_time);
1491  INSTR_TIME_SUBTRACT(cur_time, start_time);
1492  cur_timeout = timeout - (long) INSTR_TIME_GET_MILLISEC(cur_time);
1493  if (cur_timeout <= 0)
1494  break;
1495  }
1496  }
1497 #ifndef WIN32
1498  waiting = false;
1499 #endif
1500 
1502 
1503  return returned_events;
1504 }
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:122
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:181
#define INSTR_TIME_GET_MILLISEC(t)
Definition: instr_time.h:191
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:172
static int WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, WaitEvent *occurred_events, int nevents)
Definition: latch.c:1807
static time_t start_time
Definition: pg_ctl.c:94
void pgwin32_dispatch_queued_signals(void)
Definition: signal.c:120
void * user_data
Definition: latch.h:155
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:88
static void pgstat_report_wait_end(void)
Definition: wait_event.h:104

References Assert(), WaitEventSet::events, WaitEvent::events, WaitEvent::fd, INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, INSTR_TIME_SUBTRACT, Latch::is_set, WaitEventSet::latch, WaitEventSet::latch_pos, Latch::maybe_sleeping, pg_memory_barrier, PGINVALID_SOCKET, pgstat_report_wait_end(), pgstat_report_wait_start(), pgwin32_dispatch_queued_signals(), WaitEvent::pos, start_time, WaitEvent::user_data, WaitEventSetWaitBlock(), waiting, and WL_LATCH_SET.

Referenced by ExecAppendAsyncEventWait(), pq_check_connection(), secure_read(), secure_write(), ServerLoop(), SysLoggerMain(), WaitLatch(), WaitLatchOrSocket(), and WalSndWait().

◆ WaitLatch()

int WaitLatch ( Latch latch,
int  wakeEvents,
long  timeout,
uint32  wait_event_info 
)

Definition at line 490 of file latch.c.

492 {
493  WaitEvent event;
494 
495  /* Postmaster-managed callers must handle postmaster death somehow. */
497  (wakeEvents & WL_EXIT_ON_PM_DEATH) ||
498  (wakeEvents & WL_POSTMASTER_DEATH));
499 
500  /*
501  * Some callers may have a latch other than MyLatch, or no latch at all,
502  * or want to handle postmaster death differently. It's cheap to assign
503  * those, so just do it every time.
504  */
505  if (!(wakeEvents & WL_LATCH_SET))
506  latch = NULL;
509  ((wakeEvents & WL_EXIT_ON_PM_DEATH) != 0);
510 
512  (wakeEvents & WL_TIMEOUT) ? timeout : -1,
513  &event, 1,
514  wait_event_info) == 0)
515  return WL_TIMEOUT;
516  else
517  return event.events;
518 }
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
Definition: latch.c:1006
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
Definition: latch.c:1381
#define WL_TIMEOUT
Definition: latch.h:128

References Assert(), WaitEventSet::exit_on_postmaster_death, IsUnderPostmaster, LatchWaitSet, LatchWaitSetLatchPos, ModifyWaitEvent(), WaitEventSetWait(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.

Referenced by ApplyLauncherMain(), autoprewarm_main(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CheckpointWriteDelay(), ConditionVariableTimedSleep(), do_pg_backup_stop(), gather_readnext(), lazy_truncate_heap(), LogicalParallelApplyLoop(), logicalrep_worker_stop_internal(), mq_putmessage(), pa_send_data(), pa_wait_for_xact_state(), pg_promote(), pg_sleep(), pg_wait_until_termination(), pgarch_MainLoop(), ProcSleep(), ProcWaitForSignal(), recoveryApplyDelay(), RegisterSyncRequest(), shm_mq_receive_bytes(), shm_mq_send_bytes(), shm_mq_wait_internal(), SyncRepWaitForLSN(), test_shm_mq_pipelined(), throttle(), wait_for_relation_state_change(), wait_for_worker_state_change(), wait_for_workers_to_become_ready(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), WaitForReplicationWorkerAttach(), WaitForWALToBecomeAvailable(), WalRcvWaitForStartPosition(), WalWriterMain(), and worker_spi_main().

◆ WaitLatchOrSocket()

int WaitLatchOrSocket ( Latch latch,
int  wakeEvents,
pgsocket  sock,
long  timeout,
uint32  wait_event_info 
)

Definition at line 538 of file latch.c.

540 {
541  int ret = 0;
542  int rc;
543  WaitEvent event;
545 
546  if (wakeEvents & WL_TIMEOUT)
547  Assert(timeout >= 0);
548  else
549  timeout = -1;
550 
551  if (wakeEvents & WL_LATCH_SET)
553  latch, NULL);
554 
555  /* Postmaster-managed callers must handle postmaster death somehow. */
557  (wakeEvents & WL_EXIT_ON_PM_DEATH) ||
558  (wakeEvents & WL_POSTMASTER_DEATH));
559 
560  if ((wakeEvents & WL_POSTMASTER_DEATH) && IsUnderPostmaster)
562  NULL, NULL);
563 
564  if ((wakeEvents & WL_EXIT_ON_PM_DEATH) && IsUnderPostmaster)
566  NULL, NULL);
567 
568  if (wakeEvents & WL_SOCKET_MASK)
569  {
570  int ev;
571 
572  ev = wakeEvents & WL_SOCKET_MASK;
573  AddWaitEventToSet(set, ev, sock, NULL, NULL);
574  }
575 
576  rc = WaitEventSetWait(set, timeout, &event, 1, wait_event_info);
577 
578  if (rc == 0)
579  ret |= WL_TIMEOUT;
580  else
581  {
582  ret |= event.events & (WL_LATCH_SET |
585  }
586 
587  FreeWaitEventSet(set);
588 
589  return ret;
590 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135

References AddWaitEventToSet(), Assert(), CreateWaitEventSet(), CurrentMemoryContext, FreeWaitEventSet(), IsUnderPostmaster, PGINVALID_SOCKET, WaitEventSetWait(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_POSTMASTER_DEATH, WL_SOCKET_MASK, and WL_TIMEOUT.

Referenced by be_tls_open_server(), copy_read_data(), libpqrcv_PQgetResult(), libpqsrv_connect_internal(), LogicalRepApplyLoop(), pgfdw_get_cleanup_result(), pgfdw_get_result(), read_or_wait(), secure_open_gssapi(), and WalReceiverMain().