diff options
author | babenko <babenko@yandex-team.com> | 2022-11-16 09:44:16 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2022-11-16 09:44:16 +0300 |
commit | c7037dfb3708e261a40f3a27dcf3aa32985cc602 (patch) | |
tree | 2636b904f2b8291c565bda4c9b172e8fac5a92de | |
parent | 53e58124e62ac7cc2a957e10fc2400d2b6b5eb92 (diff) | |
download | ydb-c7037dfb3708e261a40f3a27dcf3aa32985cc602.tar.gz |
Switch to modern std::memory_order enum
-rw-r--r-- | library/cpp/yt/memory/atomic_intrusive_ptr-inl.h | 4 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref_counted-inl.h | 22 | ||||
-rw-r--r-- | library/cpp/yt/memory/ref_tracked-inl.h | 8 | ||||
-rw-r--r-- | library/cpp/yt/threading/event_count-inl.h | 20 | ||||
-rw-r--r-- | library/cpp/yt/threading/recursive_spin_lock-inl.h | 2 | ||||
-rw-r--r-- | library/cpp/yt/threading/rw_spin_lock-inl.h | 18 | ||||
-rw-r--r-- | library/cpp/yt/threading/spin_lock-inl.h | 6 | ||||
-rw-r--r-- | library/cpp/yt/threading/spin_wait.cpp | 4 |
8 files changed, 42 insertions, 42 deletions
diff --git a/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h b/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h index ca2467a280..f52e5d37da 100644 --- a/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h +++ b/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h @@ -22,9 +22,9 @@ TAtomicIntrusivePtr<T>::TAtomicIntrusivePtr(TIntrusivePtr<T> other) template <class T> TAtomicIntrusivePtr<T>::TAtomicIntrusivePtr(TAtomicIntrusivePtr&& other) - : Ptr_(other.Ptr_.load(std::memory_order_relaxed)) + : Ptr_(other.Ptr_.load(std::memory_order::relaxed)) { - other.Ptr_.store(nullptr, std::memory_order_relaxed); + other.Ptr_.store(nullptr, std::memory_order::relaxed); } template <class T> diff --git a/library/cpp/yt/memory/ref_counted-inl.h b/library/cpp/yt/memory/ref_counted-inl.h index bb29f70585..9b30960917 100644 --- a/library/cpp/yt/memory/ref_counted-inl.h +++ b/library/cpp/yt/memory/ref_counted-inl.h @@ -68,21 +68,21 @@ struct TMemoryReleaser<T, std::enable_if_t<T::EnableHazard>> Y_FORCE_INLINE int TRefCounter::GetRefCount() const noexcept { - return StrongCount_.load(std::memory_order_acquire); + return StrongCount_.load(std::memory_order::acquire); } Y_FORCE_INLINE void TRefCounter::Ref(int n) const noexcept { // It is safe to use relaxed here, since new reference is always created from another live reference. - StrongCount_.fetch_add(n, std::memory_order_relaxed); + StrongCount_.fetch_add(n, std::memory_order::relaxed); - YT_ASSERT(WeakCount_.load(std::memory_order_relaxed) > 0); + YT_ASSERT(WeakCount_.load(std::memory_order::relaxed) > 0); } Y_FORCE_INLINE bool TRefCounter::TryRef() const noexcept { - auto value = StrongCount_.load(std::memory_order_relaxed); - YT_ASSERT(WeakCount_.load(std::memory_order_relaxed) > 0); + auto value = StrongCount_.load(std::memory_order::relaxed); + YT_ASSERT(WeakCount_.load(std::memory_order::relaxed) > 0); while (value != 0 && !StrongCount_.compare_exchange_weak(value, value + 1)); return value != 0; @@ -95,10 +95,10 @@ Y_FORCE_INLINE bool TRefCounter::Unref(int n) const // // See http://www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html#boost_atomic.usage_examples.example_reference_counters // - auto oldStrongCount = StrongCount_.fetch_sub(n, std::memory_order_release); + auto oldStrongCount = StrongCount_.fetch_sub(n, std::memory_order::release); YT_ASSERT(oldStrongCount >= n); if (oldStrongCount == n) { - std::atomic_thread_fence(std::memory_order_acquire); + std::atomic_thread_fence(std::memory_order::acquire); NSan::Acquire(&StrongCount_); return true; } else { @@ -108,21 +108,21 @@ Y_FORCE_INLINE bool TRefCounter::Unref(int n) const Y_FORCE_INLINE int TRefCounter::GetWeakRefCount() const noexcept { - return WeakCount_.load(std::memory_order_acquire); + return WeakCount_.load(std::memory_order::acquire); } Y_FORCE_INLINE void TRefCounter::WeakRef() const noexcept { - auto oldWeakCount = WeakCount_.fetch_add(1, std::memory_order_relaxed); + auto oldWeakCount = WeakCount_.fetch_add(1, std::memory_order::relaxed); YT_ASSERT(oldWeakCount > 0); } Y_FORCE_INLINE bool TRefCounter::WeakUnref() const { - auto oldWeakCount = WeakCount_.fetch_sub(1, std::memory_order_release); + auto oldWeakCount = WeakCount_.fetch_sub(1, std::memory_order::release); YT_ASSERT(oldWeakCount > 0); if (oldWeakCount == 1) { - std::atomic_thread_fence(std::memory_order_acquire); + std::atomic_thread_fence(std::memory_order::acquire); NSan::Acquire(&WeakCount_); return true; } else { diff --git a/library/cpp/yt/memory/ref_tracked-inl.h b/library/cpp/yt/memory/ref_tracked-inl.h index 4bde72881d..efd95edd2d 100644 --- a/library/cpp/yt/memory/ref_tracked-inl.h +++ b/library/cpp/yt/memory/ref_tracked-inl.h @@ -18,13 +18,13 @@ template <class T> Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookie() { static std::atomic<TRefCountedTypeCookie> cookie{NullRefCountedTypeCookie}; - auto cookieValue = cookie.load(std::memory_order_relaxed); + auto cookieValue = cookie.load(std::memory_order::relaxed); if (Y_UNLIKELY(cookieValue == NullRefCountedTypeCookie)) { cookieValue = TRefCountedTrackerFacade::GetCookie( GetRefCountedTypeKey<T>(), sizeof(T), NYT::TSourceLocation()); - cookie.store(cookieValue, std::memory_order_relaxed); + cookie.store(cookieValue, std::memory_order::relaxed); } return cookieValue; } @@ -33,13 +33,13 @@ template <class T, class TTag, int Counter> Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation(const TSourceLocation& location) { static std::atomic<TRefCountedTypeCookie> cookie{NullRefCountedTypeCookie}; - auto cookieValue = cookie.load(std::memory_order_relaxed); + auto cookieValue = cookie.load(std::memory_order::relaxed); if (Y_UNLIKELY(cookieValue == NullRefCountedTypeCookie)) { cookieValue = TRefCountedTrackerFacade::GetCookie( GetRefCountedTypeKey<T>(), sizeof(T), location); - cookie.store(cookieValue, std::memory_order_relaxed); + cookie.store(cookieValue, std::memory_order::relaxed); } return cookieValue; } diff --git a/library/cpp/yt/threading/event_count-inl.h b/library/cpp/yt/threading/event_count-inl.h index 21cc88c70b..18f7bfec52 100644 --- a/library/cpp/yt/threading/event_count-inl.h +++ b/library/cpp/yt/threading/event_count-inl.h @@ -34,7 +34,7 @@ inline void TEventCount::NotifyMany(int count) TGuard<TMutex> guard(Mutex_); #endif - ui64 prev = Value_.fetch_add(AddEpoch, std::memory_order_acq_rel); + ui64 prev = Value_.fetch_add(AddEpoch, std::memory_order::acq_rel); if (Y_UNLIKELY((prev & WaiterMask) != 0)) { #ifdef _linux_ FutexWake( @@ -52,7 +52,7 @@ inline void TEventCount::NotifyMany(int count) inline TEventCount::TCookie TEventCount::PrepareWait() { - ui64 value = Value_.load(std::memory_order_acquire); + ui64 value = Value_.load(std::memory_order::acquire); return TCookie(static_cast<ui32>(value >> EpochShift)); } @@ -61,11 +61,11 @@ inline void TEventCount::CancelWait() inline bool TEventCount::Wait(TCookie cookie, TInstant deadline) { - Value_.fetch_add(AddWaiter, std::memory_order_acq_rel); + Value_.fetch_add(AddWaiter, std::memory_order::acq_rel); bool result = true; #ifdef _linux_ - while ((Value_.load(std::memory_order_acquire) >> EpochShift) == cookie.Epoch_) { + while ((Value_.load(std::memory_order::acquire) >> EpochShift) == cookie.Epoch_) { auto timeout = deadline - TInstant::Now(); auto futexResult = FutexWait( @@ -80,11 +80,11 @@ inline bool TEventCount::Wait(TCookie cookie, TInstant deadline) } #else TGuard<TMutex> guard(Mutex_); - if ((Value_.load(std::memory_order_acquire) >> EpochShift) == cookie.Epoch_) { + if ((Value_.load(std::memory_order::acquire) >> EpochShift) == cookie.Epoch_) { result = ConditionVariable_.WaitD(Mutex_, deadline); } #endif - ui64 prev = Value_.fetch_add(SubWaiter, std::memory_order_seq_cst); + ui64 prev = Value_.fetch_add(SubWaiter, std::memory_order::seq_cst); YT_ASSERT((prev & WaiterMask) != 0); return result; } @@ -131,26 +131,26 @@ bool TEventCount::Await(TCondition&& condition, TDuration timeout) inline void TEvent::NotifyOne() { - Set_.store(true, std::memory_order_release); + Set_.store(true, std::memory_order::release); EventCount_.NotifyOne(); } inline void TEvent::NotifyAll() { - Set_.store(true, std::memory_order_release); + Set_.store(true, std::memory_order::release); EventCount_.NotifyAll(); } inline bool TEvent::Test() const { - return Set_.load(std::memory_order_acquire); + return Set_.load(std::memory_order::acquire); } inline bool TEvent::Wait(TInstant deadline) { return EventCount_.Await( [&] { - return Set_.load(std::memory_order_acquire); + return Set_.load(std::memory_order::acquire); }, deadline); } diff --git a/library/cpp/yt/threading/recursive_spin_lock-inl.h b/library/cpp/yt/threading/recursive_spin_lock-inl.h index 2932845081..ab829255d0 100644 --- a/library/cpp/yt/threading/recursive_spin_lock-inl.h +++ b/library/cpp/yt/threading/recursive_spin_lock-inl.h @@ -57,7 +57,7 @@ inline bool TRecursiveSpinLock::IsLockedByCurrentThread() const noexcept inline bool TRecursiveSpinLock::TryAndTryAcquire() noexcept { - auto value = Value_.load(std::memory_order_relaxed); + auto value = Value_.load(std::memory_order::relaxed); auto recursionDepth = value & RecursionDepthMask; if (recursionDepth > 0 && (value >> ThreadIdShift) != GetSequentialThreadId()) { return false; diff --git a/library/cpp/yt/threading/rw_spin_lock-inl.h b/library/cpp/yt/threading/rw_spin_lock-inl.h index e9d9e121f9..173059757c 100644 --- a/library/cpp/yt/threading/rw_spin_lock-inl.h +++ b/library/cpp/yt/threading/rw_spin_lock-inl.h @@ -30,7 +30,7 @@ inline void TReaderWriterSpinLock::AcquireReaderForkFriendly() noexcept inline void TReaderWriterSpinLock::ReleaseReader() noexcept { - auto prevValue = Value_.fetch_sub(ReaderDelta, std::memory_order_release); + auto prevValue = Value_.fetch_sub(ReaderDelta, std::memory_order::release); Y_ASSERT((prevValue & ~WriterMask) != 0); } @@ -44,7 +44,7 @@ inline void TReaderWriterSpinLock::AcquireWriter() noexcept inline void TReaderWriterSpinLock::ReleaseWriter() noexcept { - auto prevValue = Value_.fetch_and(~WriterMask, std::memory_order_release); + auto prevValue = Value_.fetch_and(~WriterMask, std::memory_order::release); Y_ASSERT(prevValue & WriterMask); } @@ -65,9 +65,9 @@ inline bool TReaderWriterSpinLock::IsLockedByWriter() const noexcept inline bool TReaderWriterSpinLock::TryAcquireReader() noexcept { - auto oldValue = Value_.fetch_add(ReaderDelta, std::memory_order_acquire); + auto oldValue = Value_.fetch_add(ReaderDelta, std::memory_order::acquire); if ((oldValue & WriterMask) != 0) { - Value_.fetch_sub(ReaderDelta, std::memory_order_relaxed); + Value_.fetch_sub(ReaderDelta, std::memory_order::relaxed); return false; } return true; @@ -75,7 +75,7 @@ inline bool TReaderWriterSpinLock::TryAcquireReader() noexcept inline bool TReaderWriterSpinLock::TryAndTryAcquireReader() noexcept { - auto oldValue = Value_.load(std::memory_order_relaxed); + auto oldValue = Value_.load(std::memory_order::relaxed); if ((oldValue & WriterMask) != 0) { return false; } @@ -84,23 +84,23 @@ inline bool TReaderWriterSpinLock::TryAndTryAcquireReader() noexcept inline bool TReaderWriterSpinLock::TryAcquireReaderForkFriendly() noexcept { - auto oldValue = Value_.load(std::memory_order_relaxed); + auto oldValue = Value_.load(std::memory_order::relaxed); if ((oldValue & WriterMask) != 0) { return false; } auto newValue = oldValue + ReaderDelta; - return Value_.compare_exchange_weak(oldValue, newValue, std::memory_order_acquire); + return Value_.compare_exchange_weak(oldValue, newValue, std::memory_order::acquire); } inline bool TReaderWriterSpinLock::TryAcquireWriter() noexcept { auto expected = UnlockedValue; - return Value_.compare_exchange_weak(expected, WriterMask, std::memory_order_acquire); + return Value_.compare_exchange_weak(expected, WriterMask, std::memory_order::acquire); } inline bool TReaderWriterSpinLock::TryAndTryAcquireWriter() noexcept { - auto oldValue = Value_.load(std::memory_order_relaxed); + auto oldValue = Value_.load(std::memory_order::relaxed); if (oldValue != UnlockedValue) { return false; } diff --git a/library/cpp/yt/threading/spin_lock-inl.h b/library/cpp/yt/threading/spin_lock-inl.h index 515842f9cc..dd7c219725 100644 --- a/library/cpp/yt/threading/spin_lock-inl.h +++ b/library/cpp/yt/threading/spin_lock-inl.h @@ -26,9 +26,9 @@ inline void TSpinLock::Acquire() noexcept inline void TSpinLock::Release() noexcept { #ifdef NDEBUG - Value_.store(UnlockedValue, std::memory_order_release); + Value_.store(UnlockedValue, std::memory_order::release); #else - YT_ASSERT(Value_.exchange(UnlockedValue, std::memory_order_release) != UnlockedValue); + YT_ASSERT(Value_.exchange(UnlockedValue, std::memory_order::release) != UnlockedValue); #endif } @@ -50,7 +50,7 @@ inline bool TSpinLock::TryAcquire() noexcept inline bool TSpinLock::TryAndTryAcquire() noexcept { - auto value = Value_.load(std::memory_order_relaxed); + auto value = Value_.load(std::memory_order::relaxed); #ifdef YT_ENABLE_SPIN_LOCK_OWNERSHIP_TRACKING YT_ASSERT(value != GetSequentialThreadId()); #endif diff --git a/library/cpp/yt/threading/spin_wait.cpp b/library/cpp/yt/threading/spin_wait.cpp index 309fdb8b3a..0929121f94 100644 --- a/library/cpp/yt/threading/spin_wait.cpp +++ b/library/cpp/yt/threading/spin_wait.cpp @@ -17,9 +17,9 @@ namespace { TDuration SuggestSleepDelay(int iteration) { static std::atomic<ui64> Rand; - auto rand = Rand.load(std::memory_order_relaxed); + auto rand = Rand.load(std::memory_order::relaxed); rand = 0x5deece66dLL * rand + 0xb; // numbers from nrand48() - Rand.store(rand, std::memory_order_relaxed); + Rand.store(rand, std::memory_order::relaxed); constexpr ui64 MinDelayUs = 128; |