Skip to content
6 changes: 5 additions & 1 deletion libcxx/include/__atomic/atomic_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ struct __atomic_ref_base {

friend struct __atomic_waitable_traits<__atomic_ref_base<_Tp>>;

// require types that are 1, 2, 4, 8, or 16 bytes in length to be aligned to at least their size to allow them to be
// used lock-free
static constexpr bool __min_alignement = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || (sizeof(_Tp) > 16) ? 0 : sizeof(_Tp);

public:
using value_type = _Tp;

static constexpr size_t required_alignment = alignof(_Tp);
static constexpr size_t required_alignment = alignof(_Tp) > __min_alignement ? alignof(_Tp) : __min_alignement;

// The __atomic_always_lock_free builtin takes into account the alignment of the pointer if provided,
// so we create a fake pointer with a suitable alignment when querying it. Note that we are guaranteed
Expand Down