Skip to content

Commit f5a5773

Browse files
committed
Allow condition variables to be used in interrupt code.
Adjust the condition variable sleep loop to work correctly when code reached by its internal CHECK_FOR_INTERRUPTS() call interacts with another condition variable. There are no such cases currently, but a proposed patch would do this. Discussion: https://postgr.es/m/CA+hUKGLdemy2gBm80kz20GTe6hNVwoErE8KwcJk6-U56oStjtg@mail.gmail.com
1 parent 814f1d8 commit f5a5773

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/backend/storage/lmgr/condition_variable.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
165165
/* Reset latch before examining the state of the wait list. */
166166
ResetLatch(MyLatch);
167167

168-
CHECK_FOR_INTERRUPTS();
169-
170168
/*
171169
* If this process has been taken out of the wait list, then we know
172170
* that it has been signaled by ConditionVariableSignal (or
@@ -190,6 +188,15 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
190188
}
191189
SpinLockRelease(&cv->mutex);
192190

191+
/*
192+
* Check for interrupts, and return spuriously if that caused the
193+
* current sleep target to change (meaning that interrupt handler code
194+
* waited for a different condition variable).
195+
*/
196+
CHECK_FOR_INTERRUPTS();
197+
if (cv != cv_sleep_target)
198+
done = true;
199+
193200
/* We were signaled, so return */
194201
if (done)
195202
return false;

0 commit comments

Comments
 (0)