LWLockAcquireWithVar needs to set the protected variable while holding
the spinlock. Need to use a volatile pointer to make sure it doesn't get
reordered by the compiler. The other functions that accessed the protected
variable already got this right.
9.4 only. Earlier releases didn't have this code, and in master, spinlock
release acts as a compiler barrier.
LWLockAcquireCommon(LWLock *l, LWLockMode mode, uint64 *valptr, uint64 val)
{
volatile LWLock *lock = l;
+ volatile uint64 *valp = valptr;
PGPROC *proc = MyProc;
bool retry = false;
bool result = true;
}
/* If there's a variable associated with this lock, initialize it */
- if (valptr)
- *valptr = val;
+ if (valp)
+ *valp = val;
/* We are done updating shared state of the lock itself. */
SpinLockRelease(&lock->mutex);