Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5ffb7c7

Browse files
committed
De-pessimize ConditionVariableCancelSleep().
Commitb91dd9d was concerned with a theoretical problem with ournon-atomic condition variable operations. If you stop sleeping, andthen cancel the sleep in a separate step, you might be signaled inbetween, and that could be lost. That doesn't matter for callers ofConditionVariableBroadcast(), but callers of ConditionVariableSignal()might be upset if a signal went missing like this.Commitbc971f4 interacted badly with that logic, because it doesn'tuse ConditionVariableSleep(), which would normally put us back in thewait list. ConditionVariableCancelSleep() would be confused and thinkwe'd received an extra signal, and try to forward it to another backend,resulting in wakeup storms.New idea: ConditionVariableCancelSleep() can just return true if we'vebeen signaled. Hypothetical users of ConditionVariableSignal() wouldthen still have a way to deal with rare lost signals if they areconcerned about that problem.Back-patch to 16, wherebc971f4 arrived.Reported-by: Tomas Vondra <tomas.vondra@enterprisedb.com>Reviewed-by: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/2840876b-4cfe-240f-0a7e-29ffd66711e7%40enterprisedb.com
1 parent82a4eda commit5ffb7c7

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,17 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
223223
*
224224
* Do nothing if nothing is pending; this allows this function to be called
225225
* during transaction abort to clean up any unfinished CV sleep.
226+
*
227+
* Return true if we've been signaled.
226228
*/
227-
void
229+
bool
228230
ConditionVariableCancelSleep(void)
229231
{
230232
ConditionVariable*cv=cv_sleep_target;
231233
boolsignaled= false;
232234

233235
if (cv==NULL)
234-
return;
236+
return false;
235237

236238
SpinLockAcquire(&cv->mutex);
237239
if (proclist_contains(&cv->wakeup,MyProc->pgprocno,cvWaitLink))
@@ -240,15 +242,9 @@ ConditionVariableCancelSleep(void)
240242
signaled= true;
241243
SpinLockRelease(&cv->mutex);
242244

243-
/*
244-
* If we've received a signal, pass it on to another waiting process, if
245-
* there is one. Otherwise a call to ConditionVariableSignal() might get
246-
* lost, despite there being another process ready to handle it.
247-
*/
248-
if (signaled)
249-
ConditionVariableSignal(cv);
250-
251245
cv_sleep_target=NULL;
246+
247+
returnsignaled;
252248
}
253249

254250
/*

‎src/include/storage/condition_variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extern void ConditionVariableInit(ConditionVariable *cv);
5656
externvoidConditionVariableSleep(ConditionVariable*cv,uint32wait_event_info);
5757
externboolConditionVariableTimedSleep(ConditionVariable*cv,longtimeout,
5858
uint32wait_event_info);
59-
externvoidConditionVariableCancelSleep(void);
59+
externboolConditionVariableCancelSleep(void);
6060

6161
/*
6262
* Optionally, ConditionVariablePrepareToSleep can be called before entering

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp