Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomicWrapper.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
25 #ifndef _ATOMIC_WRAPPER_H_
26 #define _ATOMIC_WRAPPER_H_
27 
28 #include <atomic>
29 
30 #include "galois/config.h"
31 
32 namespace galois {
39 template <class T>
40 class CopyableAtomic : public std::atomic<T> {
41 public:
43  CopyableAtomic() : std::atomic<T>(T{}) {}
44 
46  constexpr CopyableAtomic(T desired) : std::atomic<T>(desired) {}
47 
49  constexpr CopyableAtomic(const CopyableAtomic<T>& other)
50  : CopyableAtomic(other.load(std::memory_order_relaxed)) {}
51 
54  this->store(other.load(std::memory_order_relaxed),
55  std::memory_order_relaxed);
56  return *this;
57  }
58 };
59 
60 } // namespace galois
61 #endif
CopyableAtomic & operator=(const CopyableAtomic< T > &other)
Copy constructor operator.
Definition: AtomicWrapper.h:53
Class that inherits from std::atomic to make it copyable by defining a copy constructor.
Definition: AtomicWrapper.h:40
constexpr CopyableAtomic(const CopyableAtomic< T > &other)
Copy constructor.
Definition: AtomicWrapper.h:49
CopyableAtomic()
Default constructor.
Definition: AtomicWrapper.h:43
constexpr CopyableAtomic(T desired)
Constructor initializing atomic to passed in data.
Definition: AtomicWrapper.h:46