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/lfstack.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/lfstack.h')
-rw-r--r-- | util/thread/lfstack.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/util/thread/lfstack.h b/util/thread/lfstack.h index effde7c706..b81c6403c9 100644 --- a/util/thread/lfstack.h +++ b/util/thread/lfstack.h @@ -30,12 +30,14 @@ class TLockFreeStack: TNonCopyable { void TryToFreeMemory() { TNode* current = FreePtr.load(std::memory_order_acquire); - if (!current) + if (!current) { return; + } if (DequeueCount.load() == 1) { // node current is in free list, we are the last thread so try to cleanup - if (FreePtr.compare_exchange_strong(current, nullptr)) + if (FreePtr.compare_exchange_strong(current, nullptr)) { EraseList(current); + } } } void EraseList(TNode* p) { @@ -54,8 +56,9 @@ class TLockFreeStack: TNonCopyable { // act as if *this != expected even if they are equal. // When a compare-and-exchange is in a loop, the weak version will yield better // performance on some platforms. - if (Head.compare_exchange_weak(headValue, head)) + if (Head.compare_exchange_weak(headValue, head)) { break; + } } } template <class U> @@ -115,8 +118,9 @@ public: // Dequeue()s in progress, put node to free list for (TNode* freePtr = FreePtr.load(std::memory_order_acquire);;) { current->Next.store(freePtr, std::memory_order_release); - if (FreePtr.compare_exchange_weak(freePtr, current)) + if (FreePtr.compare_exchange_weak(freePtr, current)) { break; + } } } return true; @@ -151,8 +155,9 @@ public: } for (TNode* freePtr = FreePtr.load(std::memory_order_acquire);;) { currentLast->Next.store(freePtr, std::memory_order_release); - if (FreePtr.compare_exchange_weak(freePtr, current)) + if (FreePtr.compare_exchange_weak(freePtr, current)) { break; + } } } return; |