Open
Bug 1948601
Opened 1 year ago
Updated 10 months ago
Enable more types for the use with Atomic<T>
Categories
(Core :: MFBT, enhancement)
Core
MFBT
Tracking
()
NEW
People
(Reporter: jstutte, Unassigned)
References
Details
Currently we can only use booleans, integral types and enums (all only of size 4 or 8) with Atomic<T>. The underlying std::atomic has less strict requirements.
I assume we could just use the same minimal set of functions as for enums, something like:
/**
- * Atomic<T> implementation for enum types.
+ * Atomic<T> implementation for other types.
*
* The atomic store and load operations and the atomic swap method is provided.
*/
template <typename T, MemoryOrdering Order>
-class Atomic<T, Order, std::enable_if_t<std::is_enum_v<T>>>
+class Atomic<
+ T, Order,
+ std::enable_if_t<
+ !std::is_integral_v<T> && !std::is_same_v<T, bool> &&
+ !std::is_pointer_v<T> &&
+ // See https://en.cppreference.com/w/cpp/atomic/atomic for constraints.
+ std::is_trivially_copyable_v<T> && std::is_copy_constructible_v<T> &&
+ std::is_move_constructible_v<T> && std::is_copy_assignable_v<T> &&
+ std::is_move_assignable_v<T> &&
+ std::is_same_v<T, typename std::remove_cv<T>::type>>>
: public detail::AtomicBase<T, Order> {
typedef typename detail::AtomicBase<T, Order> Base;
public:
constexpr Atomic() : Base() {}
explicit constexpr Atomic(T aInit) : Base(aInit) {}
operator T() const { return T(Base::Intrinsics::load(Base::mValue)); }
to enable its use for more types. There might be also a question about the allowed size of types, but that could be a bit more tricky to understand.
| Reporter | ||
Comment 1•1 year ago
|
||
This came up in bug 1920451 when trying to use Atomic<std::chrono::time_point<...>>.
Bug 732043 long list of comments (from 12 years ago) might give some background on the rationales for the current restrictions.
You need to log in
before you can comment on or make changes to this bug.
Description
•