提交 d699ba41 编写于 作者: H Heikki Linnakangas

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.
上级 6c2744f1
...@@ -1842,15 +1842,14 @@ WakeupWaiters(XLogRecPtr EndPos) ...@@ -1842,15 +1842,14 @@ WakeupWaiters(XLogRecPtr EndPos)
slot->xlogInsertingAt = EndPos; slot->xlogInsertingAt = EndPos;
/* /*
* See if there are any waiters that need to be woken up. * See if there are any LW_WAIT_UNTIL_FREE waiters that need to be woken
* up. They are always in the front of the queue.
*/ */
head = slot->head; head = slot->head;
if (head != NULL) if (head != NULL && head->lwWaitMode == LW_WAIT_UNTIL_FREE)
{ {
proc = head; proc = head;
/* LW_WAIT_UNTIL_FREE waiters are always in the front of the queue */
next = proc->lwWaitLink; next = proc->lwWaitLink;
while (next && next->lwWaitMode == LW_WAIT_UNTIL_FREE) while (next && next->lwWaitMode == LW_WAIT_UNTIL_FREE)
{ {
...@@ -1862,6 +1861,8 @@ WakeupWaiters(XLogRecPtr EndPos) ...@@ -1862,6 +1861,8 @@ WakeupWaiters(XLogRecPtr EndPos)
slot->head = next; slot->head = next;
proc->lwWaitLink = NULL; proc->lwWaitLink = NULL;
} }
else
head = NULL;
/* We are done updating shared state of the lock itself. */ /* We are done updating shared state of the lock itself. */
SpinLockRelease(&slot->mutex); SpinLockRelease(&slot->mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册