From: Andres Freund Date: Tue, 9 Dec 2025 04:03:54 +0000 (-0500) Subject: Improve documentation for pg_atomic_unlocked_write_u32() X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=aa749bde323364039f369784071f315ad53c1325;p=postgresql.git Improve documentation for pg_atomic_unlocked_write_u32() After my recent commit 7902a47c20b, Nathan noticed that pg_atomic_unlocked_write_u64() was not accurately described by the comments for the 32bit version. Turns out the 32bit version has suffered from copy-and-paste-itis since its introduction. Fix. Reported-by: Nathan Bossart Reviewed-by: Tom Lane Reviewed-by: Nathan Bossart Discussion: https://postgr.es/m/aTGt7q4Jvn97uGAx@nathan --- diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h index 830ea5c7c52..babe4ebc4e8 100644 --- a/src/include/port/atomics.h +++ b/src/include/port/atomics.h @@ -281,11 +281,13 @@ pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val) /* * pg_atomic_unlocked_write_u32 - unlocked write to atomic variable. * - * The write is guaranteed to succeed as a whole, i.e. it's not possible to - * observe a partial write for any reader. But note that writing this way is - * not guaranteed to correctly interact with read-modify-write operations like - * pg_atomic_compare_exchange_u32. This should only be used in cases where - * minor performance regressions due to atomics emulation are unacceptable. + * Write to an atomic variable, without atomicity guarantees. I.e. it is not + * guaranteed that a concurrent reader will not see a torn value, nor is this + * guaranteed to correctly interact with concurrent read-modify-write + * operations like pg_atomic_compare_exchange_u32. This should only be used + * in cases where minor performance regressions due to atomic operations are + * unacceptable and where exclusive access is guaranteed via some external + * means. * * No barrier semantics. */