pgsql: Introduce atomic read/write functions with full barrier semantic

Поиск
Список
Период
Сортировка
От Nathan Bossart
Тема pgsql: Introduce atomic read/write functions with full barrier semantic
Дата
Msg-id E1rfitE-001Q2I-K6@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bd5132db558b6c8d11eb838be81e2177a95c7388

Modified Files
--------------
src/include/port/atomics.h         | 58 ++++++++++++++++++++++++++++++++++++++
src/include/port/atomics/generic.h | 36 +++++++++++++++++++++++
2 files changed, 94 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Dean Rasheed
Дата:
Сообщение: pgsql: Support MERGE into updatable views.
Следующее
От: Nathan Bossart
Дата:
Сообщение: pgsql: Convert archiver's force_dir_scan variable to an atomic variable