aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/condition_variable.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2019-07-13 13:55:10 +1200
committerThomas Munro <tmunro@postgresql.org>2019-07-13 14:50:18 +1200
commitb91dd9de5ea0839d0d248ebbe8cb926c3df52c7c (patch)
tree19da475a11d2fae877149ea88a686b334e012f29 /src/backend/storage/lmgr/condition_variable.c
parent1321509fa43293615c4e5fa5dc8eed5286f479b1 (diff)
downloadpostgresql-b91dd9de5ea0839d0d248ebbe8cb926c3df52c7c.tar.gz
postgresql-b91dd9de5ea0839d0d248ebbe8cb926c3df52c7c.zip
Forward received condition variable signals on cancel.
After a process decides not to wait for a condition variable, it can still consume a signal before it reaches ConditionVariableCancelSleep(). In that case, pass the signal on to another waiter if possible, so that a signal doesn't go missing when there is another process ready to receive it. Author: Thomas Munro Reviewed-by: Shawn Debnath Discussion: https://postgr.es/m/CA%2BhUKGLQ_RW%2BXs8znDn36e-%2Bmq2--zrPemBqTQ8eKT-VO1OF4Q%40mail.gmail.com
Diffstat (limited to 'src/backend/storage/lmgr/condition_variable.c')
-rw-r--r--src/backend/storage/lmgr/condition_variable.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/storage/lmgr/condition_variable.c b/src/backend/storage/lmgr/condition_variable.c
index bc8607efe45..e08507f0cc5 100644
--- a/src/backend/storage/lmgr/condition_variable.c
+++ b/src/backend/storage/lmgr/condition_variable.c
@@ -245,6 +245,7 @@ void
ConditionVariableCancelSleep(void)
{
ConditionVariable *cv = cv_sleep_target;
+ bool signaled = false;
if (cv == NULL)
return;
@@ -252,8 +253,18 @@ ConditionVariableCancelSleep(void)
SpinLockAcquire(&cv->mutex);
if (proclist_contains(&cv->wakeup, MyProc->pgprocno, cvWaitLink))
proclist_delete(&cv->wakeup, MyProc->pgprocno, cvWaitLink);
+ else
+ signaled = true;
SpinLockRelease(&cv->mutex);
+ /*
+ * If we've received a signal, pass it on to another waiting process, if
+ * there is one. Otherwise a call to ConditionVariableSignal() might get
+ * lost, despite there being another process ready to handle it.
+ */
+ if (signaled)
+ ConditionVariableSignal(cv);
+
cv_sleep_target = NULL;
}