From: Andres Freund Date: Thu, 31 Dec 2020 04:42:08 +0000 (-0800) Subject: condition variable: add ConditionVariableCancelSleepEx(). X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=87003acd0bc7664dc74c1aebe7c0e5d4ec8a06a4;p=users%2Fandresfreund%2Fpostgres.git condition variable: add ConditionVariableCancelSleepEx(). Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- diff --git a/src/backend/storage/lmgr/condition_variable.c b/src/backend/storage/lmgr/condition_variable.c index 0a61ff0031..77f8d4b907 100644 --- a/src/backend/storage/lmgr/condition_variable.c +++ b/src/backend/storage/lmgr/condition_variable.c @@ -218,7 +218,7 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, * during transaction abort to clean up any unfinished CV sleep. */ void -ConditionVariableCancelSleep(void) +ConditionVariableCancelSleepEx(bool only_broadcasts) { ConditionVariable *cv = cv_sleep_target; bool signaled = false; @@ -238,12 +238,18 @@ ConditionVariableCancelSleep(void) * there is one. Otherwise a call to ConditionVariableSignal() might get * lost, despite there being another process ready to handle it. */ - if (signaled) + if (signaled && !only_broadcasts) ConditionVariableSignal(cv); cv_sleep_target = NULL; } +void +ConditionVariableCancelSleep(void) +{ + ConditionVariableCancelSleepEx(false); +} + /* * Wake up the oldest process sleeping on the CV, if there is any. * diff --git a/src/include/storage/condition_variable.h b/src/include/storage/condition_variable.h index 4cba0eccff..dbfe68238b 100644 --- a/src/include/storage/condition_variable.h +++ b/src/include/storage/condition_variable.h @@ -57,6 +57,7 @@ extern void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info extern bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info); extern void ConditionVariableCancelSleep(void); +extern void ConditionVariableCancelSleepEx(bool only_broadcasts); /* * Optionally, ConditionVariablePrepareToSleep can be called before entering