2016-08-07 19:01:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/*
|
2018-09-02 17:22:35 +00:00
|
|
|
This header implements bs_t<> class for scoped enum types (enum class).
|
|
|
|
To enable bs_t<>, enum scope must contain `__bitset_enum_max` entry.
|
2016-08-07 19:01:27 +00:00
|
|
|
|
|
|
|
enum class flagzz : u32
|
|
|
|
{
|
|
|
|
flag1, // Bit indices start from zero
|
|
|
|
flag2,
|
|
|
|
|
|
|
|
__bitset_enum_max // It must be the last value
|
|
|
|
};
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
This also enables helper operators for this enum type.
|
2016-08-07 19:01:27 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
`+flagzz::flag1` - unary `+` operator convert flagzz value to bs_t<flagzz>
|
|
|
|
`flagzz::flag1 + flagzz::flag2` - bitset union
|
|
|
|
`flagzz::flag1 - flagzz::flag2` - bitset difference
|
|
|
|
Intersection (&) and symmetric difference (^) is also available.
|
|
|
|
*/
|
|
|
|
|
2020-12-12 12:01:29 +00:00
|
|
|
#include "util/types.hpp"
|
2019-07-26 22:34:10 +00:00
|
|
|
#include "util/atomic.hpp"
|
2020-12-22 11:05:05 +00:00
|
|
|
#include "Utilities/StrFmt.h"
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
template <typename T>
|
|
|
|
class atomic_bs_t;
|
|
|
|
|
|
|
|
// Bitset type for enum class with available bits [0, T::__bitset_enum_max)
|
|
|
|
template <typename T>
|
|
|
|
class bs_t final
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
public:
|
2016-08-07 19:01:27 +00:00
|
|
|
// Underlying type
|
|
|
|
using under = std::underlying_type_t<T>;
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
private:
|
|
|
|
// Underlying value
|
|
|
|
under m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
friend class atomic_bs_t<T>;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-04 10:31:18 +00:00
|
|
|
// Value constructor
|
|
|
|
constexpr explicit bs_t(int, under data)
|
|
|
|
: m_data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
public:
|
2020-12-18 07:39:54 +00:00
|
|
|
static constexpr usz bitmax = sizeof(T) * 8;
|
|
|
|
static constexpr usz bitsize = static_cast<under>(T::__bitset_enum_max);
|
2016-08-07 19:01:27 +00:00
|
|
|
|
|
|
|
static_assert(std::is_enum<T>::value, "bs_t<> error: invalid type (must be enum)");
|
2018-09-02 17:22:35 +00:00
|
|
|
static_assert(bitsize <= bitmax, "bs_t<> error: invalid __bitset_enum_max");
|
|
|
|
static_assert(bitsize != bitmax || std::is_unsigned<under>::value, "bs_t<> error: invalid __bitset_enum_max (sign bit)");
|
2016-08-07 19:01:27 +00:00
|
|
|
|
|
|
|
// Helper function
|
|
|
|
static constexpr under shift(T value)
|
|
|
|
{
|
|
|
|
return static_cast<under>(1) << static_cast<under>(value);
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t() = default;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Construct from a single bit
|
|
|
|
constexpr bs_t(T bit)
|
|
|
|
: m_data(shift(bit))
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Test for empty bitset
|
|
|
|
constexpr explicit operator bool() const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return m_data != 0;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Extract underlying data
|
|
|
|
constexpr explicit operator under() const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Copy
|
|
|
|
constexpr bs_t operator +() const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return *this;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t& operator +=(bs_t rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
m_data |= static_cast<under>(rhs);
|
|
|
|
return *this;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t& operator -=(bs_t rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
m_data &= ~static_cast<under>(rhs);
|
|
|
|
return *this;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t& operator &=(bs_t rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
m_data &= static_cast<under>(rhs);
|
|
|
|
return *this;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t& operator ^=(bs_t rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
m_data ^= static_cast<under>(rhs);
|
|
|
|
return *this;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t operator +(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, m_data | rhs.m_data);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t operator -(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, m_data & ~rhs.m_data);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t operator &(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, m_data & rhs.m_data);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bs_t operator ^(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, m_data ^ rhs.m_data);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool operator ==(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return m_data == rhs.m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool operator !=(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return m_data != rhs.m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool test(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return (m_data & rhs.m_data) != 0;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool test_and_set(T bit)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
bool r = (m_data & shift(bit)) != 0;
|
|
|
|
m_data |= shift(bit);
|
|
|
|
return r;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool test_and_reset(T bit)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
bool r = (m_data & shift(bit)) != 0;
|
|
|
|
m_data &= ~shift(bit);
|
|
|
|
return r;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
constexpr bool test_and_complement(T bit)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
bool r = (m_data & shift(bit)) != 0;
|
|
|
|
m_data ^= shift(bit);
|
|
|
|
return r;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unary '+' operator: promote plain enum value to bitset value
|
2018-09-02 17:22:35 +00:00
|
|
|
template <typename T, typename = decltype(T::__bitset_enum_max)>
|
|
|
|
constexpr bs_t<T> operator +(T bit)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return bit;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Binary '+' operator: bitset union
|
2018-09-02 17:22:35 +00:00
|
|
|
template <typename T, typename = decltype(T::__bitset_enum_max)>
|
2016-08-07 19:01:27 +00:00
|
|
|
constexpr bs_t<T> operator +(T lhs, T rhs)
|
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return bs_t<T>(lhs) + bs_t<T>(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Binary '-' operator: bitset difference
|
2018-09-02 17:22:35 +00:00
|
|
|
template <typename T, typename = decltype(T::__bitset_enum_max)>
|
2016-08-07 19:01:27 +00:00
|
|
|
constexpr bs_t<T> operator -(T lhs, T rhs)
|
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return bs_t<T>(lhs) - bs_t<T>(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Binary '&' operator: bitset intersection
|
|
|
|
template <typename T, typename = decltype(T::__bitset_enum_max)>
|
|
|
|
constexpr bs_t<T> operator &(T lhs, T rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return bs_t<T>(lhs) & bs_t<T>(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Binary '^' operator: bitset symmetric difference
|
|
|
|
template <typename T, typename = decltype(T::__bitset_enum_max)>
|
|
|
|
constexpr bs_t<T> operator ^(T lhs, T rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Atomic bitset specialization with optimized operations
|
|
|
|
template <typename T>
|
2020-12-03 11:47:15 +00:00
|
|
|
class atomic_bs_t : public atomic_t<::bs_t<T>>
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
// Corresponding bitset type
|
|
|
|
using bs_t = ::bs_t<T>;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Base class
|
|
|
|
using base = atomic_t<::bs_t<T>>;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
// Use underlying m_data
|
|
|
|
using base::m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
public:
|
|
|
|
// Underlying type
|
|
|
|
using under = typename bs_t::under;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
atomic_bs_t() = default;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
atomic_bs_t(const atomic_bs_t&) = delete;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
atomic_bs_t& operator =(const atomic_bs_t&) = delete;
|
2016-08-07 19:01:27 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
explicit constexpr atomic_bs_t(bs_t value)
|
|
|
|
: base(value)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
explicit constexpr atomic_bs_t(T bit)
|
|
|
|
: base(bit)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
explicit operator bool() const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return static_cast<bool>(base::load());
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
explicit operator under() const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return static_cast<under>(base::load());
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 10:31:18 +00:00
|
|
|
bs_t operator +() const
|
|
|
|
{
|
|
|
|
return base::load();
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t fetch_add(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::fetch_or(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t add_fetch(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::or_fetch(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator +=(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return add_fetch(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t fetch_sub(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::fetch_and(m_data.m_data, ~rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t sub_fetch(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, ~rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator -=(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return sub_fetch(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t fetch_and(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::fetch_and(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t and_fetch(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::and_fetch(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator &=(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return and_fetch(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t fetch_xor(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::fetch_xor(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t xor_fetch(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, atomic_storage<under>::xor_fetch(m_data.m_data, rhs.m_data));
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator ^=(const bs_t& rhs)
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return xor_fetch(rhs);
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
auto fetch_or(const bs_t&) = delete;
|
|
|
|
auto or_fetch(const bs_t&) = delete;
|
|
|
|
auto operator |=(const bs_t&) = delete;
|
|
|
|
auto operator ++() = delete;
|
|
|
|
auto operator --() = delete;
|
|
|
|
auto operator ++(int) = delete;
|
|
|
|
auto operator --(int) = delete;
|
2016-08-10 12:48:34 +00:00
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator +(bs_t rhs) const
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, base::load().m_data | rhs.m_data);
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator -(bs_t rhs) const
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, base::load().m_data & ~rhs.m_data);
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator &(bs_t rhs) const
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, base::load().m_data & rhs.m_data);
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bs_t operator ^(bs_t rhs) const
|
2016-08-07 19:01:27 +00:00
|
|
|
{
|
2018-09-04 10:31:18 +00:00
|
|
|
return bs_t(0, base::load().m_data ^ rhs.m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bs_t operator ==(bs_t rhs) const
|
|
|
|
{
|
|
|
|
return base::load().m_data == rhs.m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bs_t operator !=(bs_t rhs) const
|
|
|
|
{
|
|
|
|
return base::load().m_data != rhs.m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator +(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return bs_t(0, lhs.m_data | rhs.load().m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator -(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return bs_t(0, lhs.m_data & ~rhs.load().m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator &(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return bs_t(0, lhs.m_data & rhs.load().m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator ^(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return bs_t(0, lhs.m_data ^ rhs.load().m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator ==(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return lhs.m_data == rhs.load().m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bs_t operator !=(bs_t lhs, const atomic_bs_t& rhs)
|
|
|
|
{
|
|
|
|
return lhs.m_data != rhs.load().m_data;
|
2016-08-07 19:01:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bool test_and_set(T rhs)
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return atomic_storage<under>::bts(m_data.m_data, static_cast<uint>(static_cast<under>(rhs)));
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 17:22:35 +00:00
|
|
|
bool test_and_reset(T rhs)
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return atomic_storage<under>::btr(m_data.m_data, static_cast<uint>(static_cast<under>(rhs)));
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 11:47:15 +00:00
|
|
|
bool test_and_invert(T rhs)
|
2016-08-10 12:48:34 +00:00
|
|
|
{
|
2018-09-02 17:22:35 +00:00
|
|
|
return atomic_storage<under>::btc(m_data.m_data, static_cast<uint>(static_cast<under>(rhs)));
|
2016-08-10 12:48:34 +00:00
|
|
|
}
|
2020-12-03 11:47:15 +00:00
|
|
|
|
|
|
|
bool bit_test_set(uint bit) = delete;
|
|
|
|
bool bit_test_reset(uint bit) = delete;
|
|
|
|
bool bit_test_invert(uint bit) = delete;
|
2016-08-10 12:48:34 +00:00
|
|
|
};
|
2018-09-14 09:18:07 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct fmt_unveil<bs_t<T>, void>
|
|
|
|
{
|
|
|
|
// Format as is
|
|
|
|
using type = bs_t<T>;
|
|
|
|
|
|
|
|
static inline u64 get(const bs_t<T>& bitset)
|
|
|
|
{
|
|
|
|
return static_cast<std::underlying_type_t<T>>(bitset);
|
|
|
|
}
|
|
|
|
};
|