Micro optimize LWLockAttemptLock() a bit.

Andres Freund <andres@anarazel.de>

Commit: a4b09af3e93707351f1d4b8efafabfa135c0f70b
Author: Andres Freund <andres@anarazel.de>
Date: 2015-08-02T16:41:23Z
Releases: 9.6.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