Thread: pgsql: Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64.
Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64. Presently, all platforms implement atomic exchanges by performing an atomic compare-and-swap in a loop until it succeeds. This can be especially expensive when there is contention on the atomic variable. This commit optimizes atomic exchanges on many platforms by using compiler intrinsics, which should compile into something much less expensive than a compare-and-swap loop. Since these intrinsics have been available for some time, the inline assembly implementations are omitted. Suggested-by: Andres Freund Reviewed-by: Andres Freund Discussion: https://postgr.es/m/20231129212905.GA1258737%40nathanxps13 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/64b1fb5f03266f0ef4eef3ad2b7d97170bb05b78 Modified Files -------------- src/include/port/atomics/generic-gcc.h | 34 +++++++++++++++++++++++++++++++ src/include/port/atomics/generic-msvc.h | 18 ++++++++++++++++ src/include/port/atomics/generic-sunpro.h | 14 +++++++++++++ 3 files changed, 66 insertions(+)