From d9c2447999a7d61cf60e0012606702c9225715f7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 12 Jul 2021 11:46:05 -0400 Subject: [PATCH] AK: Add free function to wrap around __atomic_is_lock_free built-in Note: this exact implementation is needed for __atomic_is_lock_free to link with both GCC (for the SerenityOS build) and Clang (for the Fuzzer build). The size argument must be a compile-time constant, otherwise it fails to link with both compilers. Alternatively, the following definition links with GCC but fails with Clang: template static inline bool atomic_is_lock_free(volatile void* ptr = nullptr) { return __atomic_is_lock_free(S, ptr); } --- AK/Atomic.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/Atomic.h b/AK/Atomic.h index 61a8e41385..ec7191250a 100644 --- a/AK/Atomic.h +++ b/AK/Atomic.h @@ -133,6 +133,12 @@ static inline void atomic_store(volatile T** var, std::nullptr_t, MemoryOrder or __atomic_store_n(const_cast(var), nullptr, order); } +template +static inline bool atomic_is_lock_free(volatile T* ptr = nullptr) noexcept +{ + return __atomic_is_lock_free(sizeof(T), ptr); +} + template class Atomic { T m_value { 0 };