Use standard compare_exchange loop style in ProcArrayGroupClearXid().
authorNoah Misch <noah@leadboat.com>
Sat, 19 Oct 2019 03:21:10 +0000 (20:21 -0700)
committerNoah Misch <noah@leadboat.com>
Sat, 19 Oct 2019 03:21:10 +0000 (20:21 -0700)
Besides style, this might improve performance in the contended case.

Reviewed by Amit Kapila.

Discussion: https://postgr.es/m/20191015035348.GA4166224@rfd.leadboat.com

src/backend/storage/ipc/procarray.c

index 8abcfdf841fba64fbfca9560f6698664f7ec7d37..3da53074b18412a40b385338ef0bbbd6dce785f1 100644 (file)
@@ -493,9 +493,9 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
    /* Add ourselves to the list of processes needing a group XID clear. */
    proc->procArrayGroupMember = true;
    proc->procArrayGroupMemberXid = latestXid;
+   nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
    while (true)
    {
-       nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
        pg_atomic_write_u32(&proc->procArrayGroupNext, nextidx);
 
        if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,