Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e2d394d

Browse filesBrowse files
committed
Use WaitLatch() for condition variables.
Previously, condition_variable.c created a long lived WaitEventSet to avoid extra system calls. WaitLatch() now uses something similar internally, so there is no point in wasting an extra kernel descriptor. Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGJAC4Oqao%3DqforhNey20J8CiG2R%3DoBPqvfR0vOJrFysGw%40mail.gmail.com
1 parent 3347c98 commit e2d394d
Copy full SHA for e2d394d

File tree

Expand file treeCollapse file tree

1 file changed

+5
-23
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-23
lines changed

‎src/backend/storage/lmgr/condition_variable.c

Copy file name to clipboardExpand all lines: src/backend/storage/lmgr/condition_variable.c
+5-23Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
/* Initially, we are not prepared to sleep on any condition variable. */
3131
static ConditionVariable *cv_sleep_target = NULL;
3232

33-
/* Reusable WaitEventSet. */
34-
static WaitEventSet *cv_wait_event_set = NULL;
35-
3633
/*
3734
* Initialize a condition variable.
3835
*/
@@ -62,23 +59,6 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv)
6259
{
6360
int pgprocno = MyProc->pgprocno;
6461

65-
/*
66-
* If first time through in this process, create a WaitEventSet, which
67-
* we'll reuse for all condition variable sleeps.
68-
*/
69-
if (cv_wait_event_set == NULL)
70-
{
71-
WaitEventSet *new_event_set;
72-
73-
new_event_set = CreateWaitEventSet(TopMemoryContext, 2);
74-
AddWaitEventToSet(new_event_set, WL_LATCH_SET, PGINVALID_SOCKET,
75-
MyLatch, NULL);
76-
AddWaitEventToSet(new_event_set, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET,
77-
NULL, NULL);
78-
/* Don't set cv_wait_event_set until we have a correct WES. */
79-
cv_wait_event_set = new_event_set;
80-
}
81-
8262
/*
8363
* If some other sleep is already prepared, cancel it; this is necessary
8464
* because we have just one static variable tracking the prepared sleep,
@@ -135,6 +115,7 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
135115
long cur_timeout = -1;
136116
instr_time start_time;
137117
instr_time cur_time;
118+
int wait_events;
138119

139120
/*
140121
* If the caller didn't prepare to sleep explicitly, then do so now and
@@ -166,19 +147,20 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
166147
INSTR_TIME_SET_CURRENT(start_time);
167148
Assert(timeout >= 0 && timeout <= INT_MAX);
168149
cur_timeout = timeout;
150+
wait_events = WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH;
169151
}
152+
else
153+
wait_events = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH;
170154

171155
while (true)
172156
{
173-
WaitEvent event;
174157
bool done = false;
175158

176159
/*
177160
* Wait for latch to be set. (If we're awakened for some other
178161
* reason, the code below will cope anyway.)
179162
*/
180-
(void) WaitEventSetWait(cv_wait_event_set, cur_timeout, &event, 1,
181-
wait_event_info);
163+
(void) WaitLatch(MyLatch, wait_events, cur_timeout, wait_event_info);
182164

183165
/* Reset latch before examining the state of the wait list. */
184166
ResetLatch(MyLatch);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.