#pragma once #ifndef TRACELESS_GUARD_INL_H_ #error "Direct inclusion of this file is not allowed, include traceless_guard.h" #endif #undef TRACELESS_GUARD_INL_H_ #include "rw_spin_lock.h" #include "spin_lock_count.h" #include #include namespace NYT::NThreading::NPrivate { //////////////////////////////////////////////////////////////////////////////// #ifdef NDEBUG template > using TTracelessGuard = TGuard; template > using TTracelessInverseGuard = TInverseGuard; template > using TTracelessTryGuard = TTryGuard; template using TTracelessReaderGuard = TReaderGuard; template using TTracelessWriterGuard = TWriterGuard; #else template struct TTracelessOps : public TOps { template static void Acquire(T* t) noexcept { TOps::Acquire(t); NDetail::RecordSpinLockReleased(); } template static void Release(T* t) noexcept { NDetail::RecordSpinLockAcquired(); TOps::Release(t); } template requires requires (T* t) { { TOps::TryAcquire(t) } -> std::same_as; } static bool TryAcquire(T* t) noexcept { bool isAcquired = TOps::TryAcquire(t); if (isAcquired) { NDetail::RecordSpinLockReleased(); } return isAcquired; } }; template > using TTracelessGuard = TGuard>; template > using TTracelessInverseGuard = TInverseGuard>; template > using TTracelessTryGuard = TTryGuard>; template using TTracelessReaderGuard = TGuard>>; template using TTracelessWriterGuard = TGuard>>; #endif //////////////////////////////////////////////////////////////////////////////// template TTracelessGuard TracelessGuard(const T& mutex) { return {&mutex}; } template TTracelessTryGuard TracelessTryGuard(const T& mutex) { return {&mutex}; } template TTracelessReaderGuard TracelessReaderGuard(const T& mutex) { return {&mutex}; } template TTracelessWriterGuard TracelessWriterGuard(const T& mutex) { return {&mutex}; } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NThreading::NPrivate