summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/AtomicUniquePtr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/OSSupport/AtomicUniquePtr.h')
-rw-r--r--src/OSSupport/AtomicUniquePtr.h49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/OSSupport/AtomicUniquePtr.h b/src/OSSupport/AtomicUniquePtr.h
index 92debbac6..b1867ac1a 100644
--- a/src/OSSupport/AtomicUniquePtr.h
+++ b/src/OSSupport/AtomicUniquePtr.h
@@ -4,41 +4,38 @@
/** An RAII wrapper for std::atomic<T*>. */
-template <typename T>
-class cAtomicUniquePtr
+template <typename T> class cAtomicUniquePtr
{
-public:
+ public:
static_assert(!std::is_array<T>::value, "cAtomicUniquePtr does not support arrays");
DISALLOW_COPY_AND_ASSIGN(cAtomicUniquePtr);
- cAtomicUniquePtr() noexcept:
+ cAtomicUniquePtr() noexcept :
m_Ptr(nullptr)
{
}
- cAtomicUniquePtr(std::unique_ptr<T> a_Ptr) noexcept:
+ cAtomicUniquePtr(std::unique_ptr<T> a_Ptr) noexcept :
m_Ptr(a_Ptr.release())
{
}
- cAtomicUniquePtr & operator = (std::unique_ptr<T> a_Ptr) noexcept
+ cAtomicUniquePtr & operator=(std::unique_ptr<T> a_Ptr) noexcept
{
store(std::move(a_Ptr));
return *this;
}
- ~cAtomicUniquePtr() noexcept
- {
- delete load();
- }
+ ~cAtomicUniquePtr() noexcept { delete load(); }
- operator T * () const noexcept
- {
- return load();
- }
+ operator T *() const noexcept { return load(); }
- bool compare_exchange_weak(T *& a_Expected, std::unique_ptr<T> && a_Desired, std::memory_order a_Order = std::memory_order_seq_cst) noexcept
+ bool compare_exchange_weak(
+ T *& a_Expected,
+ std::unique_ptr<T> && a_Desired,
+ std::memory_order a_Order = std::memory_order_seq_cst
+ ) noexcept
{
bool DidExchange = m_Ptr.compare_exchange_weak(a_Expected, a_Desired.get(), a_Order);
if (DidExchange)
@@ -49,7 +46,11 @@ public:
return DidExchange;
}
- bool compare_exchange_strong(T *& a_Expected, std::unique_ptr<T> && a_Desired, std::memory_order a_Order = std::memory_order_seq_cst) noexcept
+ bool compare_exchange_strong(
+ T *& a_Expected,
+ std::unique_ptr<T> && a_Desired,
+ std::memory_order a_Order = std::memory_order_seq_cst
+ ) noexcept
{
bool DidExchange = m_Ptr.compare_exchange_strong(a_Expected, a_Desired.get(), a_Order);
if (DidExchange)
@@ -60,15 +61,15 @@ public:
return DidExchange;
}
- std::unique_ptr<T> exchange(std::unique_ptr<T> a_Ptr, std::memory_order a_Order = std::memory_order_seq_cst) noexcept
+ std::unique_ptr<T> exchange(
+ std::unique_ptr<T> a_Ptr,
+ std::memory_order a_Order = std::memory_order_seq_cst
+ ) noexcept
{
- return std::unique_ptr<T>{ m_Ptr.exchange(a_Ptr.release(), a_Order) };
+ return std::unique_ptr<T> {m_Ptr.exchange(a_Ptr.release(), a_Order)};
}
- T * load(std::memory_order a_Order = std::memory_order_seq_cst) const noexcept
- {
- return m_Ptr.load(a_Order);
- }
+ T * load(std::memory_order a_Order = std::memory_order_seq_cst) const noexcept { return m_Ptr.load(a_Order); }
void store(std::unique_ptr<T> a_Ptr, std::memory_order a_Order = std::memory_order_seq_cst) noexcept
{
@@ -76,6 +77,6 @@ public:
delete m_Ptr.exchange(a_Ptr.release(), a_Order);
}
-private:
- std::atomic<T*> m_Ptr;
+ private:
+ std::atomic<T *> m_Ptr;
};