From 02784b77bb4f652d362297d947b8305dea2b195a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 2 Apr 2016 10:19:20 +0200 Subject: Make Atimoc fit style-guide. --- src/atomic.h | 144 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 77 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/atomic.h b/src/atomic.h index 84ef949..e0b80b1 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -38,75 +38,85 @@ class Atomic; // use std::atomic if possible template class Atomic::value>::type> - : public std::atomic { - - public: - // inherit methods - using std::atomic::atomic; - using std::atomic::operator=; + : public std::atomic +{ +public: + // inherit methods + using std::atomic::atomic; + using std::atomic::operator=; }; // else work around it using a mutex template -class Atomic::value>::type> { - public: - using self_type = Atomic::value>::type>; - - Atomic() - : data{} - , mutex{} { - } - - Atomic(T data) - : data{std::move(data)} - , mutex{} { - } - - Atomic(self_type const & other) - : data{} - , mutex{} { - std::lock_guard lock{other.mutex}; - data = other.data; - } - - Atomic(self_type&& other) - : data{} - , mutex{} { - std::lock_guard lock{other.mutex}; - std::swap(data, other.data); - } - - T operator=(T data) { - std::lock_guard lock{mutex}; - this->data = std::move(data); - return this->data; - } - - operator T() const { - return load(); - } - - bool is_lock_free() const { - return false; - } - - void store(T data) { - std::lock_guard lock{mutex}; - this->data = std::move(data); - } - - T load() const { - std::lock_guard lock{mutex}; - return data; - } - - T exchange(T data){ - std::lock_guard lock{mutex}; - std::swap(data, this->data); - return data; - } - - private: - T data; - mutable std::mutex mutex; +class Atomic::value>::type> +{ +public: + using self_type = + Atomic::value>::type>; + + Atomic() + : data{} + , mutex{} + { + } + + Atomic(T data) + : data{std::move(data)} + , mutex{} + { + } + + Atomic(self_type const & other) + : data{} + , mutex{} + { + std::lock_guard lock{other.mutex}; + data = other.data; + } + + Atomic(self_type&& other) + : data{} + , mutex{} + { + std::lock_guard lock{other.mutex}; + std::swap(data, other.data); + } + + T operator=(T data) + { + std::lock_guard lock{mutex}; + this->data = std::move(data); + return this->data; + } + + operator T() const + { + return load(); + } + + bool is_lock_free() const + { + return false; + } + + void store(T data) + { + std::lock_guard lock{mutex}; + this->data = std::move(data); + } + + T load() const { + std::lock_guard lock{mutex}; + return data; + } + + T exchange(T data){ + std::lock_guard lock{mutex}; + std::swap(data, this->data); + return data; + } + +private: + T data; + mutable std::mutex mutex; }; -- cgit v1.2.3