DASH  0.3.0
Atomic.h
1 #ifndef DASH__ATOMIC_H__INCLUDED
2 #define DASH__ATOMIC_H__INCLUDED
3 
4 #include <dash/Meta.h>
5 
6 #include <type_traits>
7 #include <sstream>
8 
9 
10 namespace dash {
11 
48 template <typename T>
49 class Atomic
50 {
51  static_assert(
53  "Type not supported for atomic operations");
54 
55 private:
56  T _value;
57  typedef Atomic<T> self_t;
58 
59 public:
60  typedef T value_type;
61 
62  constexpr Atomic() = default;
63  constexpr Atomic(const Atomic<T>& other) = default;
64  constexpr Atomic(Atomic<T>&& other) = default;
65 
66  self_t& operator=(const self_t& other) = default;
67  self_t& operator=(self_t&& other) = default;
68 
73  constexpr Atomic(T value)
74  : _value(value) { }
75 
84  T operator=(T value) = delete;
85 
90  operator T() = delete;
91 
92  constexpr bool operator==(const self_t & other) const {
93  return _value == other._value;
94  }
95 
96  constexpr bool operator!=(const self_t & other) const {
97  return !(*this == other);
98  }
99 
100  template<typename T_>
101  friend std::ostream & operator<<(
102  std::ostream & os,
103  const Atomic<T_> & at);
104 
105 }; // class Atomic
106 
107 template<typename T>
108 std::ostream & operator<<(
109  std::ostream & os,
110  const Atomic<T> & at)
111 {
112  std::ostringstream ss;
113  ss << dash::typestr(at) << "<phantom>";
114  return operator<<(os, ss.str());
115 }
116 
117 } // namespace dash
118 
119 #include <dash/atomic/Type_traits.h>
120 #include <dash/atomic/GlobAtomicRef.h>
121 #include <dash/atomic/GlobAtomicAsyncRef.h>
122 #include <dash/atomic/Operation.h>
123 
124 #endif // DASH__ATOMIC_H__INCLUDED
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
Type wrapper to mark any trivial type atomic.
Type trait indicating whether a type can be used for global atomic operations.
Definition: Types.h:252
constexpr Atomic(T value)
Initializes the underlying value with desired.
Definition: Atomic.h:73
std::string typestr(const T &obj)
Returns string containing the type name of the given object.
Definition: TypeInfo.h:20