diff options
author | galtsev <galtsev@yandex-team.ru> | 2022-02-10 16:49:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:32 +0300 |
commit | b3770c4662dc5be7135e21630d44f69d0787c167 (patch) | |
tree | e8fca9ae46f702aa7e1d2a7fdb3d4e969ae2aff7 /util/system | |
parent | d6a9908bd3435a3571dfcb969988eba7a690802b (diff) | |
download | ydb-b3770c4662dc5be7135e21630d44f69d0787c167.tar.gz |
Restoring authorship annotation for <galtsev@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/mutex.cpp | 2 | ||||
-rw-r--r-- | util/system/rwlock.cpp | 140 | ||||
-rw-r--r-- | util/system/rwlock.h | 4 |
3 files changed, 73 insertions, 73 deletions
diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 4041402db9..d175f0f792 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -20,7 +20,7 @@ public: inline T() { int result; - + memset(&Attr, 0, sizeof(Attr)); result = pthread_mutexattr_init(&Attr); if (result != 0) { diff --git a/util/system/rwlock.cpp b/util/system/rwlock.cpp index bb3dcbf188..53e0357d39 100644 --- a/util/system/rwlock.cpp +++ b/util/system/rwlock.cpp @@ -2,39 +2,39 @@ #include "mutex.h" #include "condvar.h" -#include <util/generic/yexception.h> - +#include <util/generic/yexception.h> + #if defined(_unix_) #include <errno.h> #include <pthread.h> -#endif - +#endif + #if defined(_win_) || defined(_darwin_) //darwin rwlocks not recursive -class TRWMutex::TImpl { +class TRWMutex::TImpl { public: TImpl(); ~TImpl(); - + void AcquireRead() noexcept; bool TryAcquireRead() noexcept; void ReleaseRead() noexcept; - + void AcquireWrite() noexcept; bool TryAcquireWrite() noexcept; void ReleaseWrite() noexcept; - + void Release() noexcept; - + private: TMutex Lock_; int State_; TCondVar ReadCond_; TCondVar WriteCond_; int BlockedWriters_; -}; - -TRWMutex::TImpl::TImpl() +}; + +TRWMutex::TImpl::TImpl() : State_(0) , BlockedWriters_(0) { @@ -43,8 +43,8 @@ TRWMutex::TImpl::TImpl() TRWMutex::TImpl::~TImpl() { Y_VERIFY(State_ == 0, "failure, State_ != 0"); Y_VERIFY(BlockedWriters_ == 0, "failure, BlockedWriters_ != 0"); -} - +} + void TRWMutex::TImpl::AcquireRead() noexcept { with_lock (Lock_) { while (BlockedWriters_ || State_ < 0) { @@ -140,111 +140,111 @@ void TRWMutex::TImpl::Release() noexcept { ReadCond_.Signal(); } } -} - -#else /* POSIX threads */ - -class TRWMutex::TImpl { +} + +#else /* POSIX threads */ + +class TRWMutex::TImpl { public: TImpl(); ~TImpl(); - + void AcquireRead() noexcept; bool TryAcquireRead() noexcept; void ReleaseRead() noexcept; - + void AcquireWrite() noexcept; bool TryAcquireWrite() noexcept; void ReleaseWrite() noexcept; - + void Release() noexcept; - + private: pthread_rwlock_t Lock_; -}; - -TRWMutex::TImpl::TImpl() { +}; + +TRWMutex::TImpl::TImpl() { int result = pthread_rwlock_init(&Lock_, nullptr); - if (result != 0) { + if (result != 0) { ythrow yexception() << "rwlock init failed (" << LastSystemErrorText(result) << ")"; - } -} - + } +} + TRWMutex::TImpl::~TImpl() { const int result = pthread_rwlock_destroy(&Lock_); Y_VERIFY(result == 0, "rwlock destroy failed (%s)", LastSystemErrorText(result)); -} - +} + void TRWMutex::TImpl::AcquireRead() noexcept { const int result = pthread_rwlock_rdlock(&Lock_); Y_VERIFY(result == 0, "rwlock rdlock failed (%s)", LastSystemErrorText(result)); -} - +} + bool TRWMutex::TImpl::TryAcquireRead() noexcept { const int result = pthread_rwlock_tryrdlock(&Lock_); Y_VERIFY(result == 0 || result == EBUSY, "rwlock tryrdlock failed (%s)", LastSystemErrorText(result)); - return result == 0; -} - + return result == 0; +} + void TRWMutex::TImpl::ReleaseRead() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock (read) unlock failed (%s)", LastSystemErrorText(result)); } - + void TRWMutex::TImpl::AcquireWrite() noexcept { const int result = pthread_rwlock_wrlock(&Lock_); Y_VERIFY(result == 0, "rwlock wrlock failed (%s)", LastSystemErrorText(result)); -} - +} + bool TRWMutex::TImpl::TryAcquireWrite() noexcept { const int result = pthread_rwlock_trywrlock(&Lock_); Y_VERIFY(result == 0 || result == EBUSY, "rwlock trywrlock failed (%s)", LastSystemErrorText(result)); - return result == 0; -} - + return result == 0; +} + void TRWMutex::TImpl::ReleaseWrite() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock (write) unlock failed (%s)", LastSystemErrorText(result)); -} - +} + void TRWMutex::TImpl::Release() noexcept { const int result = pthread_rwlock_unlock(&Lock_); Y_VERIFY(result == 0, "rwlock unlock failed (%s)", LastSystemErrorText(result)); -} - +} + #endif - -TRWMutex::TRWMutex() - : Impl_(new TImpl()) -{ -} - + +TRWMutex::TRWMutex() + : Impl_(new TImpl()) +{ +} + TRWMutex::~TRWMutex() = default; - + void TRWMutex::AcquireRead() noexcept { - Impl_->AcquireRead(); -} + Impl_->AcquireRead(); +} bool TRWMutex::TryAcquireRead() noexcept { - return Impl_->TryAcquireRead(); -} + return Impl_->TryAcquireRead(); +} void TRWMutex::ReleaseRead() noexcept { - Impl_->ReleaseRead(); -} - + Impl_->ReleaseRead(); +} + void TRWMutex::AcquireWrite() noexcept { - Impl_->AcquireWrite(); -} + Impl_->AcquireWrite(); +} bool TRWMutex::TryAcquireWrite() noexcept { - return Impl_->TryAcquireWrite(); -} + return Impl_->TryAcquireWrite(); +} void TRWMutex::ReleaseWrite() noexcept { - Impl_->ReleaseWrite(); -} - + Impl_->ReleaseWrite(); +} + void TRWMutex::Release() noexcept { - Impl_->Release(); -} + Impl_->Release(); +} diff --git a/util/system/rwlock.h b/util/system/rwlock.h index 0bb9b3fe1c..924d459a06 100644 --- a/util/system/rwlock.h +++ b/util/system/rwlock.h @@ -3,8 +3,8 @@ #include "guard.h" #include "defaults.h" -#include <util/generic/ptr.h> - +#include <util/generic/ptr.h> + class TRWMutex { public: TRWMutex(); |