ProcArrayGroupClearXid() compare-exchange style

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: amit(dot)kapila16(at)gmail(dot)com
Subject: ProcArrayGroupClearXid() compare-exchange style
Date: 2019-10-15 03:53:48
Message-ID: 20191015035348.GA4166224@rfd.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Attachment Content-Type Size
compare-exchange-style-v1.patch text/plain 918 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2019-10-15 04:39:16 Re: Collation versioning
Previous Message Thomas Munro 2019-10-15 01:39:16 Re: "pg_ctl: the PID file ... is empty" at end of make check