diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-11-20 17:37:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 17:37:57 +0000 |
commit | f76323e9b295c15751e51e3443aa47a36bee8023 (patch) | |
tree | 4113c8cad473a33e0f746966e0cf087252fa1d7a /util/thread/lfqueue.h | |
parent | 753ecb8d410a4cb459c26f3a0082fb2d1724fe63 (diff) | |
parent | a7b9a6afea2a9d7a7bfac4c5eb4c1a8e60adb9e6 (diff) | |
download | ydb-f76323e9b295c15751e51e3443aa47a36bee8023.tar.gz |
Merge pull request #11788 from ydb-platform/mergelibs-241120-1113
Library import 241120-1113
Diffstat (limited to 'util/thread/lfqueue.h')
-rw-r--r-- | util/thread/lfqueue.h | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/util/thread/lfqueue.h b/util/thread/lfqueue.h index bfe88013fc..089f234741 100644 --- a/util/thread/lfqueue.h +++ b/util/thread/lfqueue.h @@ -72,8 +72,9 @@ class TLockFreeQueue: public TNonCopyable { void TryToFreeAsyncMemory() { const auto keepCounter = FreeingTaskCounter.load(); TRootNode* current = FreePtr.load(std::memory_order_acquire); - if (current == nullptr) + if (current == nullptr) { return; + } if (FreememCounter.load() == 1) { // we are the last thread, try to cleanup // check if another thread have cleaned up @@ -103,8 +104,9 @@ class TLockFreeQueue: public TNonCopyable { toDelete->ToDelete.store(lst, std::memory_order_release); for (auto freePtr = FreePtr.load();;) { toDelete->NextFree.store(freePtr, std::memory_order_release); - if (FreePtr.compare_exchange_weak(freePtr, toDelete)) + if (FreePtr.compare_exchange_weak(freePtr, toDelete)) { break; + } } } void AsyncUnref(TRootNode* toDelete, TListNode* lst) { @@ -148,15 +150,17 @@ class TLockFreeQueue: public TNonCopyable { Tail->Next.store(newCopy, std::memory_order_release); newCopy = Copy; Copy = nullptr; // do not destroy prev try - if (!newTail) + if (!newTail) { newTail = Tail; // tried to invert same list + } break; } TListNode* newElem = new TListNode(ptr->Data, newCopy); newCopy = newElem; ptr = ptr->Next.load(std::memory_order_acquire); - if (!newTail) + if (!newTail) { newTail = newElem; + } } EraseList(Copy); // copy was useless Copy = newCopy; @@ -176,8 +180,9 @@ class TLockFreeQueue: public TNonCopyable { for (TListNode* node = head;; node = node->Next.load(std::memory_order_acquire)) { newRoot->IncCount(node->Data); - if (node == tail) + if (node == tail) { break; + } } if (JobQueue.compare_exchange_weak(curRoot, newRoot)) { @@ -251,8 +256,9 @@ public: } template <typename TIter> void EnqueueAll(TIter dataBegin, TIter dataEnd) { - if (dataBegin == dataEnd) + if (dataBegin == dataEnd) { return; + } TIter i = dataBegin; TListNode* node = new TListNode(*i); @@ -272,8 +278,9 @@ public: TListNode* tail = curRoot->PopQueue.load(std::memory_order_acquire); if (tail) { // has elems to pop - if (!newRoot) + if (!newRoot) { newRoot = new TRootNode; + } newRoot->PushQueue.store(curRoot->PushQueue.load(std::memory_order_acquire), std::memory_order_release); newRoot->PopQueue.store(tail->Next.load(std::memory_order_acquire), std::memory_order_release); @@ -294,8 +301,9 @@ public: return false; // no elems to pop } - if (!newRoot) + if (!newRoot) { newRoot = new TRootNode; + } newRoot->PushQueue.store(nullptr, std::memory_order_release); listInvertor.DoCopy(curRoot->PushQueue.load(std::memory_order_acquire)); newRoot->PopQueue.store(listInvertor.Copy, std::memory_order_release); |