pg_atomic_exchange_u32() in ProcArrayGroupClearXid()
Alexander Korotkov <a.korotkov@postgrespro.ru>
From: Alexander Korotkov <a.korotkov@postgrespro.ru>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2018-09-21T17:35:28Z
Lists: pgsql-hackers
Hi!
While investigating ProcArrayGroupClearXid() code I wonder why do we have
this loop instead of plain pg_atomic_exchange_u32() call? Is it
intentional?
/*
* Now that we've got the lock, clear the list of processes waiting for
* 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;
}
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Replace CAS loop with single TAS in ProcArrayGroupClearXid()
- 2f39106a209e 12.0 landed