#pragma once #include "guard.h" #include "defaults.h" #include class TRWMutex { public: TRWMutex(); ~TRWMutex(); void AcquireRead() noexcept; bool TryAcquireRead() noexcept; void ReleaseRead() noexcept; void AcquireWrite() noexcept; bool TryAcquireWrite() noexcept; void ReleaseWrite() noexcept; void Release() noexcept; private: class TImpl; THolder Impl_; }; template struct TReadGuardOps { static inline void Acquire(T* t) noexcept { t->AcquireRead(); } static inline void Release(T* t) noexcept { t->ReleaseRead(); } }; template struct TTryReadGuardOps: public TReadGuardOps { static inline bool TryAcquire(T* t) noexcept { return t->TryAcquireRead(); } }; template struct TWriteGuardOps { static inline void Acquire(T* t) noexcept { t->AcquireWrite(); } static inline void Release(T* t) noexcept { t->ReleaseWrite(); } }; template struct TTryWriteGuardOps: public TWriteGuardOps { static inline bool TryAcquire(T* t) noexcept { return t->TryAcquireWrite(); } }; template using TReadGuardBase = TGuard>; template using TTryReadGuardBase = TTryGuard>; template using TWriteGuardBase = TGuard>; template using TTryWriteGuardBase = TTryGuard>; using TReadGuard = TReadGuardBase; using TTryReadGuard = TTryReadGuardBase; using TWriteGuard = TWriteGuardBase; using TTryWriteGuard = TTryWriteGuardBase;