diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | c2a1af049e9deca890e9923abe64fe6c59060348 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/messagebus/remote_client_session_semaphore.cpp | |
parent | 1f553f46fb4f3c5eec631352cdd900a0709016af (diff) | |
download | ydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/remote_client_session_semaphore.cpp')
-rw-r--r-- | library/cpp/messagebus/remote_client_session_semaphore.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/library/cpp/messagebus/remote_client_session_semaphore.cpp b/library/cpp/messagebus/remote_client_session_semaphore.cpp index f1d02cc5c2..f877ed4257 100644 --- a/library/cpp/messagebus/remote_client_session_semaphore.cpp +++ b/library/cpp/messagebus/remote_client_session_semaphore.cpp @@ -1,67 +1,67 @@ #include "remote_client_session_semaphore.h" #include <util/stream/output.h> -#include <util/system/yassert.h> - -using namespace NBus; -using namespace NBus::NPrivate; - -TRemoteClientSessionSemaphore::TRemoteClientSessionSemaphore(TAtomicBase limit, const char* name) - : Name(name) - , Limit(limit) - , Current(0) - , StopSignal(0) -{ +#include <util/system/yassert.h> + +using namespace NBus; +using namespace NBus::NPrivate; + +TRemoteClientSessionSemaphore::TRemoteClientSessionSemaphore(TAtomicBase limit, const char* name) + : Name(name) + , Limit(limit) + , Current(0) + , StopSignal(0) +{ Y_VERIFY(limit > 0, "limit must be > 0"); Y_UNUSED(Name); -} - +} + TRemoteClientSessionSemaphore::~TRemoteClientSessionSemaphore() { Y_VERIFY(AtomicGet(Current) == 0); -} - -bool TRemoteClientSessionSemaphore::TryAcquire() { - if (!TryWait()) { - return false; - } - - AtomicIncrement(Current); - return true; -} - -bool TRemoteClientSessionSemaphore::TryWait() { - if (AtomicGet(Current) < Limit) - return true; +} + +bool TRemoteClientSessionSemaphore::TryAcquire() { + if (!TryWait()) { + return false; + } + + AtomicIncrement(Current); + return true; +} + +bool TRemoteClientSessionSemaphore::TryWait() { + if (AtomicGet(Current) < Limit) + return true; if (Y_UNLIKELY(AtomicGet(StopSignal))) - return true; - return false; -} - -void TRemoteClientSessionSemaphore::Acquire() { - Wait(); - - Increment(); -} - -void TRemoteClientSessionSemaphore::Increment() { - IncrementMultiple(1); -} - -void TRemoteClientSessionSemaphore::IncrementMultiple(TAtomicBase count) { - AtomicAdd(Current, count); - Updated(); -} - -void TRemoteClientSessionSemaphore::Release() { - ReleaseMultiple(1); -} - -void TRemoteClientSessionSemaphore::ReleaseMultiple(TAtomicBase count) { - AtomicSub(Current, count); - Updated(); -} - -void TRemoteClientSessionSemaphore::Stop() { - AtomicSet(StopSignal, 1); - Updated(); -} + return true; + return false; +} + +void TRemoteClientSessionSemaphore::Acquire() { + Wait(); + + Increment(); +} + +void TRemoteClientSessionSemaphore::Increment() { + IncrementMultiple(1); +} + +void TRemoteClientSessionSemaphore::IncrementMultiple(TAtomicBase count) { + AtomicAdd(Current, count); + Updated(); +} + +void TRemoteClientSessionSemaphore::Release() { + ReleaseMultiple(1); +} + +void TRemoteClientSessionSemaphore::ReleaseMultiple(TAtomicBase count) { + AtomicSub(Current, count); + Updated(); +} + +void TRemoteClientSessionSemaphore::Stop() { + AtomicSet(StopSignal, 1); + Updated(); +} |