diff options
author | spacelord <[email protected]> | 2022-02-10 16:48:15 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:48:15 +0300 |
commit | 16747e4f77455cca4932df21eb76f12cb0a97a5c (patch) | |
tree | 4dd6da4102d99d0d69dec53c1050d290a850a9f2 /util/thread | |
parent | a817f5de12611ec73085eba17f8ec7740a46bdb7 (diff) |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'util/thread')
-rw-r--r-- | util/thread/pool.cpp | 42 | ||||
-rw-r--r-- | util/thread/pool_ut.cpp | 52 |
2 files changed, 47 insertions, 47 deletions
diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp index 05fad02e9b9..e8420eb3c88 100644 --- a/util/thread/pool.cpp +++ b/util/thread/pool.cpp @@ -67,7 +67,7 @@ TThreadFactoryHolder::TThreadFactoryHolder() noexcept class TThreadPool::TImpl: public TIntrusiveListItem<TImpl>, public IThreadFactory::IThreadAble { using TTsr = IThreadPool::TTsr; - using TJobQueue = TFastQueue<IObjectInQueue*>; + using TJobQueue = TFastQueue<IObjectInQueue*>; using TThreadRef = THolder<IThreadFactory::IThread>; public: @@ -643,20 +643,20 @@ size_t TSimpleThreadPool::Size() const noexcept { namespace { class TOwnedObjectInQueue: public IObjectInQueue { - private: - THolder<IObjectInQueue> Owned; - - public: + private: + THolder<IObjectInQueue> Owned; + + public: TOwnedObjectInQueue(THolder<IObjectInQueue> owned) : Owned(std::move(owned)) - { - } - + { + } + void Process(void* data) override { - THolder<TOwnedObjectInQueue> self(this); - Owned->Process(data); - } - }; + THolder<TOwnedObjectInQueue> self(this); + Owned->Process(data); + } + }; } void IThreadPool::SafeAdd(IObjectInQueue* obj) { @@ -665,17 +665,17 @@ void IThreadPool::SafeAdd(IObjectInQueue* obj) { void IThreadPool::SafeAddAndOwn(THolder<IObjectInQueue> obj) { Y_ENSURE_EX(AddAndOwn(std::move(obj)), TThreadPoolException() << TStringBuf("can not add to queue and own")); -} - +} + bool IThreadPool::AddAndOwn(THolder<IObjectInQueue> obj) { auto owner = MakeHolder<TOwnedObjectInQueue>(std::move(obj)); - bool added = Add(owner.Get()); - if (added) { + bool added = Add(owner.Get()); + if (added) { Y_UNUSED(owner.Release()); - } - return added; -} - + } + return added; +} + using IThread = IThreadFactory::IThread; using IThreadAble = IThreadFactory::IThreadAble; @@ -721,7 +721,7 @@ namespace { TSystemEvent StartEvent_; }; - using TThreadImplRef = TIntrusivePtr<TThreadImpl>; + using TThreadImplRef = TIntrusivePtr<TThreadImpl>; public: inline TPoolThread(IThreadPool* parent) diff --git a/util/thread/pool_ut.cpp b/util/thread/pool_ut.cpp index 893770d0c47..07b0e0a235f 100644 --- a/util/thread/pool_ut.cpp +++ b/util/thread/pool_ut.cpp @@ -32,24 +32,24 @@ struct TThreadPoolTest { }; struct TOwnedTask: public IObjectInQueue { - bool& Processed; - bool& Destructed; - - TOwnedTask(bool& processed, bool& destructed) - : Processed(processed) - , Destructed(destructed) - { - } - + bool& Processed; + bool& Destructed; + + TOwnedTask(bool& processed, bool& destructed) + : Processed(processed) + , Destructed(destructed) + { + } + ~TOwnedTask() override { - Destructed = true; - } - - void Process(void*) override { - Processed = true; - } - }; - + Destructed = true; + } + + void Process(void*) override { + Processed = true; + } + }; + inline void TestAnyQueue(IThreadPool* queue, size_t queueSize = 1000) { TReallyFastRng32 rand(17); const size_t cnt = 1000; @@ -112,18 +112,18 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { t.TestAnyQueue(&q); } } - + Y_UNIT_TEST(TestAddAndOwn) { TThreadPool q; - q.Start(2); - bool processed = false; - bool destructed = false; + q.Start(2); + bool processed = false; + bool destructed = false; q.SafeAddAndOwn(MakeHolder<TThreadPoolTest::TOwnedTask>(processed, destructed)); - q.Stop(); - - UNIT_ASSERT_C(processed, "Not processed"); - UNIT_ASSERT_C(destructed, "Not destructed"); - } + q.Stop(); + + UNIT_ASSERT_C(processed, "Not processed"); + UNIT_ASSERT_C(destructed, "Not destructed"); + } Y_UNIT_TEST(TestAddFunc) { TFailAddQueue queue; |