aboutsummaryrefslogtreecommitdiffstats
path: root/util/thread
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit8cbc307de0221f84c80c42dcbe07d40727537e2c (patch)
tree625d5a673015d1df891e051033e9fcde5c7be4e5 /util/thread
parent30d1ef3941e0dc835be7609de5ebee66958f215a (diff)
downloadydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/thread')
-rw-r--r--util/thread/factory.cpp2
-rw-r--r--util/thread/fwd.cpp2
-rw-r--r--util/thread/fwd.h42
-rw-r--r--util/thread/lfqueue.h50
-rw-r--r--util/thread/lfqueue_ut.cpp12
-rw-r--r--util/thread/lfstack.h14
-rw-r--r--util/thread/lfstack_ut.cpp16
-rw-r--r--util/thread/pool.cpp18
-rw-r--r--util/thread/pool.h8
-rw-r--r--util/thread/pool_ut.cpp8
-rw-r--r--util/thread/singleton.h4
-rw-r--r--util/thread/singleton_ut.cpp4
12 files changed, 90 insertions, 90 deletions
diff --git a/util/thread/factory.cpp b/util/thread/factory.cpp
index 48e898f32d..0336a25876 100644
--- a/util/thread/factory.cpp
+++ b/util/thread/factory.cpp
@@ -35,7 +35,7 @@ namespace {
static void* ThreadProc(void* func) {
((IThreadAble*)(func))->Execute();
- return nullptr;
+ return nullptr;
}
private:
diff --git a/util/thread/fwd.cpp b/util/thread/fwd.cpp
index 4214b6df83..2261ef316c 100644
--- a/util/thread/fwd.cpp
+++ b/util/thread/fwd.cpp
@@ -1 +1 @@
-#include "fwd.h"
+#include "fwd.h"
diff --git a/util/thread/fwd.h b/util/thread/fwd.h
index 6f1caed21c..78f81c8c52 100644
--- a/util/thread/fwd.h
+++ b/util/thread/fwd.h
@@ -1,30 +1,30 @@
-#pragma once
-
-#include <stlfwd>
-
-struct TDefaultLFCounter;
-
-template <class T, class TCounter = TDefaultLFCounter>
-class TLockFreeQueue;
-
-template <class T, class TCounter = TDefaultLFCounter>
-class TAutoLockFreeQueue;
-
-template <class T>
+#pragma once
+
+#include <stlfwd>
+
+struct TDefaultLFCounter;
+
+template <class T, class TCounter = TDefaultLFCounter>
+class TLockFreeQueue;
+
+template <class T, class TCounter = TDefaultLFCounter>
+class TAutoLockFreeQueue;
+
+template <class T>
class TLockFreeStack;
-
+
class IThreadFactory;
-
-struct IObjectInQueue;
+
+struct IObjectInQueue;
class TThreadFactoryHolder;
-
-using TThreadFunction = std::function<void()>;
-
+
+using TThreadFunction = std::function<void()>;
+
class IThreadPool;
class TFakeThreadPool;
class TThreadPool;
class TAdaptiveThreadPool;
class TSimpleThreadPool;
-
-template <class TQueueType, class TSlave>
+
+template <class TQueueType, class TSlave>
class TThreadPoolBinder;
diff --git a/util/thread/lfqueue.h b/util/thread/lfqueue.h
index ab523631e4..116e1d4c85 100644
--- a/util/thread/lfqueue.h
+++ b/util/thread/lfqueue.h
@@ -1,7 +1,7 @@
#pragma once
-#include "fwd.h"
-
+#include "fwd.h"
+
#include <util/generic/ptr.h>
#include <util/system/atomic.h>
#include <util/system/yassert.h>
@@ -23,8 +23,8 @@ struct TDefaultLFCounter {
// @tparam TCounter, a observer class to count number of items in queue
// be carifull, IncCount and DecCount can be called on a moved object and
// it is TCounter class responsibility to check validity of passed object
-template <class T, class TCounter>
-class TLockFreeQueue: public TNonCopyable {
+template <class T, class TCounter>
+class TLockFreeQueue: public TNonCopyable {
struct TListNode {
template <typename U>
TListNode(U&& u, TListNode* next)
@@ -51,10 +51,10 @@ class TLockFreeQueue: public TNonCopyable {
TRootNode* volatile NextFree;
TRootNode()
- : PushQueue(nullptr)
- , PopQueue(nullptr)
- , ToDelete(nullptr)
- , NextFree(nullptr)
+ : PushQueue(nullptr)
+ , PopQueue(nullptr)
+ , ToDelete(nullptr)
+ , NextFree(nullptr)
{
}
void CopyCounter(TRootNode* x) {
@@ -78,7 +78,7 @@ class TLockFreeQueue: public TNonCopyable {
void TryToFreeAsyncMemory() {
TAtomic keepCounter = AtomicAdd(FreeingTaskCounter, 0);
TRootNode* current = AtomicGet(FreePtr);
- if (current == nullptr)
+ if (current == nullptr)
return;
if (AtomicAdd(FreememCounter, 0) == 1) {
// we are the last thread, try to cleanup
@@ -86,7 +86,7 @@ class TLockFreeQueue: public TNonCopyable {
if (keepCounter != AtomicAdd(FreeingTaskCounter, 0)) {
return;
}
- if (AtomicCas(&FreePtr, (TRootNode*)nullptr, current)) {
+ if (AtomicCas(&FreePtr, (TRootNode*)nullptr, current)) {
// free list
while (current) {
TRootNode* p = AtomicGet(current->NextFree);
@@ -131,29 +131,29 @@ class TLockFreeQueue: public TNonCopyable {
TListNode* PrevFirst;
TListInvertor()
- : Copy(nullptr)
- , Tail(nullptr)
- , PrevFirst(nullptr)
+ : Copy(nullptr)
+ , Tail(nullptr)
+ , PrevFirst(nullptr)
{
}
~TListInvertor() {
EraseList(Copy);
}
void CopyWasUsed() {
- Copy = nullptr;
- Tail = nullptr;
- PrevFirst = nullptr;
+ Copy = nullptr;
+ Tail = nullptr;
+ PrevFirst = nullptr;
}
void DoCopy(TListNode* ptr) {
TListNode* newFirst = ptr;
- TListNode* newCopy = nullptr;
- TListNode* newTail = nullptr;
+ TListNode* newCopy = nullptr;
+ TListNode* newTail = nullptr;
while (ptr) {
if (ptr == PrevFirst) {
// short cut, we have copied this part already
AtomicSet(Tail->Next, newCopy);
newCopy = Copy;
- Copy = nullptr; // do not destroy prev try
+ Copy = nullptr; // do not destroy prev try
if (!newTail)
newTail = Tail; // tried to invert same list
break;
@@ -188,7 +188,7 @@ class TLockFreeQueue: public TNonCopyable {
}
if (AtomicCas(&JobQueue, newRoot, curRoot)) {
- AsyncUnref(curRoot, nullptr);
+ AsyncUnref(curRoot, nullptr);
break;
}
}
@@ -229,7 +229,7 @@ public:
: JobQueue(new TRootNode)
, FreememCounter(0)
, FreeingTaskCounter(0)
- , FreePtr(nullptr)
+ , FreePtr(nullptr)
{
}
~TLockFreeQueue() {
@@ -272,7 +272,7 @@ public:
EnqueueImpl(node, tail);
}
bool Dequeue(T* data) {
- TRootNode* newRoot = nullptr;
+ TRootNode* newRoot = nullptr;
TListInvertor listInvertor;
AsyncRef();
for (;;) {
@@ -310,7 +310,7 @@ public:
newRoot->CopyCounter(curRoot);
Y_ASSERT(AtomicGet(curRoot->PopQueue) == nullptr);
if (AtomicCas(&JobQueue, newRoot, curRoot)) {
- newRoot = nullptr;
+ newRoot = nullptr;
listInvertor.CopyWasUsed();
AsyncDel(curRoot, AtomicGet(curRoot->PushQueue));
} else {
@@ -359,7 +359,7 @@ public:
}
};
-template <class T, class TCounter>
+template <class T, class TCounter>
class TAutoLockFreeQueue {
public:
using TRef = THolder<T>;
@@ -372,7 +372,7 @@ public:
}
inline bool Dequeue(TRef* t) {
- T* res = nullptr;
+ T* res = nullptr;
if (Queue.Dequeue(&res)) {
t->Reset(res);
diff --git a/util/thread/lfqueue_ut.cpp b/util/thread/lfqueue_ut.cpp
index 83bca100cf..aa6b21afeb 100644
--- a/util/thread/lfqueue_ut.cpp
+++ b/util/thread/lfqueue_ut.cpp
@@ -102,8 +102,8 @@ int TOperationsChecker::CopyCtor_ = 0;
int TOperationsChecker::MoveAssign_ = 0;
int TOperationsChecker::CopyAssign_ = 0;
-Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
- Y_UNIT_TEST(TestMoveEnqueue) {
+Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
+ Y_UNIT_TEST(TestMoveEnqueue) {
TMoveTest value(0xFF, 0xAA);
TMoveTest tmp;
@@ -121,7 +121,7 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
UNIT_ASSERT_VALUES_EQUAL(tmp.Value(), 0xAA);
}
- Y_UNIT_TEST(TestSimpleEnqueueDequeue) {
+ Y_UNIT_TEST(TestSimpleEnqueueDequeue) {
TLockFreeQueue<int> queue;
int i = -1;
@@ -153,7 +153,7 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
UNIT_ASSERT_VALUES_EQUAL(i, tmp);
}
- Y_UNIT_TEST(TestSimpleEnqueueAllDequeue) {
+ Y_UNIT_TEST(TestSimpleEnqueueAllDequeue) {
TLockFreeQueue<int> queue;
int i = -1;
@@ -302,7 +302,7 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
UNIT_ASSERT_VALUES_EQUAL(v[2], 3);
}
- Y_UNIT_TEST(CleanInDestructor) {
+ Y_UNIT_TEST(CleanInDestructor) {
TSimpleSharedPtr<bool> p(new bool);
UNIT_ASSERT_VALUES_EQUAL(1u, p.RefCount());
@@ -318,7 +318,7 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
UNIT_ASSERT_VALUES_EQUAL(1, p.RefCount());
}
- Y_UNIT_TEST(CheckOperationsCount) {
+ Y_UNIT_TEST(CheckOperationsCount) {
TOperationsChecker o;
o.Check(1, 0, 0, 0, 0);
TLockFreeQueue<TOperationsChecker> queue;
diff --git a/util/thread/lfstack.h b/util/thread/lfstack.h
index ca3d95f3c3..bfdb9f6879 100644
--- a/util/thread/lfstack.h
+++ b/util/thread/lfstack.h
@@ -16,7 +16,7 @@ class TLockFreeStack: TNonCopyable {
template <class U>
explicit TNode(U&& val)
: Value(std::forward<U>(val))
- , Next(nullptr)
+ , Next(nullptr)
{
}
};
@@ -31,7 +31,7 @@ class TLockFreeStack: TNonCopyable {
return;
if (AtomicAdd(DequeueCount, 0) == 1) {
// node current is in free list, we are the last thread so try to cleanup
- if (AtomicCas(&FreePtr, (TNode*)nullptr, current))
+ if (AtomicCas(&FreePtr, (TNode*)nullptr, current))
EraseList(current);
}
}
@@ -57,8 +57,8 @@ class TLockFreeStack: TNonCopyable {
public:
TLockFreeStack()
- : Head(nullptr)
- , FreePtr(nullptr)
+ : Head(nullptr)
+ , FreePtr(nullptr)
, DequeueCount(0)
{
}
@@ -127,7 +127,7 @@ public:
void DequeueAll(TCollection* res) {
AtomicAdd(DequeueCount, 1);
for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) {
- if (AtomicCas(&Head, (TNode*)nullptr, current)) {
+ if (AtomicCas(&Head, (TNode*)nullptr, current)) {
for (TNode* x = current; x;) {
res->push_back(std::move(x->Value));
x = x->Next;
@@ -171,7 +171,7 @@ public:
template <typename TCollection>
void DequeueAllSingleConsumer(TCollection* res) {
for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) {
- if (AtomicCas(&Head, (TNode*)nullptr, current)) {
+ if (AtomicCas(&Head, (TNode*)nullptr, current)) {
for (TNode* x = current; x;) {
res->push_back(std::move(x->Value));
x = x->Next;
@@ -182,7 +182,7 @@ public:
}
}
bool IsEmpty() {
- AtomicAdd(DequeueCount, 0); // mem barrier
+ AtomicAdd(DequeueCount, 0); // mem barrier
return AtomicGet(Head) == nullptr; // without lock, so result is approximate
}
};
diff --git a/util/thread/lfstack_ut.cpp b/util/thread/lfstack_ut.cpp
index e20a838f95..9021220e88 100644
--- a/util/thread/lfstack_ut.cpp
+++ b/util/thread/lfstack_ut.cpp
@@ -8,7 +8,7 @@
#include "lfstack.h"
-Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
+Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
class TCountDownLatch {
private:
TAtomic Current_;
@@ -106,15 +106,15 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
}
};
- Y_UNIT_TEST(TestDequeueAll) {
+ Y_UNIT_TEST(TestDequeueAll) {
TDequeueAllTester<false>().Run();
}
- Y_UNIT_TEST(TestDequeueAllSingleConsumer) {
+ Y_UNIT_TEST(TestDequeueAllSingleConsumer) {
TDequeueAllTester<true>().Run();
}
- Y_UNIT_TEST(TestDequeueAllEmptyStack) {
+ Y_UNIT_TEST(TestDequeueAllEmptyStack) {
TLockFreeStack<int> stack;
TVector<int> r;
@@ -123,7 +123,7 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
UNIT_ASSERT(r.empty());
}
- Y_UNIT_TEST(TestDequeueAllReturnsInReverseOrder) {
+ Y_UNIT_TEST(TestDequeueAllReturnsInReverseOrder) {
TLockFreeStack<int> stack;
stack.Enqueue(17);
@@ -140,7 +140,7 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
UNIT_ASSERT_VALUES_EQUAL(17, r.at(2));
}
- Y_UNIT_TEST(TestEnqueueAll) {
+ Y_UNIT_TEST(TestEnqueueAll) {
TLockFreeStack<int> stack;
TVector<int> v;
@@ -174,7 +174,7 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
}
}
- Y_UNIT_TEST(CleanInDestructor) {
+ Y_UNIT_TEST(CleanInDestructor) {
TSimpleSharedPtr<bool> p(new bool);
UNIT_ASSERT_VALUES_EQUAL(1u, p.RefCount());
@@ -307,7 +307,7 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) {
};
// Test for catching thread sanitizer problems
- Y_UNIT_TEST(TestFreeList) {
+ Y_UNIT_TEST(TestFreeList) {
TMultiThreadTester<TFreeListTest>().Run();
}
diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp
index 05fad02e9b..f280a29f9c 100644
--- a/util/thread/pool.cpp
+++ b/util/thread/pool.cpp
@@ -13,7 +13,7 @@
#include <util/generic/singleton.h>
#include <util/generic/fastqueue.h>
-#include <util/stream/output.h>
+#include <util/stream/output.h>
#include <util/string/builder.h>
#include <util/system/event.h>
@@ -94,7 +94,7 @@ public:
}
TAtforkQueueRestarter::Get().UnregisterObject(this);
- Y_ASSERT(Tharr.empty());
+ Y_ASSERT(Tharr.empty());
}
inline bool Add(IObjectInQueue* obj) {
@@ -209,7 +209,7 @@ private:
}
while (true) {
- IObjectInQueue* job = nullptr;
+ IObjectInQueue* job = nullptr;
with_lock (QueueMutex) {
while (Queue.Empty() && !AtomicGet(ShouldTerminate)) {
@@ -309,7 +309,7 @@ private:
#if defined(_bionic_)
//no pthread_atfork on android libc
#elif defined(_unix_)
- pthread_atfork(nullptr, nullptr, ProcessChildAction);
+ pthread_atfork(nullptr, nullptr, ProcessChildAction);
#endif
}
};
@@ -395,7 +395,7 @@ public:
TTsr tsr(Impl_->Parent_);
IObjectInQueue* obj;
- while ((obj = Impl_->WaitForJob()) != nullptr) {
+ while ((obj = Impl_->WaitForJob()) != nullptr) {
if (Impl_->Catching) {
try {
try {
@@ -424,7 +424,7 @@ public:
, Namer(params)
, ThrCount_(0)
, AllDone_(false)
- , Obj_(nullptr)
+ , Obj_(nullptr)
, Free_(0)
, IdleTime_(TDuration::Max())
{
@@ -445,7 +445,7 @@ public:
inline void Add(IObjectInQueue* obj) {
with_lock (Mutex_) {
- while (Obj_ != nullptr) {
+ while (Obj_ != nullptr) {
CondFree_.Wait(Mutex_);
}
@@ -522,7 +522,7 @@ private:
}
IObjectInQueue* ret = Obj_;
- Obj_ = nullptr;
+ Obj_ = nullptr;
--Free_;
@@ -746,7 +746,7 @@ namespace {
void DoJoin() noexcept override {
if (Impl_) {
Impl_->WaitForComplete();
- Impl_ = nullptr;
+ Impl_ = nullptr;
}
}
diff --git a/util/thread/pool.h b/util/thread/pool.h
index d1ea3a67cb..d7d56651e8 100644
--- a/util/thread/pool.h
+++ b/util/thread/pool.h
@@ -1,6 +1,6 @@
#pragma once
-#include "fwd.h"
+#include "fwd.h"
#include "factory.h"
#include <util/system/yassert.h>
@@ -217,12 +217,12 @@ public:
* Created resource is passed to IObjectInQueue::Proccess function.
*/
virtual void* CreateThreadSpecificResource() {
- return nullptr;
+ return nullptr;
}
virtual void DestroyThreadSpecificResource(void* resource) {
- if (resource != nullptr) {
- Y_ASSERT(resource == nullptr);
+ if (resource != nullptr) {
+ Y_ASSERT(resource == nullptr);
}
}
diff --git a/util/thread/pool_ut.cpp b/util/thread/pool_ut.cpp
index 893770d0c4..18f4549dc2 100644
--- a/util/thread/pool_ut.cpp
+++ b/util/thread/pool_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/stream/output.h>
+#include <util/stream/output.h>
#include <util/random/fast.h>
#include <util/system/spinlock.h>
#include <util/system/thread.h>
@@ -113,7 +113,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) {
}
}
- Y_UNIT_TEST(TestAddAndOwn) {
+ Y_UNIT_TEST(TestAddAndOwn) {
TThreadPool q;
q.Start(2);
bool processed = false;
@@ -125,7 +125,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) {
UNIT_ASSERT_C(destructed, "Not destructed");
}
- Y_UNIT_TEST(TestAddFunc) {
+ Y_UNIT_TEST(TestAddFunc) {
TFailAddQueue queue;
bool added = queue.AddFunc(
[]() {} // Lambda, I call him 'Lambda'!
@@ -138,7 +138,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) {
UNIT_CHECK_GENERATED_EXCEPTION(queue.SafeAddFunc([] {}), TThreadPoolException);
}
- Y_UNIT_TEST(TestFunctionNotCopied) {
+ Y_UNIT_TEST(TestFunctionNotCopied) {
struct TFailOnCopy {
TFailOnCopy() {
}
diff --git a/util/thread/singleton.h b/util/thread/singleton.h
index 4a1e05aea0..8d3bdda992 100644
--- a/util/thread/singleton.h
+++ b/util/thread/singleton.h
@@ -12,10 +12,10 @@ namespace NPrivate {
}
static inline T* Get() {
-#if defined(Y_HAVE_FAST_POD_TLS)
+#if defined(Y_HAVE_FAST_POD_TLS)
Y_POD_STATIC_THREAD(T*) fast(nullptr);
- if (Y_UNLIKELY(!fast)) {
+ if (Y_UNLIKELY(!fast)) {
fast = GetSlow();
}
diff --git a/util/thread/singleton_ut.cpp b/util/thread/singleton_ut.cpp
index 164b1cc184..d4a31b36f1 100644
--- a/util/thread/singleton_ut.cpp
+++ b/util/thread/singleton_ut.cpp
@@ -12,8 +12,8 @@ namespace {
};
}
-Y_UNIT_TEST_SUITE(Tls) {
- Y_UNIT_TEST(FastThread) {
+Y_UNIT_TEST_SUITE(Tls) {
+ Y_UNIT_TEST(FastThread) {
UNIT_ASSERT_VALUES_EQUAL(0, FastTlsSingleton<TFoo>()->i);
FastTlsSingleton<TFoo>()->i += 3;
UNIT_ASSERT_VALUES_EQUAL(3, FastTlsSingleton<TFoo>()->i);