PostgreSQL Source Code: src/include/storage/waiteventset.h Source File

PostgreSQL Source Code git master
waiteventset.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * waiteventset.h
4 * ppoll() / pselect() like interface for waiting for events
5 *
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.
10 *
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
15 * functions.
16 *
17 *
18 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
19 * Portions Copyright (c) 1994, Regents of the University of California
20 *
21 * src/include/storage/waiteventset.h
22 *
23 *-------------------------------------------------------------------------
24 */
25#ifndef WAITEVENTSET_H
26#define WAITEVENTSET_H
27
28#include "utils/resowner.h"
29
30/*
31 * Bitmasks for events that may wake-up WaitLatch(), WaitLatchOrSocket(), or
32 * WaitEventSetWait().
33 */
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)
40#ifdef WIN32
41#define WL_SOCKET_CONNECTED (1 << 6)
42#else
43/* avoid having to deal with case on platforms not requiring it */
44 #define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
45#endif
46 #define WL_SOCKET_CLOSED (1 << 7)
47#ifdef WIN32
48#define WL_SOCKET_ACCEPT (1 << 8)
49#else
50/* avoid having to deal with case on platforms not requiring it */
51 #define WL_SOCKET_ACCEPT WL_SOCKET_READABLE
52#endif
53 #define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
54 WL_SOCKET_WRITEABLE | \
55 WL_SOCKET_CONNECTED | \
56 WL_SOCKET_ACCEPT | \
57 WL_SOCKET_CLOSED)
58
59 typedef struct WaitEvent
60{
61 int pos; /* position in the event data structure */
62 uint32 events; /* triggered events */
63 pgsocket fd; /* socket fd associated with event */
64 void *user_data; /* pointer provided in AddWaitEventToSet */
65#ifdef WIN32
66 bool reset; /* Is reset of the event required? */
67#endif
68 } WaitEvent;
69
70/* forward declarations to avoid exposing waiteventset.c implementation details */
71 typedef struct WaitEventSet WaitEventSet;
72
73struct Latch;
74
75/*
76 * prototypes for functions in waiteventset.c
77 */
78extern void InitializeWaitEventSupport(void);
79
80extern WaitEventSet *CreateWaitEventSet(ResourceOwner resowner, int nevents);
81extern void FreeWaitEventSet(WaitEventSet *set);
82extern void FreeWaitEventSetAfterFork(WaitEventSet *set);
83extern int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd,
84 struct Latch *latch, void *user_data);
85extern void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events,
86 struct Latch *latch);
87extern int WaitEventSetWait(WaitEventSet *set, long timeout,
88 WaitEvent *occurred_events, int nevents,
89 uint32 wait_event_info);
90extern int GetNumRegisteredWaitEvents(WaitEventSet *set);
91extern bool WaitEventSetCanReportClosed(void);
92
93#ifndef WIN32
94extern void WakeupMyProc(void);
95extern void WakeupOtherProc(int pid);
96#endif
97
98#endif /* WAITEVENTSET_H */
uint32_t uint32
Definition: c.h:538
int pgsocket
Definition: port.h:29
static int fd(const char *x, int i)
Definition: preproc-init.c:105
void reset(void)
Definition: sql-declare.c:600
Definition: latch.h:114
pgsocket fd
Definition: waiteventset.h:63
int pos
Definition: waiteventset.h:61
void * user_data
Definition: waiteventset.h:64
uint32 events
Definition: waiteventset.h:62
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, struct Latch *latch, void *user_data)
Definition: waiteventset.c:570
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, struct Latch *latch)
Definition: waiteventset.c:656
void FreeWaitEventSetAfterFork(WaitEventSet *set)
Definition: waiteventset.c:524
void WakeupMyProc(void)
Definition: waiteventset.c:2020
int GetNumRegisteredWaitEvents(WaitEventSet *set)
Definition: waiteventset.c:1883
void WakeupOtherProc(int pid)
Definition: waiteventset.c:2033
void InitializeWaitEventSupport(void)
Definition: waiteventset.c:241
bool WaitEventSetCanReportClosed(void)
Definition: waiteventset.c:1868
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
Definition: waiteventset.c:1038
void FreeWaitEventSet(WaitEventSet *set)
Definition: waiteventset.c:481
WaitEventSet * CreateWaitEventSet(ResourceOwner resowner, int nevents)
Definition: waiteventset.c:364
struct WaitEvent WaitEvent

AltStyle によって変換されたページ (->オリジナル) /