Skip to content

Commit 47c7187

Browse files
committed
Avoid need for valgrind suppressions for pg_atomic_init_u64 on some platforms.
Previously we used pg_atomic_write_64_impl inside pg_atomic_init_u64. That works correctly, but on platforms without 64bit single copy atomicity it could trigger spurious valgrind errors about uninitialized memory, because we use compare_and_swap for atomic writes on such platforms. I previously suppressed one instance of this problem (6c878ed), but as Tom reports that wasn't enough. As the atomic variable cannot yet be concurrently accessible during initialization, it seems better to have pg_atomic_init_64_impl set the value directly. Change pg_atomic_init_u32_impl for symmetry. Reported-By: Tom Lane Author: Andres Freund Discussion: https://postgr.es/m/[email protected] Backpatch: 9.5-
1 parent c2e71cb commit 47c7187

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

src/include/port/atomics/generic.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
160160
static inline void
161161
pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
162162
{
163-
pg_atomic_write_u32_impl(ptr, val_);
163+
ptr->value = val_;
164164
}
165165
#endif
166166

@@ -330,7 +330,7 @@ pg_atomic_read_u64_impl(volatile pg_atomic_uint64 *ptr)
330330
static inline void
331331
pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
332332
{
333-
pg_atomic_write_u64_impl(ptr, val_);
333+
ptr->value = val_;
334334
}
335335
#endif
336336

src/tools/valgrind.supp

-14
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,6 @@
134134
fun:IsBinaryCoercible
135135
}
136136

137-
# Atomic writes to 64bit atomic vars uses compare/exchange to
138-
# guarantee atomic writes of 64bit variables. pg_atomic_write is used
139-
# during initialization of the atomic variable; that leads to an
140-
# initial read of the old, undefined, memory value. But that's just to
141-
# make sure the swap works correctly.
142-
{
143-
uninitialized_atomic_init_u64
144-
Memcheck:Cond
145-
fun:pg_atomic_exchange_u64_impl
146-
fun:pg_atomic_write_u64_impl
147-
fun:pg_atomic_init_u64_impl
148-
}
149-
150-
151137
# Python's allocator does some low-level tricks for efficiency. Those
152138
# can be disabled for better instrumentation; but few people testing
153139
# postgres will have such a build of python. So add broad

0 commit comments

Comments
 (0)