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<size_t S>
    static inline bool atomic_is_lock_free(volatile void* ptr = nullptr)
    {
        return __atomic_is_lock_free(S, ptr);
    }
This commit is contained in:
Timothy Flynn 2021-07-12 11:46:05 -04:00 committed by Linus Groh
parent 33eb830929
commit d9c2447999
Notes: sideshowbarker 2024-07-18 09:01:06 +09:00

View file

@ -133,6 +133,12 @@ static inline void atomic_store(volatile T** var, std::nullptr_t, MemoryOrder or
__atomic_store_n(const_cast<V**>(var), nullptr, order);
}
template<typename T>
static inline bool atomic_is_lock_free(volatile T* ptr = nullptr) noexcept
{
return __atomic_is_lock_free(sizeof(T), ptr);
}
template<typename T, MemoryOrder DefaultMemoryOrder = AK::MemoryOrder::memory_order_seq_cst>
class Atomic {
T m_value { 0 };