@@ -48,15 +48,16 @@ using namespace argon::vm::sync;
48
48
49
49
// PRIVATE
50
50
void RecursiveSharedMutex::lock_shared_slow (std::thread::id id) {
51
- auto current = this ->_lock .load (std::memory_order_relaxed );
51
+ auto current = this ->_lock .load (std::memory_order_acquire );
52
52
MutexBits desired{};
53
53
54
54
do {
55
55
while (current.is_ulocked () && this ->_id != id) {
56
56
this ->_pending ++;
57
57
OS_WAIT (&this ->_lock , current.value ());
58
+ this ->_pending --;
58
59
59
- current = this ->_lock .load (std::memory_order_relaxed );
60
+ current = this ->_lock .load (std::memory_order_acquire );
60
61
}
61
62
62
63
desired = current;
@@ -74,6 +75,7 @@ void RecursiveSharedMutex::lock_slow() {
74
75
while (!this ->_lock .compare_exchange_strong (current, desired)) {
75
76
this ->_pending ++;
76
77
OS_WAIT (&this ->_lock , current.value ());
78
+ this ->_pending --;
77
79
78
80
current = MutexBits{};
79
81
}
@@ -141,12 +143,10 @@ void RecursiveSharedMutex::unlock() {
141
143
do {
142
144
desired = current;
143
145
desired.release_unique ();
144
- } while (!this ->_lock .compare_exchange_strong (current, desired));
146
+ } while (!this ->_lock .compare_exchange_strong (current, desired, std::memory_order_acq_rel ));
145
147
146
- if (this ->_pending > 0 ) {
147
- this ->_pending --;
148
+ if (this ->_pending > 0 )
148
149
OS_WAKE (&this ->_lock );
149
- }
150
150
}
151
151
152
152
void RecursiveSharedMutex::unlock_shared () {
@@ -157,10 +157,8 @@ void RecursiveSharedMutex::unlock_shared() {
157
157
desired = current;
158
158
159
159
desired.dec_shared ();
160
- } while (!this ->_lock .compare_exchange_strong (current, desired));
160
+ } while (!this ->_lock .compare_exchange_strong (current, desired, std::memory_order_acq_rel ));
161
161
162
- if (this ->_pending > 0 ) {
163
- this ->_pending --;
162
+ if (this ->_pending > 0 )
164
163
OS_WAKE (&this ->_lock );
165
- }
166
164
}
0 commit comments