1/*-------------------------------------------------------------------------
4 * ppoll() / pselect() like interface for waiting for events
6 * WaitEventSets allow to wait for latches being set and additional events -
7 * postmaster dying and socket readiness of several sockets currently - at the
8 * same time. On many platforms using a long lived event set is more
9 * efficient than using WaitLatch or WaitLatchOrSocket.
11 * WaitEventSetWait includes a provision for timeouts (which should be avoided
12 * when possible, as they incur extra overhead) and a provision for postmaster
13 * child processes to wake up immediately on postmaster death. See
14 * storage/ipc/waiteventset.c for detailed specifications for the exported
18 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
19 * Portions Copyright (c) 1994, Regents of the University of California
21 * src/include/storage/waiteventset.h
23 *-------------------------------------------------------------------------
31 * Bitmasks for events that may wake-up WaitLatch(), WaitLatchOrSocket(), or
34 #define WL_LATCH_SET (1 << 0)
35 #define WL_SOCKET_READABLE (1 << 1)
36 #define WL_SOCKET_WRITEABLE (1 << 2)
37 #define WL_TIMEOUT (1 << 3) /* not for WaitEventSetWait() */
38 #define WL_POSTMASTER_DEATH (1 << 4)
39 #define WL_EXIT_ON_PM_DEATH (1 << 5)
41#define WL_SOCKET_CONNECTED (1 << 6)
43/* avoid having to deal with case on platforms not requiring it */
44 #define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
46 #define WL_SOCKET_CLOSED (1 << 7)
48#define WL_SOCKET_ACCEPT (1 << 8)
50/* avoid having to deal with case on platforms not requiring it */
51 #define WL_SOCKET_ACCEPT WL_SOCKET_READABLE
53 #define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
54 WL_SOCKET_WRITEABLE | \
55 WL_SOCKET_CONNECTED | \
61 int pos;
/* position in the event data structure */
64 void *
user_data;
/* pointer provided in AddWaitEventToSet */
66 bool reset;
/* Is reset of the event required? */
70/* forward declarations to avoid exposing waiteventset.c implementation details */
76 * prototypes for functions in waiteventset.c
84 struct Latch *latch,
void *user_data);
98#endif /* WAITEVENTSET_H */
static int fd(const char *x, int i)
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, struct Latch *latch, void *user_data)
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, struct Latch *latch)
void FreeWaitEventSetAfterFork(WaitEventSet *set)
int GetNumRegisteredWaitEvents(WaitEventSet *set)
void WakeupOtherProc(int pid)
void InitializeWaitEventSupport(void)
bool WaitEventSetCanReportClosed(void)
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
void FreeWaitEventSet(WaitEventSet *set)
WaitEventSet * CreateWaitEventSet(ResourceOwner resowner, int nevents)
struct WaitEvent WaitEvent