Skip to content

Commit e48a774

Browse files
committed
Only use acq ordering for MicroSpinLock locking
1 parent e197b3a commit e48a774

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

folly/synchronization/MicroSpinLock.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ struct MicroSpinLock {
6868
void init() noexcept { payload()->store(FREE); }
6969

7070
bool try_lock() noexcept {
71-
bool ret = xchg(LOCKED) == FREE;
71+
bool ret = xchg_acq(LOCKED) == FREE;
7272
annotate_rwlock_try_acquired(
7373
this, annotate_rwlock_level::wrlock, ret, __FILE__, __LINE__);
7474
return ret;
7575
}
7676

7777
void lock() noexcept {
7878
detail::Sleeper sleeper;
79-
while (xchg(LOCKED) != FREE) {
79+
while (xchg_acq(LOCKED) != FREE) {
8080
do {
8181
sleeper.wait();
8282
} while (payload()->load(std::memory_order_relaxed) == LOCKED);
@@ -98,9 +98,9 @@ struct MicroSpinLock {
9898
return reinterpret_cast<std::atomic<uint8_t>*>(&this->lock_);
9999
}
100100

101-
uint8_t xchg(uint8_t newVal) noexcept {
101+
uint8_t xchg_acq(uint8_t newVal) noexcept {
102102
return std::atomic_exchange_explicit(
103-
payload(), newVal, std::memory_order_acq_rel);
103+
payload(), newVal, std::memory_order_acquire);
104104
}
105105
};
106106
static_assert(

0 commit comments

Comments
 (0)