DASH  0.3.0
Operation.h
1 #ifndef DASH__ATOMIC_OPERATION_H_
2 #define DASH__ATOMIC_OPERATION_H_
3 
4 #include <dash/atomic/GlobAtomicRef.h>
5 
6 namespace dash {
7 
8 // forward decls
9 template<typename T>
10 class Atomic;
11 
28 namespace atomic {
29 
33 template<typename T>
35  return ref.load();
36 }
37 
41 template<typename T>
43  const T & value)
44 {
45  ref.store(value);
46 }
47 
52 template<typename T>
54  const T & value)
55 {
56  return ref.exchange(value);
57 }
58 
65 template<typename T>
67  const dash::GlobRef<dash::Atomic<T>>& ref,
68  const T & expected,
69  const T & desired)
70 {
71  return ref.compare_exchange(expected, desired);
72 }
73 
77 template<
78  typename T,
79  typename BinaryOp >
80 void op(
81  const dash::GlobRef<dash::Atomic<T>>& ref,
82  const BinaryOp binary_op,
84  const T & value)
85 {
86  ref.op(binary_op, value);
87 }
88 
95 template<
96  typename T,
97  typename BinaryOp >
99  const dash::GlobRef<dash::Atomic<T>>& ref,
100  const BinaryOp binary_op,
102  const T & value)
103 {
104  return ref.fetch_op(binary_op, value);
105 }
106 
110 template<typename T>
111 typename std::enable_if<
112  std::is_integral<T>::value,
113  void>::type
115  const dash::GlobRef<dash::Atomic<T>>& ref,
116  const T & value)
117 {
118  ref.add(value);
119 }
120 
124 template<typename T>
125 typename std::enable_if<
126  std::is_integral<T>::value,
127  void>::type
129  const dash::GlobRef<dash::Atomic<T>>& ref,
130  const T & value)
131 {
132  ref.sub(value);
133 }
134 
138 template<typename T>
139 typename std::enable_if<
140  std::is_integral<T>::value,
141  void>::type
143  const dash::GlobRef<dash::Atomic<T>>& ref,
144  const T & value)
145 {
146  ref.multiply(value);
147 }
148 
149 
156 template<typename T>
157 typename std::enable_if<
158  std::is_integral<T>::value,
159  T>::type
161  const dash::GlobRef<dash::Atomic<T>>& ref,
163  const T & value)
164 {
165  return ref.fetch_add(value);
166 }
167 
174 template<typename T>
175 typename std::enable_if<
176  std::is_integral<T>::value,
177  T>::type
179  const dash::GlobRef<dash::Atomic<T>>& ref,
181  const T & value)
182 {
183  return ref.fetch_sub(value);
184 }
185 
186 } // namespace atomic
187 } // namespace dash
188 
189 #endif // DASH__ATOMIC_OPERATION_H_
190 
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.
std::enable_if< std::is_integral< T >::value, T >::type fetch_sub(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomic fetch-and-sub operation on the referenced shared value.
Definition: Operation.h:178
std::enable_if< std::is_integral< T >::value, void >::type multiply(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomic multiply operation on the referenced shared value.
Definition: Operation.h:142
std::enable_if< std::is_integral< T >::value, void >::type add(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomic add operation on the referenced shared value.
Definition: Operation.h:114
void op(const dash::GlobRef< dash::Atomic< T >> &ref, const BinaryOp binary_op, const T &value)
Atomically executes specified operation on the referenced shared value.
Definition: Operation.h:80
std::enable_if< std::is_integral< T >::value, T >::type fetch_add(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomic fetch-and-add operation on the referenced shared value.
Definition: Operation.h:160
T load(const dash::GlobRef< dash::Atomic< T >> &ref)
Get the value of the shared atomic.
Definition: Operation.h:34
std::enable_if< std::is_integral< T >::value, void >::type sub(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomic subtract operation on the referenced shared value.
Definition: Operation.h:128
T fetch_op(const dash::GlobRef< dash::Atomic< T >> &ref, const BinaryOp binary_op, const T &value)
Atomic fetch-and-op operation on the referenced shared value.
Definition: Operation.h:98
bool compare_exchange(const dash::GlobRef< dash::Atomic< T >> &ref, const T &expected, const T &desired)
Atomically compares the value with the value of expected and if those are bitwise-equal, replaces the former with desired.
Definition: Operation.h:66
void store(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Set the value of the atomic reference.
Definition: Operation.h:42
T exchange(const dash::GlobRef< dash::Atomic< T >> &ref, const T &value)
Atomically sets the value of the atomic reference and returns the old value.
Definition: Operation.h:53