aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/misc/test_sync.h
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/misc/test_sync.h
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/misc/test_sync.h')
-rw-r--r--library/cpp/messagebus/misc/test_sync.h134
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 be3f4f20b8..8e5aa212aa 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);
- }
-};
+ }
+};