ProcArrayGroupClearXid() compare-exchange style
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: pgsql-hackers@postgresql.org
Cc: amit.kapila16@gmail.com
Date: 2019-10-15T03:53:48Z
Lists: pgsql-hackers
Attachments
- compare-exchange-style-v1.patch (text/plain) patch v1
ProcArrayGroupClearXid() has this:
while (true)
{
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
...
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
&nextidx,
(uint32) proc->pgprocno))
break;
}
This, from UnpinBuffer(), is our more-typical style:
old_buf_state = pg_atomic_read_u32(&buf->state);
for (;;)
{
...
if (pg_atomic_compare_exchange_u32(&buf->state, &old_buf_state,
buf_state))
break;
}
That is, we typically put the pg_atomic_read_u32() outside the loop. After
the first iteration, it is redundant with the side effect of
pg_atomic_compare_exchange_u32(). I haven't checked whether this materially
improves performance, but, for style, I would like to change it in HEAD.
Commits
-
Use standard compare_exchange loop style in ProcArrayGroupClearXid().
- 48cc59ed24f9 13.0 landed