Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d699ba4

Browse files
committed
Fix WakeupWaiters() to not wake up an exclusive locker unnecessarily.
WakeupWaiters() is supposed to wake up all LW_WAIT_UNTIL_FREE waiters of the slot, but the loop incorrectly also woke up the first LW_EXCLUSIVE waiter, if there was no LW_WAIT_UNTIL_FREE waiters in the queue. Noted by Andres Freund. This code is new in 9.4, so no backpatching.
1 parent 6c2744f commit d699ba4

File tree

1 file changed

+5
-4
lines changed
  • src/backend/access/transam

1 file changed

+5
-4
lines changed

src/backend/access/transam/xlog.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -1842,15 +1842,14 @@ WakeupWaiters(XLogRecPtr EndPos)
18421842
slot->xlogInsertingAt = EndPos;
18431843

18441844
/*
1845-
* See if there are any waiters that need to be woken up.
1845+
* See if there are any LW_WAIT_UNTIL_FREE waiters that need to be woken
1846+
* up. They are always in the front of the queue.
18461847
*/
18471848
head = slot->head;
18481849

1849-
if (head != NULL)
1850+
if (head != NULL && head->lwWaitMode == LW_WAIT_UNTIL_FREE)
18501851
{
18511852
proc = head;
1852-
1853-
/* LW_WAIT_UNTIL_FREE waiters are always in the front of the queue */
18541853
next = proc->lwWaitLink;
18551854
while (next && next->lwWaitMode == LW_WAIT_UNTIL_FREE)
18561855
{
@@ -1862,6 +1861,8 @@ WakeupWaiters(XLogRecPtr EndPos)
18621861
slot->head = next;
18631862
proc->lwWaitLink = NULL;
18641863
}
1864+
else
1865+
head = NULL;
18651866

18661867
/* We are done updating shared state of the lock itself. */
18671868
SpinLockRelease(&slot->mutex);

0 commit comments

Comments
 (0)