File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -32,12 +32,31 @@ namespace detail {
32
32
#if !defined(BOOST_ASIO_HAS_THREADS)
33
33
typedef long atomic_count;
34
34
inline void increment (atomic_count& a, long b) { a += b; }
35
+ inline void ref_count_up (atomic_count& a) { ++a; }
36
+ inline bool ref_count_down (atomic_count& a) { return --a == 0 ; }
35
37
#elif defined(BOOST_ASIO_HAS_STD_ATOMIC)
36
38
typedef std::atomic<long > atomic_count;
37
39
inline void increment (atomic_count& a, long b) { a += b; }
40
+
41
+ inline void ref_count_up (atomic_count& a)
42
+ {
43
+ a.fetch_add (1 , std::memory_order_relaxed);
44
+ }
45
+
46
+ inline bool ref_count_down (atomic_count& a)
47
+ {
48
+ if (a.fetch_sub (1 , std::memory_order_release) == 1 )
49
+ {
50
+ std::atomic_thread_fence (std::memory_order_acquire);
51
+ return true ;
52
+ }
53
+ return false ;
54
+ }
38
55
#else // defined(BOOST_ASIO_HAS_STD_ATOMIC)
39
56
typedef boost::detail::atomic_count atomic_count;
40
57
inline void increment (atomic_count& a, long b) { while (b > 0 ) ++a, --b; }
58
+ inline void ref_count_up (atomic_count& a) { ++a; }
59
+ inline bool ref_count_down (atomic_count& a) { return --a == 0 ; }
41
60
#endif // defined(BOOST_ASIO_HAS_STD_ATOMIC)
42
61
43
62
} // namespace detail
Original file line number Diff line number Diff line change @@ -149,13 +149,13 @@ class executor::impl
149
149
150
150
impl_base* clone () const BOOST_ASIO_NOEXCEPT
151
151
{
152
- ++ ref_count_;
152
+ detail::ref_count_up ( ref_count_) ;
153
153
return const_cast <impl_base*>(static_cast <const impl_base*>(this ));
154
154
}
155
155
156
156
void destroy () BOOST_ASIO_NOEXCEPT
157
157
{
158
- if (-- ref_count_ == 0 )
158
+ if (detail::ref_count_down ( ref_count_) )
159
159
{
160
160
allocator_type alloc (allocator_);
161
161
impl* p = this ;
You can’t perform that action at this time.
0 commit comments