diff options
author | kimkim <kimkim@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
commit | 13f84424ed9975f6827d9786087c6fe6ea265cda (patch) | |
tree | b94acc282c49a5de96b9e3e19feead21736f3273 /util/system/condvar_ut.cpp | |
parent | 35f29a67a6b8e50e1826c837330086049114c5ba (diff) | |
download | ydb-13f84424ed9975f6827d9786087c6fe6ea265cda.tar.gz |
Restoring authorship annotation for <kimkim@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/condvar_ut.cpp')
-rw-r--r-- | util/system/condvar_ut.cpp | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/util/system/condvar_ut.cpp b/util/system/condvar_ut.cpp index 5130a18d32..7c1c85a26a 100644 --- a/util/system/condvar_ut.cpp +++ b/util/system/condvar_ut.cpp @@ -3,45 +3,45 @@ #include "condvar.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/system/atomic.h> #include <util/system/atomic_ops.h> #include <util/thread/pool.h> - + class TCondVarTest: public TTestBase { - UNIT_TEST_SUITE(TCondVarTest); + UNIT_TEST_SUITE(TCondVarTest); UNIT_TEST(TestBasics) UNIT_TEST(TestSyncronize) - UNIT_TEST_SUITE_END(); - - struct TSharedData { - TSharedData() - : stopWaiting(false) - , in(0) - , out(0) - , waited(0) - , failed(false) - { - } - - TMutex mutex; - TCondVar condVar1; - TCondVar condVar2; - + UNIT_TEST_SUITE_END(); + + struct TSharedData { + TSharedData() + : stopWaiting(false) + , in(0) + , out(0) + , waited(0) + , failed(false) + { + } + + TMutex mutex; + TCondVar condVar1; + TCondVar condVar2; + TAtomic stopWaiting; - + TAtomic in; TAtomic out; - + TAtomic waited; - - bool failed; - }; - + + bool failed; + }; + class TThreadTask: public IObjectInQueue { public: using PFunc = void (TThreadTask::*)(void); - + TThreadTask(PFunc func, size_t id, size_t totalIds, TSharedData& data) : Func_(func) , Id_(id) @@ -49,20 +49,20 @@ class TCondVarTest: public TTestBase { , Data_(data) { } - + void Process(void*) override { THolder<TThreadTask> This(this); (this->*Func_)(); } - + #define FAIL_ASSERT(cond) \ if (!(cond)) { \ Data_.failed = true; \ - } + } void RunBasics() { Y_ASSERT(TotalIds_ == 3); - + if (Id_ < 2) { TGuard<TMutex> guard(Data_.mutex); while (!AtomicGet(Data_.stopWaiting)) { @@ -109,10 +109,10 @@ class TCondVarTest: public TTestBase { AtomicIncrement(Data_.waited); while (AtomicGet(Data_.in) < TotalIds_) { bool res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1)); - FAIL_ASSERT(res == true); - } - } - + FAIL_ASSERT(res == true); + } + } + AtomicIncrement(Data_.out); if (AtomicGet(Data_.out) == TotalIds_) { AtomicSet(Data_.in, 0); @@ -121,10 +121,10 @@ class TCondVarTest: public TTestBase { while (AtomicGet(Data_.out) < TotalIds_) { bool res = Data_.condVar2.WaitT(Data_.mutex, TDuration::Seconds(1)); FAIL_ASSERT(res == true); - } - } + } + } } - + FAIL_ASSERT(AtomicGet(Data_.waited) == (TotalIds_ - 1) * 10); } @@ -157,15 +157,15 @@ class TCondVarTest: public TTestBase { FAIL_ASSERT(Data_.waited == (TotalIds_ - 1) * 10); } -#undef FAIL_ASSERT - +#undef FAIL_ASSERT + private: PFunc Func_; size_t Id_; TAtomicBase TotalIds_; TSharedData& Data_; - }; - + }; + private: #define RUN_CYCLE(what, count) \ Q_.Start(count); \ @@ -176,11 +176,11 @@ private: bool b = Data_.failed; \ Data_.failed = false; \ UNIT_ASSERT(!b); - + inline void TestBasics() { RUN_CYCLE(RunBasics, 3); } - + inline void TestBasicsWithPredicate() { RUN_CYCLE(RunBasicsWithPredicate, 3); } @@ -195,6 +195,6 @@ private: #undef RUN_CYCLE TSharedData Data_; TThreadPool Q_; -}; - -UNIT_TEST_SUITE_REGISTRATION(TCondVarTest); +}; + +UNIT_TEST_SUITE_REGISTRATION(TCondVarTest); |