diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-02-10 15:14:07 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-02-10 15:18:18 +0200 |
commit | d699ba41349e4ef397222a7223606fa03f4c4870 (patch) | |
tree | 58a2754ed9160f942897c1ccb7159b7f4935e484 | |
parent | 6c2744f1d3a0d2e456f8d52776c976da3eb8d3a0 (diff) | |
download | postgresql-d699ba41349e4ef397222a7223606fa03f4c4870.tar.gz postgresql-d699ba41349e4ef397222a7223606fa03f4c4870.zip |
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.
-rw-r--r-- | src/backend/access/transam/xlog.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7f63185b1cc..508970a751d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1842,15 +1842,14 @@ WakeupWaiters(XLogRecPtr 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; - if (head != NULL) + if (head != NULL && head->lwWaitMode == LW_WAIT_UNTIL_FREE) { proc = head; - - /* LW_WAIT_UNTIL_FREE waiters are always in the front of the queue */ next = proc->lwWaitLink; while (next && next->lwWaitMode == LW_WAIT_UNTIL_FREE) { @@ -1862,6 +1861,8 @@ WakeupWaiters(XLogRecPtr EndPos) slot->head = next; proc->lwWaitLink = NULL; } + else + head = NULL; /* We are done updating shared state of the lock itself. */ SpinLockRelease(&slot->mutex); |