aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/cc_semaphore_ut.cpp
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/cc_semaphore_ut.cpp
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/cc_semaphore_ut.cpp')
-rw-r--r--library/cpp/messagebus/cc_semaphore_ut.cpp70
1 files changed, 35 insertions, 35 deletions
diff --git a/library/cpp/messagebus/cc_semaphore_ut.cpp b/library/cpp/messagebus/cc_semaphore_ut.cpp
index 206bb7c96a..5359ce2f7f 100644
--- a/library/cpp/messagebus/cc_semaphore_ut.cpp
+++ b/library/cpp/messagebus/cc_semaphore_ut.cpp
@@ -1,45 +1,45 @@
#include <library/cpp/testing/unittest/registar.h>
-
-#include "cc_semaphore.h"
-
+
+#include "cc_semaphore.h"
+
#include <util/system/atomic.h>
-namespace {
+namespace {
struct TTestSemaphore: public TComplexConditionSemaphore<TTestSemaphore> {
- TAtomic Current;
-
+ TAtomic Current;
+
TTestSemaphore()
: Current(0)
{
}
-
- bool TryWait() {
- return AtomicGet(Current) > 0;
- }
-
- void Aquire() {
- Wait();
- AtomicDecrement(Current);
- }
-
- void Release() {
- AtomicIncrement(Current);
- Updated();
- }
- };
-}
-
+
+ bool TryWait() {
+ return AtomicGet(Current) > 0;
+ }
+
+ void Aquire() {
+ Wait();
+ AtomicDecrement(Current);
+ }
+
+ void Release() {
+ AtomicIncrement(Current);
+ Updated();
+ }
+ };
+}
+
Y_UNIT_TEST_SUITE(TComplexConditionSemaphore) {
Y_UNIT_TEST(Simple) {
- TTestSemaphore sema;
- UNIT_ASSERT(!sema.TryWait());
- sema.Release();
- UNIT_ASSERT(sema.TryWait());
- sema.Release();
- UNIT_ASSERT(sema.TryWait());
- sema.Aquire();
- UNIT_ASSERT(sema.TryWait());
- sema.Aquire();
- UNIT_ASSERT(!sema.TryWait());
- }
-}
+ TTestSemaphore sema;
+ UNIT_ASSERT(!sema.TryWait());
+ sema.Release();
+ UNIT_ASSERT(sema.TryWait());
+ sema.Release();
+ UNIT_ASSERT(sema.TryWait());
+ sema.Aquire();
+ UNIT_ASSERT(sema.TryWait());
+ sema.Aquire();
+ UNIT_ASSERT(!sema.TryWait());
+ }
+}