diff options
author | eeight <eeight@yandex-team.ru> | 2022-05-11 10:40:18 +0300 |
---|---|---|
committer | eeight <eeight@yandex-team.ru> | 2022-05-11 10:40:18 +0300 |
commit | 05a6fea78142058210511273b3ece21050ad137b (patch) | |
tree | 628e5702bd4d5597541b4302bd80af1295053aa4 /util/thread | |
parent | 3548eb45b1cf56fc87c6e908d3446b633f68d42e (diff) | |
download | ydb-05a6fea78142058210511273b3ece21050ad137b.tar.gz |
IGNIETFERRO-1105 TAtomic -> std::atomic in util/generic/* and threadpool
ref:39a714b781c60dca9e3b946d870971076e14ab7c
Diffstat (limited to 'util/thread')
-rw-r--r-- | util/thread/pool.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp index 05fad02e9b..fafb56ec40 100644 --- a/util/thread/pool.cpp +++ b/util/thread/pool.cpp @@ -18,7 +18,6 @@ #include <util/system/event.h> #include <util/system/mutex.h> -#include <util/system/atomic.h> #include <util/system/condvar.h> #include <util/system/thread.h> @@ -76,7 +75,7 @@ public: , Blocking(params.Blocking_) , Catching(params.Catching_) , Namer(params) - , ShouldTerminate(1) + , ShouldTerminate(true) , MaxQueueSize(0) , ThreadCountExpected(0) , ThreadCountReal(0) @@ -98,7 +97,7 @@ public: } inline bool Add(IObjectInQueue* obj) { - if (AtomicGet(ShouldTerminate)) { + if (ShouldTerminate.load()) { return false; } @@ -110,14 +109,14 @@ public: } with_lock (QueueMutex) { - while (MaxQueueSize > 0 && Queue.Size() >= MaxQueueSize && !AtomicGet(ShouldTerminate)) { + while (MaxQueueSize > 0 && Queue.Size() >= MaxQueueSize && !ShouldTerminate.load()) { if (!Blocking) { return false; } QueuePopCond.Wait(QueueMutex); } - if (AtomicGet(ShouldTerminate)) { + if (ShouldTerminate.load()) { return false; } @@ -157,7 +156,7 @@ public: private: inline void Start(size_t num, size_t maxque) { - AtomicSet(ShouldTerminate, 0); + ShouldTerminate.store(false); MaxQueueSize = maxque; ThreadCountExpected = num; @@ -174,7 +173,7 @@ private: } inline void Stop() { - AtomicSet(ShouldTerminate, 1); + ShouldTerminate.store(true); with_lock (QueueMutex) { QueuePopCond.BroadCast(); @@ -212,11 +211,11 @@ private: IObjectInQueue* job = nullptr; with_lock (QueueMutex) { - while (Queue.Empty() && !AtomicGet(ShouldTerminate)) { + while (Queue.Empty() && !ShouldTerminate.load()) { QueuePushCond.Wait(QueueMutex); } - if (AtomicGet(ShouldTerminate) && Queue.Empty()) { + if (ShouldTerminate.load() && Queue.Empty()) { tsr.Destroy(); break; @@ -264,7 +263,7 @@ private: TCondVar StopCond; TJobQueue Queue; TVector<TThreadRef> Tharr; - TAtomic ShouldTerminate; + std::atomic<bool> ShouldTerminate; size_t MaxQueueSize; size_t ThreadCountExpected; size_t ThreadCountReal; |