Micro optimize LWLockAttemptLock() a bit.

Andres Freund <andres@anarazel.de>

Commit: 9074e41dbd41bc45ef79aeac1b6496bf087509a7
Author: Andres Freund <andres@anarazel.de>
Date: 2015-08-02T16:41:41Z
Releases: 9.5.0
Micro optimize LWLockAttemptLock() a bit.

LWLockAttemptLock pointlessly read the lock's state in every loop
iteration, even though pg_atomic_compare_exchange_u32() returns the old
value. Instead do that only once before the loop iteration.

Additionally there's no need to have the expected_state variable,
old_state mostly had the same value anyway.

Noticed-By: Heikki Linnakangas
Backpatch: 9.5, no reason to let the branches diverge at this point

Files

PathChange+/−
src/backend/storage/lmgr/lwlock.c modified +12 −8