aboutsummaryrefslogtreecommitdiffstats
path: root/util/thread/lfstack.h
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
commit31773f157bf8164364649b5f470f52dece0a4317 (patch)
tree33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /util/thread/lfstack.h
parent2c7938962d8689e175574fc1e817c05049f27905 (diff)
parenteff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff)
downloadydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz
Merge branch 'rightlib' into mergelibs-241120-1113
Diffstat (limited to 'util/thread/lfstack.h')
-rw-r--r--util/thread/lfstack.h15
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;