Merge pull request #10215 from Icinga/Al2Klimov-patch-3

Atomic<T>#Atomic(T): fix C++ compliance
This commit is contained in:
Alexander Aleksandrovič Klimov 2024-11-06 13:33:46 +01:00 committed by GitHub
commit 0fde1ef632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 15 deletions

View File

@ -12,7 +12,12 @@ namespace icinga
{
/**
* Extends std::atomic with an atomic constructor.
* Like std::atomic, but enforces usage of its only safe constructor.
*
* "The default-initialized std::atomic<T> does not contain a T object,
* and its only valid uses are destruction and
* initialization by std::atomic_init, see LWG issue 2334."
* -- https://en.cppreference.com/w/cpp/atomic/atomic/atomic
*
* @ingroup base
*/
@ -20,24 +25,12 @@ template<class T>
class Atomic : public std::atomic<T> {
public:
/**
* Like std::atomic#atomic, but operates atomically
* The only safe constructor of std::atomic#atomic
*
* @param desired Initial value
*/
inline Atomic(T desired)
inline Atomic(T desired) : std::atomic<T>(desired)
{
this->store(desired);
}
/**
* Like std::atomic#atomic, but operates atomically
*
* @param desired Initial value
* @param order Initial store operation's memory order
*/
inline Atomic(T desired, std::memory_order order)
{
this->store(desired, order);
}
};