File tree 2 files changed +7
-7
lines changed
2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,13 @@ class scoped_lock
39
39
~scoped_lock ();
40
40
41
41
scoped_lock (const scoped_lock&) = delete ;
42
- scoped_lock (scoped_lock&& other) : m_mutex(std::exchange( other.m_mutex, nullptr )) {}
42
+ scoped_lock (scoped_lock&& other) : m_mutex(other.m_mutex.exchange( nullptr , std::memory_order::acq_rel )) {}
43
43
auto operator =(const scoped_lock&) -> scoped_lock& = delete ;
44
44
auto operator =(scoped_lock&& other) noexcept -> scoped_lock&
45
45
{
46
46
if (std::addressof (other) != this )
47
47
{
48
- m_mutex = std::exchange (other.m_mutex , nullptr );
48
+ m_mutex. store (other.m_mutex . exchange ( nullptr , std::memory_order::acq_rel), std::memory_order::release );
49
49
}
50
50
return *this ;
51
51
}
@@ -67,7 +67,7 @@ class scoped_lock
67
67
class coro ::mutex* mutex () const noexcept ;
68
68
69
69
private:
70
- class coro ::mutex* m_mutex{nullptr };
70
+ std::atomic< class coro ::mutex*> m_mutex{nullptr };
71
71
};
72
72
73
73
class mutex
@@ -179,12 +179,13 @@ class mutex
179
179
template <concepts::executor executor_type>
180
180
inline auto scoped_lock::unlock (executor_type& e) -> void
181
181
{
182
- if (m_mutex != nullptr )
182
+ if (auto mtx = m_mutex. load (std::memory_order::acquire) )
183
183
{
184
184
std::atomic_thread_fence (std::memory_order::release);
185
- m_mutex-> unlock (e);
185
+
186
186
// Only allow a scoped lock to unlock the mutex a single time.
187
187
m_mutex = nullptr ;
188
+ mtx->unlock (e);
188
189
}
189
190
}
190
191
Original file line number Diff line number Diff line change @@ -11,11 +11,10 @@ scoped_lock::~scoped_lock()
11
11
12
12
auto scoped_lock::unlock () -> void
13
13
{
14
- if (m_mutex != nullptr )
14
+ if (auto mtx = m_mutex. load (std::memory_order::acquire) )
15
15
{
16
16
std::atomic_thread_fence (std::memory_order::release);
17
17
18
- class coro ::mutex* mtx = m_mutex;
19
18
// Only allow a scoped lock to unlock the mutex a single time.
20
19
m_mutex = nullptr ;
21
20
mtx->unlock ();
You can’t perform that action at this time.
0 commit comments