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_server_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_server_session_semaphore.cpp')
-rw-r--r-- | library/cpp/messagebus/remote_server_session_semaphore.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/messagebus/remote_server_session_semaphore.cpp b/library/cpp/messagebus/remote_server_session_semaphore.cpp index 1db0a4e41d..6094a3586e 100644 --- a/library/cpp/messagebus/remote_server_session_semaphore.cpp +++ b/library/cpp/messagebus/remote_server_session_semaphore.cpp @@ -1,59 +1,59 @@ #include "remote_server_session_semaphore.h" #include <util/stream/output.h> -#include <util/system/yassert.h> - -using namespace NBus; -using namespace NBus::NPrivate; - -TRemoteServerSessionSemaphore::TRemoteServerSessionSemaphore( +#include <util/system/yassert.h> + +using namespace NBus; +using namespace NBus::NPrivate; + +TRemoteServerSessionSemaphore::TRemoteServerSessionSemaphore( TAtomicBase limitCount, TAtomicBase limitSize, const char* name) - : Name(name) - , LimitCount(limitCount) - , LimitSize(limitSize) - , CurrentCount(0) - , CurrentSize(0) - , PausedByUser(0) - , StopSignal(0) -{ + : Name(name) + , LimitCount(limitCount) + , LimitSize(limitSize) + , CurrentCount(0) + , CurrentSize(0) + , PausedByUser(0) + , StopSignal(0) +{ Y_VERIFY(limitCount > 0, "limit must be > 0"); Y_UNUSED(Name); -} - +} + TRemoteServerSessionSemaphore::~TRemoteServerSessionSemaphore() { Y_VERIFY(AtomicGet(CurrentCount) == 0); - // TODO: fix spider and enable + // TODO: fix spider and enable //Y_VERIFY(AtomicGet(CurrentSize) == 0); -} - -bool TRemoteServerSessionSemaphore::TryWait() { +} + +bool TRemoteServerSessionSemaphore::TryWait() { if (Y_UNLIKELY(AtomicGet(StopSignal))) - return true; - if (AtomicGet(PausedByUser)) - return false; - if (AtomicGet(CurrentCount) < LimitCount && (LimitSize < 0 || AtomicGet(CurrentSize) < LimitSize)) - return true; - return false; -} - -void TRemoteServerSessionSemaphore::IncrementMultiple(TAtomicBase count, TAtomicBase size) { - AtomicAdd(CurrentCount, count); - AtomicAdd(CurrentSize, size); - Updated(); -} - -void TRemoteServerSessionSemaphore::ReleaseMultiple(TAtomicBase count, TAtomicBase size) { - AtomicSub(CurrentCount, count); - AtomicSub(CurrentSize, size); - Updated(); -} - -void TRemoteServerSessionSemaphore::Stop() { - AtomicSet(StopSignal, 1); - Updated(); -} - -void TRemoteServerSessionSemaphore::PauseByUsed(bool pause) { - AtomicSet(PausedByUser, pause); - Updated(); -} + return true; + if (AtomicGet(PausedByUser)) + return false; + if (AtomicGet(CurrentCount) < LimitCount && (LimitSize < 0 || AtomicGet(CurrentSize) < LimitSize)) + return true; + return false; +} + +void TRemoteServerSessionSemaphore::IncrementMultiple(TAtomicBase count, TAtomicBase size) { + AtomicAdd(CurrentCount, count); + AtomicAdd(CurrentSize, size); + Updated(); +} + +void TRemoteServerSessionSemaphore::ReleaseMultiple(TAtomicBase count, TAtomicBase size) { + AtomicSub(CurrentCount, count); + AtomicSub(CurrentSize, size); + Updated(); +} + +void TRemoteServerSessionSemaphore::Stop() { + AtomicSet(StopSignal, 1); + Updated(); +} + +void TRemoteServerSessionSemaphore::PauseByUsed(bool pause) { + AtomicSet(PausedByUser, pause); + Updated(); +} |