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/misc/test_sync.h | |
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/misc/test_sync.h')
-rw-r--r-- | library/cpp/messagebus/misc/test_sync.h | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/library/cpp/messagebus/misc/test_sync.h b/library/cpp/messagebus/misc/test_sync.h index 8e5aa212aa..be3f4f20b8 100644 --- a/library/cpp/messagebus/misc/test_sync.h +++ b/library/cpp/messagebus/misc/test_sync.h @@ -1,75 +1,75 @@ -#pragma once - +#pragma once + #include <util/system/condvar.h> -#include <util/system/mutex.h> - -class TTestSync { -private: - unsigned Current; - - TMutex Mutex; - TCondVar CondVar; - -public: - TTestSync() - : Current(0) +#include <util/system/mutex.h> + +class TTestSync { +private: + unsigned Current; + + TMutex Mutex; + TCondVar CondVar; + +public: + TTestSync() + : Current(0) { } - - void Inc() { - TGuard<TMutex> guard(Mutex); - - DoInc(); - CondVar.BroadCast(); - } - - unsigned Get() { - TGuard<TMutex> guard(Mutex); - - return Current; - } - - void WaitFor(unsigned n) { - TGuard<TMutex> guard(Mutex); - + + void Inc() { + TGuard<TMutex> guard(Mutex); + + DoInc(); + CondVar.BroadCast(); + } + + unsigned Get() { + TGuard<TMutex> guard(Mutex); + + return Current; + } + + void WaitFor(unsigned n) { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(Current <= n, "too late, waiting for %d, already %d", n, Current); - - while (n > Current) { - CondVar.WaitI(Mutex); - } - } - - void WaitForAndIncrement(unsigned n) { - TGuard<TMutex> guard(Mutex); - + + while (n > Current) { + CondVar.WaitI(Mutex); + } + } + + void WaitForAndIncrement(unsigned n) { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(Current <= n, "too late, waiting for %d, already %d", n, Current); - - while (n > Current) { - CondVar.WaitI(Mutex); - } - - DoInc(); - CondVar.BroadCast(); - } - - void CheckAndIncrement(unsigned n) { - TGuard<TMutex> guard(Mutex); - + + while (n > Current) { + CondVar.WaitI(Mutex); + } + + DoInc(); + CondVar.BroadCast(); + } + + void CheckAndIncrement(unsigned n) { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(Current == n, "must be %d, currently %d", n, Current); - - DoInc(); - CondVar.BroadCast(); - } - - void Check(unsigned n) { - TGuard<TMutex> guard(Mutex); - + + DoInc(); + CondVar.BroadCast(); + } + + void Check(unsigned n) { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(Current == n, "must be %d, currently %d", n, Current); - } - -private: - void DoInc() { - unsigned r = ++Current; + } + +private: + void DoInc() { + unsigned r = ++Current; Y_UNUSED(r); - } -}; + } +}; |