summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-04-02 10:19:20 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-04-02 10:19:20 +0200
commit02784b77bb4f652d362297d947b8305dea2b195a (patch)
tree88368579cf51e428b5c96a4792ef00e329d9862f
parent036a667a2b0eca1339ba14beafc13a7fdfc23c34 (diff)
Make Atimoc fit style-guide.
-rw-r--r--src/atomic.h144
1 files changed, 77 insertions, 67 deletions
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 <typename T>
class Atomic<T, typename std::enable_if<std::is_pod<T>::value>::type>
- : public std::atomic<T> {
-
- public:
- // inherit methods
- using std::atomic<T>::atomic;
- using std::atomic<T>::operator=;
+ : public std::atomic<T>
+{
+public:
+ // inherit methods
+ using std::atomic<T>::atomic;
+ using std::atomic<T>::operator=;
};
// else work around it using a mutex
template <typename T>
-class Atomic<T, typename std::enable_if<!std::is_pod<T>::value>::type> {
- public:
- using self_type = Atomic<T, typename std::enable_if<!std::is_pod<T>::value>::type>;
-
- Atomic()
- : data{}
- , mutex{} {
- }
-
- Atomic(T data)
- : data{std::move(data)}
- , mutex{} {
- }
-
- Atomic(self_type const & other)
- : data{}
- , mutex{} {
- std::lock_guard<std::mutex> lock{other.mutex};
- data = other.data;
- }
-
- Atomic(self_type&& other)
- : data{}
- , mutex{} {
- std::lock_guard<std::mutex> lock{other.mutex};
- std::swap(data, other.data);
- }
-
- T operator=(T data) {
- std::lock_guard<std::mutex> 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<std::mutex> lock{mutex};
- this->data = std::move(data);
- }
-
- T load() const {
- std::lock_guard<std::mutex> lock{mutex};
- return data;
- }
-
- T exchange(T data){
- std::lock_guard<std::mutex> lock{mutex};
- std::swap(data, this->data);
- return data;
- }
-
- private:
- T data;
- mutable std::mutex mutex;
+class Atomic<T, typename std::enable_if<!std::is_pod<T>::value>::type>
+{
+public:
+ using self_type =
+ Atomic<T, typename std::enable_if<!std::is_pod<T>::value>::type>;
+
+ Atomic()
+ : data{}
+ , mutex{}
+ {
+ }
+
+ Atomic(T data)
+ : data{std::move(data)}
+ , mutex{}
+ {
+ }
+
+ Atomic(self_type const & other)
+ : data{}
+ , mutex{}
+ {
+ std::lock_guard<std::mutex> lock{other.mutex};
+ data = other.data;
+ }
+
+ Atomic(self_type&& other)
+ : data{}
+ , mutex{}
+ {
+ std::lock_guard<std::mutex> lock{other.mutex};
+ std::swap(data, other.data);
+ }
+
+ T operator=(T data)
+ {
+ std::lock_guard<std::mutex> 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<std::mutex> lock{mutex};
+ this->data = std::move(data);
+ }
+
+ T load() const {
+ std::lock_guard<std::mutex> lock{mutex};
+ return data;
+ }
+
+ T exchange(T data){
+ std::lock_guard<std::mutex> lock{mutex};
+ std::swap(data, this->data);
+ return data;
+ }
+
+private:
+ T data;
+ mutable std::mutex mutex;
};