]> granicus.if.org Git - postgresql/commitdiff
Replace CAS loop with single TAS in ProcArrayGroupClearXid()
authorAlexander Korotkov <akorotkov@postgresql.org>
Sat, 22 Sep 2018 13:22:30 +0000 (16:22 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Sat, 22 Sep 2018 13:22:30 +0000 (16:22 +0300)
Single pg_atomic_exchange_u32() is expected to be faster than loop of
pg_atomic_compare_exchange_u32().  Also, it would be consistent with
clog group update code.

Discussion: https://postgr.es/m/CAPpHfdtxLsC-bqfxFcHswZ91OxXcZVNDBBVfg9tAWU0jvn1tQA%40mail.gmail.com
Reviewed-by: Amit Kapila
src/backend/storage/ipc/procarray.c

index bd20497d81aecfdac83f99757ef5a4faf605c178..bf2f4dbed2d373a542cc3c164e5ec03992351f2e 100644 (file)
@@ -542,14 +542,8 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
         * group XID clearing, saving a pointer to the head of the list.  Trying
         * to pop elements one at a time could lead to an ABA problem.
         */
-       while (true)
-       {
-               nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
-               if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
-                                                                                  &nextidx,
-                                                                                  INVALID_PGPROCNO))
-                       break;
-       }
+       nextidx = pg_atomic_exchange_u32(&procglobal->procArrayGroupFirst,
+                                                                        INVALID_PGPROCNO);
 
        /* Remember head of list so we can perform wakeups after dropping lock. */
        wakeidx = nextidx;