OpenDDS  Snapshot(2023/04/28-20:55)
Atomic.h
Go to the documentation of this file.
1 #ifndef OPENDDS_DCPS_ATOMIC_H
2 #define OPENDDS_DCPS_ATOMIC_H
3 
4 #if !defined (ACE_LACKS_PRAGMA_ONCE)
5 # pragma once
6 #endif /* ACE_LACKS_PRAGMA_ONCE */
7 
9 
10 #ifdef ACE_HAS_CPP11
11 # include <atomic>
12 #else
13 # include <ace/Atomic_Op.h>
14 # include <ace/Thread_Mutex.h>
15 #endif
16 
18 
19 namespace OpenDDS {
20 namespace DCPS {
21 
22 #ifdef ACE_HAS_CPP11
23 template <typename T>
24 using Atomic = std::atomic<T>;
25 #else
26 template <typename T>
27 class Atomic
28 {
29 public:
30  Atomic() : impl_() {}
31  Atomic(T desired) : impl_(desired) {}
32 
33  inline T load() const { return impl_.value(); }
34  inline void store(T desired) const { impl_ = desired; }
35  inline T exchange(const T& desired) { return impl_.exchange(desired); }
36 
37  inline operator T() const { return impl_.value(); }
38  inline T operator=(const T& desired) { impl_ = desired; return desired; }
39 
40  inline T operator++() { return ++impl_; }
41  inline T operator++(int) { return impl_++; }
42 
43  inline T operator--() { return --impl_; }
44  inline T operator--(int) { return impl_--; }
45 
46  inline T operator+=(T arg) { return impl_ += arg; }
47  inline T operator-=(T arg) { return impl_ -= arg; }
48 
49 private:
51  Base impl_;
52 };
53 #endif
54 
55 } // DCPS
56 } // OPENDDS
57 
59 
60 #endif /* end of include guard: OPENDDS_DCPS_ATOMIC_H */
61 
Atomic(T desired)
Definition: Atomic.h:31
T operator-=(T arg)
Definition: Atomic.h:47
TYPE exchange(TYPE newval)
T operator=(const T &desired)
Definition: Atomic.h:38
T operator+=(T arg)
Definition: Atomic.h:46
void store(T desired) const
Definition: Atomic.h:34
TYPE value(void) const
T exchange(const T &desired)
Definition: Atomic.h:35
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
T load() const
Definition: Atomic.h:33
ACE_Atomic_Op< ACE_Thread_Mutex, T > Base
Definition: Atomic.h:50
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28