mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Split WaitEventSet functions to separate source file
latch.c now only contains the Latch related functions, which build on the WaitEventSet abstraction. Most of the platform-dependent stuff is now in waiteventset.c. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/8a507fb6-df28-49d3-81a5-ede180d7f0fb@iki.fi
This commit is contained in:
@ -42,7 +42,7 @@ pqinitmask(void)
|
|||||||
{
|
{
|
||||||
sigemptyset(&UnBlockSig);
|
sigemptyset(&UnBlockSig);
|
||||||
|
|
||||||
/* Note: InitializeLatchSupport() modifies UnBlockSig. */
|
/* Note: InitializeWaitEventSupport() modifies UnBlockSig. */
|
||||||
|
|
||||||
/* First set all signals, then clear some. */
|
/* First set all signals, then clear some. */
|
||||||
sigfillset(&BlockSig);
|
sigfillset(&BlockSig);
|
||||||
|
@ -548,7 +548,7 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
pqsignal(SIGCHLD, handle_pm_child_exit_signal);
|
pqsignal(SIGCHLD, handle_pm_child_exit_signal);
|
||||||
|
|
||||||
/* This may configure SIGURG, depending on platform. */
|
/* This may configure SIGURG, depending on platform. */
|
||||||
InitializeLatchSupport();
|
InitializeWaitEventSupport();
|
||||||
InitProcessLocalLatch();
|
InitProcessLocalLatch();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,6 +25,7 @@ OBJS = \
|
|||||||
signalfuncs.o \
|
signalfuncs.o \
|
||||||
sinval.o \
|
sinval.o \
|
||||||
sinvaladt.o \
|
sinvaladt.o \
|
||||||
standby.o
|
standby.o \
|
||||||
|
waiteventset.o
|
||||||
|
|
||||||
include $(top_srcdir)/src/backend/common.mk
|
include $(top_srcdir)/src/backend/common.mk
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,5 +18,6 @@ backend_sources += files(
|
|||||||
'sinval.c',
|
'sinval.c',
|
||||||
'sinvaladt.c',
|
'sinvaladt.c',
|
||||||
'standby.c',
|
'standby.c',
|
||||||
|
'waiteventset.c',
|
||||||
|
|
||||||
)
|
)
|
||||||
|
2036
src/backend/storage/ipc/waiteventset.c
Normal file
2036
src/backend/storage/ipc/waiteventset.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -127,7 +127,7 @@ InitPostmasterChild(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize process-local latch support */
|
/* Initialize process-local latch support */
|
||||||
InitializeLatchSupport();
|
InitializeWaitEventSupport();
|
||||||
InitProcessLocalLatch();
|
InitProcessLocalLatch();
|
||||||
InitializeLatchWaitSet();
|
InitializeLatchWaitSet();
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ InitStandaloneProcess(const char *argv0)
|
|||||||
InitProcessGlobals();
|
InitProcessGlobals();
|
||||||
|
|
||||||
/* Initialize process-local latch support */
|
/* Initialize process-local latch support */
|
||||||
InitializeLatchSupport();
|
InitializeWaitEventSupport();
|
||||||
InitProcessLocalLatch();
|
InitProcessLocalLatch();
|
||||||
InitializeLatchWaitSet();
|
InitializeLatchWaitSet();
|
||||||
|
|
||||||
|
@ -84,10 +84,11 @@
|
|||||||
* use of any generic handler.
|
* use of any generic handler.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* WaitEventSets allow to wait for latches being set and additional events -
|
* See also WaitEventSets in waiteventset.h. They allow to wait for latches
|
||||||
* postmaster dying and socket readiness of several sockets currently - at the
|
* being set and additional events - postmaster dying and socket readiness of
|
||||||
* same time. On many platforms using a long lived event set is more
|
* several sockets currently - at the same time. On many platforms using a
|
||||||
* efficient than using WaitLatch or WaitLatchOrSocket.
|
* long lived event set is more efficient than using WaitLatch or
|
||||||
|
* WaitLatchOrSocket.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||||
@ -102,7 +103,7 @@
|
|||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "utils/resowner.h"
|
#include "storage/waiteventset.h" /* for WL_* arguments to WaitLatch */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Latch structure should be treated as opaque and only accessed through
|
* Latch structure should be treated as opaque and only accessed through
|
||||||
@ -120,53 +121,9 @@ typedef struct Latch
|
|||||||
#endif
|
#endif
|
||||||
} Latch;
|
} Latch;
|
||||||
|
|
||||||
/*
|
|
||||||
* Bitmasks for events that may wake-up WaitLatch(), WaitLatchOrSocket(), or
|
|
||||||
* WaitEventSetWait().
|
|
||||||
*/
|
|
||||||
#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)
|
|
||||||
#ifdef WIN32
|
|
||||||
#define WL_SOCKET_CONNECTED (1 << 6)
|
|
||||||
#else
|
|
||||||
/* avoid having to deal with case on platforms not requiring it */
|
|
||||||
#define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
|
|
||||||
#endif
|
|
||||||
#define WL_SOCKET_CLOSED (1 << 7)
|
|
||||||
#ifdef WIN32
|
|
||||||
#define WL_SOCKET_ACCEPT (1 << 8)
|
|
||||||
#else
|
|
||||||
/* avoid having to deal with case on platforms not requiring it */
|
|
||||||
#define WL_SOCKET_ACCEPT WL_SOCKET_READABLE
|
|
||||||
#endif
|
|
||||||
#define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
|
|
||||||
WL_SOCKET_WRITEABLE | \
|
|
||||||
WL_SOCKET_CONNECTED | \
|
|
||||||
WL_SOCKET_ACCEPT | \
|
|
||||||
WL_SOCKET_CLOSED)
|
|
||||||
|
|
||||||
typedef struct WaitEvent
|
|
||||||
{
|
|
||||||
int pos; /* position in the event data structure */
|
|
||||||
uint32 events; /* triggered events */
|
|
||||||
pgsocket fd; /* socket fd associated with event */
|
|
||||||
void *user_data; /* pointer provided in AddWaitEventToSet */
|
|
||||||
#ifdef WIN32
|
|
||||||
bool reset; /* Is reset of the event required? */
|
|
||||||
#endif
|
|
||||||
} WaitEvent;
|
|
||||||
|
|
||||||
/* forward declaration to avoid exposing latch.c implementation details */
|
|
||||||
typedef struct WaitEventSet WaitEventSet;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prototypes for functions in latch.c
|
* prototypes for functions in latch.c
|
||||||
*/
|
*/
|
||||||
extern void InitializeLatchSupport(void);
|
|
||||||
extern void InitLatch(Latch *latch);
|
extern void InitLatch(Latch *latch);
|
||||||
extern void InitSharedLatch(Latch *latch);
|
extern void InitSharedLatch(Latch *latch);
|
||||||
extern void OwnLatch(Latch *latch);
|
extern void OwnLatch(Latch *latch);
|
||||||
@ -174,22 +131,10 @@ extern void DisownLatch(Latch *latch);
|
|||||||
extern void SetLatch(Latch *latch);
|
extern void SetLatch(Latch *latch);
|
||||||
extern void ResetLatch(Latch *latch);
|
extern void ResetLatch(Latch *latch);
|
||||||
|
|
||||||
extern WaitEventSet *CreateWaitEventSet(ResourceOwner resowner, int nevents);
|
|
||||||
extern void FreeWaitEventSet(WaitEventSet *set);
|
|
||||||
extern void FreeWaitEventSetAfterFork(WaitEventSet *set);
|
|
||||||
extern int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd,
|
|
||||||
Latch *latch, void *user_data);
|
|
||||||
extern void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch);
|
|
||||||
|
|
||||||
extern int WaitEventSetWait(WaitEventSet *set, long timeout,
|
|
||||||
WaitEvent *occurred_events, int nevents,
|
|
||||||
uint32 wait_event_info);
|
|
||||||
extern int WaitLatch(Latch *latch, int wakeEvents, long timeout,
|
extern int WaitLatch(Latch *latch, int wakeEvents, long timeout,
|
||||||
uint32 wait_event_info);
|
uint32 wait_event_info);
|
||||||
extern int WaitLatchOrSocket(Latch *latch, int wakeEvents,
|
extern int WaitLatchOrSocket(Latch *latch, int wakeEvents,
|
||||||
pgsocket sock, long timeout, uint32 wait_event_info);
|
pgsocket sock, long timeout, uint32 wait_event_info);
|
||||||
extern void InitializeLatchWaitSet(void);
|
extern void InitializeLatchWaitSet(void);
|
||||||
extern int GetNumRegisteredWaitEvents(WaitEventSet *set);
|
|
||||||
extern bool WaitEventSetCanReportClosed(void);
|
|
||||||
|
|
||||||
#endif /* LATCH_H */
|
#endif /* LATCH_H */
|
||||||
|
97
src/include/storage/waiteventset.h
Normal file
97
src/include/storage/waiteventset.h
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* waiteventset.h
|
||||||
|
* ppoll() / pselect() like interface for waiting for events
|
||||||
|
*
|
||||||
|
* WaitEventSets allow to wait for latches being set and additional events -
|
||||||
|
* postmaster dying and socket readiness of several sockets currently - at the
|
||||||
|
* same time. On many platforms using a long lived event set is more
|
||||||
|
* efficient than using WaitLatch or WaitLatchOrSocket.
|
||||||
|
*
|
||||||
|
* WaitEventSetWait includes a provision for timeouts (which should be avoided
|
||||||
|
* when possible, as they incur extra overhead) and a provision for postmaster
|
||||||
|
* child processes to wake up immediately on postmaster death. See
|
||||||
|
* storage/ipc/waiteventset.c for detailed specifications for the exported
|
||||||
|
* functions.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
||||||
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
|
*
|
||||||
|
* src/include/storage/waiteventset.h
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#ifndef WAITEVENTSET_H
|
||||||
|
#define WAITEVENTSET_H
|
||||||
|
|
||||||
|
#include "utils/resowner.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitmasks for events that may wake-up WaitLatch(), WaitLatchOrSocket(), or
|
||||||
|
* WaitEventSetWait().
|
||||||
|
*/
|
||||||
|
#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)
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WL_SOCKET_CONNECTED (1 << 6)
|
||||||
|
#else
|
||||||
|
/* avoid having to deal with case on platforms not requiring it */
|
||||||
|
#define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE
|
||||||
|
#endif
|
||||||
|
#define WL_SOCKET_CLOSED (1 << 7)
|
||||||
|
#ifdef WIN32
|
||||||
|
#define WL_SOCKET_ACCEPT (1 << 8)
|
||||||
|
#else
|
||||||
|
/* avoid having to deal with case on platforms not requiring it */
|
||||||
|
#define WL_SOCKET_ACCEPT WL_SOCKET_READABLE
|
||||||
|
#endif
|
||||||
|
#define WL_SOCKET_MASK (WL_SOCKET_READABLE | \
|
||||||
|
WL_SOCKET_WRITEABLE | \
|
||||||
|
WL_SOCKET_CONNECTED | \
|
||||||
|
WL_SOCKET_ACCEPT | \
|
||||||
|
WL_SOCKET_CLOSED)
|
||||||
|
|
||||||
|
typedef struct WaitEvent
|
||||||
|
{
|
||||||
|
int pos; /* position in the event data structure */
|
||||||
|
uint32 events; /* triggered events */
|
||||||
|
pgsocket fd; /* socket fd associated with event */
|
||||||
|
void *user_data; /* pointer provided in AddWaitEventToSet */
|
||||||
|
#ifdef WIN32
|
||||||
|
bool reset; /* Is reset of the event required? */
|
||||||
|
#endif
|
||||||
|
} WaitEvent;
|
||||||
|
|
||||||
|
/* forward declarations to avoid exposing waiteventset.c implementation details */
|
||||||
|
typedef struct WaitEventSet WaitEventSet;
|
||||||
|
|
||||||
|
typedef struct Latch Latch;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prototypes for functions in waiteventset.c
|
||||||
|
*/
|
||||||
|
extern void InitializeWaitEventSupport(void);
|
||||||
|
|
||||||
|
extern WaitEventSet *CreateWaitEventSet(ResourceOwner resowner, int nevents);
|
||||||
|
extern void FreeWaitEventSet(WaitEventSet *set);
|
||||||
|
extern void FreeWaitEventSetAfterFork(WaitEventSet *set);
|
||||||
|
extern int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd,
|
||||||
|
Latch *latch, void *user_data);
|
||||||
|
extern void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch);
|
||||||
|
extern int WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||||
|
WaitEvent *occurred_events, int nevents,
|
||||||
|
uint32 wait_event_info);
|
||||||
|
extern int GetNumRegisteredWaitEvents(WaitEventSet *set);
|
||||||
|
extern bool WaitEventSetCanReportClosed(void);
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
extern void WakeupMyProc(void);
|
||||||
|
extern void WakeupOtherProc(int pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WAITEVENTSET_H */
|
Reference in New Issue
Block a user