Commit 3f3d60d3 authored by Robert Haas's avatar Robert Haas

Fix race condition in ConditionVariablePrepareToSleep.

Thomas Munro
parent fc8219dc
...@@ -71,14 +71,17 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv) ...@@ -71,14 +71,17 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv)
&MyProc->procLatch, NULL); &MyProc->procLatch, NULL);
} }
/*
* Reset my latch before adding myself to the queue and before entering
* the caller's predicate loop.
*/
ResetLatch(&MyProc->procLatch);
/* Add myself to the wait queue. */ /* Add myself to the wait queue. */
SpinLockAcquire(&cv->mutex); SpinLockAcquire(&cv->mutex);
if (!proclist_contains(&cv->wakeup, pgprocno, cvWaitLink)) if (!proclist_contains(&cv->wakeup, pgprocno, cvWaitLink))
proclist_push_tail(&cv->wakeup, pgprocno, cvWaitLink); proclist_push_tail(&cv->wakeup, pgprocno, cvWaitLink);
SpinLockRelease(&cv->mutex); SpinLockRelease(&cv->mutex);
/* Reset my latch before entering the caller's predicate loop. */
ResetLatch(&MyProc->procLatch);
} }
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment