aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/Atomic.hpp
blob: 4008dfcbbb34a1f2422cc1c15ad462ff82fa8701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef EFSW_ATOMIC_BOOL_HPP
#define EFSW_ATOMIC_BOOL_HPP

#include <efsw/base.hpp>

#ifdef EFSW_USE_CXX11
#include <atomic>
#endif

namespace efsw {

template <typename T> class Atomic {
  public:
	explicit Atomic( T set = false ) : set_( set ) {}

	Atomic& operator=( T set ) {
#ifdef EFSW_USE_CXX11
		set_.store( set, std::memory_order_release );
#else
		set_ = set;
#endif
		return *this;
	}

	explicit operator T() const {
#ifdef EFSW_USE_CXX11
		return set_.load( std::memory_order_acquire );
#else
		return set_;
#endif
	}

	T load() const {
#ifdef EFSW_USE_CXX11
		return set_.load( std::memory_order_acquire );
#else
		return set_;
#endif
	}

  private:
#ifdef EFSW_USE_CXX11
	std::atomic<T> set_;
#else
	volatile T set_;
#endif
};

} // namespace efsw

#endif