Use ModifyWaitEvent to update exit_on_postmaster_death
This is in preparation for splitting WaitEventSet related functions to a separate source file. That will hide the details of WaitEventSet from WaitLatch, so it must use an exposed function instead of modifying WaitEventSet->exit_on_postmaster_death directly. 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:
parent
9f25b9f739
commit
84e5b2f07a
@ -154,8 +154,9 @@ struct WaitEventSet
|
|||||||
/* A common WaitEventSet used to implement WaitLatch() */
|
/* A common WaitEventSet used to implement WaitLatch() */
|
||||||
static WaitEventSet *LatchWaitSet;
|
static WaitEventSet *LatchWaitSet;
|
||||||
|
|
||||||
/* The position of the latch in LatchWaitSet. */
|
/* The positions of the latch and PM death events in LatchWaitSet */
|
||||||
#define LatchWaitSetLatchPos 0
|
#define LatchWaitSetLatchPos 0
|
||||||
|
#define LatchWaitSetPostmasterDeathPos 1
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
/* Are we currently in WaitLatch? The signal handler would like to know. */
|
/* Are we currently in WaitLatch? The signal handler would like to know. */
|
||||||
@ -353,11 +354,18 @@ InitializeLatchWaitSet(void)
|
|||||||
LatchWaitSet = CreateWaitEventSet(NULL, 2);
|
LatchWaitSet = CreateWaitEventSet(NULL, 2);
|
||||||
latch_pos = AddWaitEventToSet(LatchWaitSet, WL_LATCH_SET, PGINVALID_SOCKET,
|
latch_pos = AddWaitEventToSet(LatchWaitSet, WL_LATCH_SET, PGINVALID_SOCKET,
|
||||||
MyLatch, NULL);
|
MyLatch, NULL);
|
||||||
if (IsUnderPostmaster)
|
|
||||||
AddWaitEventToSet(LatchWaitSet, WL_EXIT_ON_PM_DEATH,
|
|
||||||
PGINVALID_SOCKET, NULL, NULL);
|
|
||||||
|
|
||||||
Assert(latch_pos == LatchWaitSetLatchPos);
|
Assert(latch_pos == LatchWaitSetLatchPos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WaitLatch will modify this to WL_EXIT_ON_PM_DEATH or
|
||||||
|
* WL_POSTMASTER_DEATH on each call.
|
||||||
|
*/
|
||||||
|
if (IsUnderPostmaster)
|
||||||
|
{
|
||||||
|
latch_pos = AddWaitEventToSet(LatchWaitSet, WL_EXIT_ON_PM_DEATH,
|
||||||
|
PGINVALID_SOCKET, NULL, NULL);
|
||||||
|
Assert(latch_pos == LatchWaitSetPostmasterDeathPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -505,8 +513,9 @@ WaitLatch(Latch *latch, int wakeEvents, long timeout,
|
|||||||
if (!(wakeEvents & WL_LATCH_SET))
|
if (!(wakeEvents & WL_LATCH_SET))
|
||||||
latch = NULL;
|
latch = NULL;
|
||||||
ModifyWaitEvent(LatchWaitSet, LatchWaitSetLatchPos, WL_LATCH_SET, latch);
|
ModifyWaitEvent(LatchWaitSet, LatchWaitSetLatchPos, WL_LATCH_SET, latch);
|
||||||
LatchWaitSet->exit_on_postmaster_death =
|
ModifyWaitEvent(LatchWaitSet, LatchWaitSetPostmasterDeathPos,
|
||||||
((wakeEvents & WL_EXIT_ON_PM_DEATH) != 0);
|
(wakeEvents & (WL_EXIT_ON_PM_DEATH | WL_POSTMASTER_DEATH)),
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (WaitEventSetWait(LatchWaitSet,
|
if (WaitEventSetWait(LatchWaitSet,
|
||||||
(wakeEvents & WL_TIMEOUT) ? timeout : -1,
|
(wakeEvents & WL_TIMEOUT) ? timeout : -1,
|
||||||
@ -1027,6 +1036,21 @@ ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
|
|||||||
old_events = event->events;
|
old_events = event->events;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allow switching between WL_POSTMASTER_DEATH and WL_EXIT_ON_PM_DEATH.
|
||||||
|
*
|
||||||
|
* Note that because WL_EXIT_ON_PM_DEATH is mapped to WL_POSTMASTER_DEATH
|
||||||
|
* in AddWaitEventToSet(), this needs to be checked before the fast-path
|
||||||
|
* below that checks if 'events' has changed.
|
||||||
|
*/
|
||||||
|
if (event->events == WL_POSTMASTER_DEATH)
|
||||||
|
{
|
||||||
|
if (events != WL_POSTMASTER_DEATH && events != WL_EXIT_ON_PM_DEATH)
|
||||||
|
elog(ERROR, "cannot remove postmaster death event");
|
||||||
|
set->exit_on_postmaster_death = ((events & WL_EXIT_ON_PM_DEATH) != 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If neither the event mask nor the associated latch changes, return
|
* If neither the event mask nor the associated latch changes, return
|
||||||
* early. That's an important optimization for some sockets, where
|
* early. That's an important optimization for some sockets, where
|
||||||
@ -1037,16 +1061,8 @@ ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
|
|||||||
(!(event->events & WL_LATCH_SET) || set->latch == latch))
|
(!(event->events & WL_LATCH_SET) || set->latch == latch))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event->events & WL_LATCH_SET &&
|
if (event->events & WL_LATCH_SET && events != event->events)
|
||||||
events != event->events)
|
|
||||||
{
|
|
||||||
elog(ERROR, "cannot modify latch event");
|
elog(ERROR, "cannot modify latch event");
|
||||||
}
|
|
||||||
|
|
||||||
if (event->events & WL_POSTMASTER_DEATH)
|
|
||||||
{
|
|
||||||
elog(ERROR, "cannot modify postmaster death event");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: validate event mask */
|
/* FIXME: validate event mask */
|
||||||
event->events = events;
|
event->events = events;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user