postgresql/src/include/port/atomics
Nathan Bossart bd5132db55 Introduce atomic read/write functions with full barrier semantics.
Writing correct code using atomic variables is often difficult due
to the memory barrier semantics (or lack thereof) of the underlying
operations.  This commit introduces atomic read/write functions
with full barrier semantics to ease this cognitive load.  For
example, some spinlocks protect a single value, and these new
functions make it easy to convert the value to an atomic variable
(thus eliminating the need for the spinlock) without modifying the
barrier semantics previously provided by the spinlock.  Since these
functions may be less performant than the other atomic reads and
writes, they are not suitable for every use-case.  However, using a
single atomic operation with full barrier semantics may be more
performant in cases where a separate explicit barrier would
otherwise be required.

The base implementations for these new functions are atomic
exchanges (for writes) and atomic fetch/adds with 0 (for reads).
These implementations can be overwritten with better architecture-
specific versions as they are discovered.

This commit leaves converting existing code to use these new
functions as a future exercise.

Reviewed-by: Andres Freund, Yong Li, Jeff Davis
Discussion: https://postgr.es/m/20231110205128.GB1315705%40nathanxps13
2024-02-29 10:00:44 -06:00
..
arch-arm.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
arch-hppa.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
arch-ppc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
arch-x86.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
fallback.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
generic-gcc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
generic-msvc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
generic-sunpro.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
generic.h Introduce atomic read/write functions with full barrier semantics. 2024-02-29 10:00:44 -06:00