aboutsummaryrefslogtreecommitdiffstats
path: root/util/thread
diff options
context:
space:
mode:
authorgridem <gridem@yandex-team.ru>2022-02-10 16:52:11 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:52:11 +0300
commitc033c991ec51e667180ad54477994acf76cd9c37 (patch)
tree690c0903ed41ca3ba2a133c65288309924a77a88 /util/thread
parent86b9a8049c23ddce4d975be32bf7655109467697 (diff)
downloadydb-c033c991ec51e667180ad54477994acf76cd9c37.tar.gz
Restoring authorship annotation for <gridem@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/thread')
-rw-r--r--util/thread/lfqueue.h56
-rw-r--r--util/thread/lfqueue_ut.cpp116
2 files changed, 86 insertions, 86 deletions
diff --git a/util/thread/lfqueue.h b/util/thread/lfqueue.h
index ab523631e4..4f919cb2ff 100644
--- a/util/thread/lfqueue.h
+++ b/util/thread/lfqueue.h
@@ -26,19 +26,19 @@ struct TDefaultLFCounter {
template <class T, class TCounter>
class TLockFreeQueue: public TNonCopyable {
struct TListNode {
- template <typename U>
- TListNode(U&& u, TListNode* next)
- : Next(next)
- , Data(std::forward<U>(u))
- {
- }
-
- template <typename U>
- explicit TListNode(U&& u)
- : Data(std::forward<U>(u))
- {
- }
-
+ template <typename U>
+ TListNode(U&& u, TListNode* next)
+ : Next(next)
+ , Data(std::forward<U>(u))
+ {
+ }
+
+ template <typename U>
+ explicit TListNode(U&& u)
+ : Data(std::forward<U>(u))
+ {
+ }
+
TListNode* volatile Next;
T Data;
};
@@ -158,7 +158,7 @@ class TLockFreeQueue: public TNonCopyable {
newTail = Tail; // tried to invert same list
break;
}
- TListNode* newElem = new TListNode(ptr->Data, newCopy);
+ TListNode* newElem = new TListNode(ptr->Data, newCopy);
newCopy = newElem;
ptr = AtomicGet(ptr->Next);
if (!newTail)
@@ -239,19 +239,19 @@ public:
EraseList(JobQueue->PopQueue);
delete JobQueue;
}
- template <typename U>
- void Enqueue(U&& data) {
- TListNode* newNode = new TListNode(std::forward<U>(data));
- EnqueueImpl(newNode, newNode);
- }
- void Enqueue(T&& data) {
- TListNode* newNode = new TListNode(std::move(data));
- EnqueueImpl(newNode, newNode);
- }
- void Enqueue(const T& data) {
- TListNode* newNode = new TListNode(data);
+ template <typename U>
+ void Enqueue(U&& data) {
+ TListNode* newNode = new TListNode(std::forward<U>(data));
EnqueueImpl(newNode, newNode);
}
+ void Enqueue(T&& data) {
+ TListNode* newNode = new TListNode(std::move(data));
+ EnqueueImpl(newNode, newNode);
+ }
+ void Enqueue(const T& data) {
+ TListNode* newNode = new TListNode(data);
+ EnqueueImpl(newNode, newNode);
+ }
template <typename TCollection>
void EnqueueAll(const TCollection& data) {
EnqueueAll(data.begin(), data.end());
@@ -262,12 +262,12 @@ public:
return;
TIter i = dataBegin;
- TListNode* volatile node = new TListNode(*i);
+ TListNode* volatile node = new TListNode(*i);
TListNode* volatile tail = node;
for (++i; i != dataEnd; ++i) {
TListNode* nextNode = node;
- node = new TListNode(*i, nextNode);
+ node = new TListNode(*i, nextNode);
}
EnqueueImpl(node, tail);
}
@@ -289,7 +289,7 @@ public:
newRoot->DecCount(tail->Data);
Y_ASSERT(AtomicGet(curRoot->PopQueue) == tail);
if (AtomicCas(&JobQueue, newRoot, curRoot)) {
- *data = std::move(tail->Data);
+ *data = std::move(tail->Data);
AtomicSet(tail->Next, nullptr);
AsyncUnref(curRoot, tail);
return true;
diff --git a/util/thread/lfqueue_ut.cpp b/util/thread/lfqueue_ut.cpp
index 83bca100cf..ca454e86a6 100644
--- a/util/thread/lfqueue_ut.cpp
+++ b/util/thread/lfqueue_ut.cpp
@@ -51,57 +51,57 @@ private:
int Value_ = 0;
};
-class TOperationsChecker {
-public:
- TOperationsChecker() {
+class TOperationsChecker {
+public:
+ TOperationsChecker() {
++DefaultCtor_;
- }
-
- TOperationsChecker(TOperationsChecker&&) {
+ }
+
+ TOperationsChecker(TOperationsChecker&&) {
++MoveCtor_;
- }
-
- TOperationsChecker(const TOperationsChecker&) {
+ }
+
+ TOperationsChecker(const TOperationsChecker&) {
++CopyCtor_;
- }
-
- TOperationsChecker& operator=(TOperationsChecker&&) {
+ }
+
+ TOperationsChecker& operator=(TOperationsChecker&&) {
++MoveAssign_;
- return *this;
- }
-
- TOperationsChecker& operator=(const TOperationsChecker&) {
+ return *this;
+ }
+
+ TOperationsChecker& operator=(const TOperationsChecker&) {
++CopyAssign_;
- return *this;
- }
-
- static void Check(int defaultCtor, int moveCtor, int copyCtor, int moveAssign, int copyAssign) {
- UNIT_ASSERT_VALUES_EQUAL(defaultCtor, DefaultCtor_);
- UNIT_ASSERT_VALUES_EQUAL(moveCtor, MoveCtor_);
- UNIT_ASSERT_VALUES_EQUAL(copyCtor, CopyCtor_);
- UNIT_ASSERT_VALUES_EQUAL(moveAssign, MoveAssign_);
- UNIT_ASSERT_VALUES_EQUAL(copyAssign, CopyAssign_);
- Clear();
- }
-
-private:
- static void Clear() {
- DefaultCtor_ = MoveCtor_ = CopyCtor_ = MoveAssign_ = CopyAssign_ = 0;
- }
-
- static int DefaultCtor_;
- static int MoveCtor_;
- static int CopyCtor_;
- static int MoveAssign_;
- static int CopyAssign_;
-};
-
-int TOperationsChecker::DefaultCtor_ = 0;
-int TOperationsChecker::MoveCtor_ = 0;
-int TOperationsChecker::CopyCtor_ = 0;
-int TOperationsChecker::MoveAssign_ = 0;
-int TOperationsChecker::CopyAssign_ = 0;
-
+ return *this;
+ }
+
+ static void Check(int defaultCtor, int moveCtor, int copyCtor, int moveAssign, int copyAssign) {
+ UNIT_ASSERT_VALUES_EQUAL(defaultCtor, DefaultCtor_);
+ UNIT_ASSERT_VALUES_EQUAL(moveCtor, MoveCtor_);
+ UNIT_ASSERT_VALUES_EQUAL(copyCtor, CopyCtor_);
+ UNIT_ASSERT_VALUES_EQUAL(moveAssign, MoveAssign_);
+ UNIT_ASSERT_VALUES_EQUAL(copyAssign, CopyAssign_);
+ Clear();
+ }
+
+private:
+ static void Clear() {
+ DefaultCtor_ = MoveCtor_ = CopyCtor_ = MoveAssign_ = CopyAssign_ = 0;
+ }
+
+ static int DefaultCtor_;
+ static int MoveCtor_;
+ static int CopyCtor_;
+ static int MoveAssign_;
+ static int CopyAssign_;
+};
+
+int TOperationsChecker::DefaultCtor_ = 0;
+int TOperationsChecker::MoveCtor_ = 0;
+int TOperationsChecker::CopyCtor_ = 0;
+int TOperationsChecker::MoveAssign_ = 0;
+int TOperationsChecker::CopyAssign_ = 0;
+
Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
Y_UNIT_TEST(TestMoveEnqueue) {
TMoveTest value(0xFF, 0xAA);
@@ -317,17 +317,17 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) {
UNIT_ASSERT_VALUES_EQUAL(1, p.RefCount());
}
-
+
Y_UNIT_TEST(CheckOperationsCount) {
- TOperationsChecker o;
- o.Check(1, 0, 0, 0, 0);
- TLockFreeQueue<TOperationsChecker> queue;
- o.Check(0, 0, 0, 0, 0);
- queue.Enqueue(std::move(o));
- o.Check(0, 1, 0, 0, 0);
- queue.Enqueue(o);
- o.Check(0, 0, 1, 0, 0);
- queue.Dequeue(&o);
- o.Check(0, 0, 2, 1, 0);
- }
+ TOperationsChecker o;
+ o.Check(1, 0, 0, 0, 0);
+ TLockFreeQueue<TOperationsChecker> queue;
+ o.Check(0, 0, 0, 0, 0);
+ queue.Enqueue(std::move(o));
+ o.Check(0, 1, 0, 0, 0);
+ queue.Enqueue(o);
+ o.Check(0, 0, 1, 0, 0);
+ queue.Dequeue(&o);
+ o.Check(0, 0, 2, 1, 0);
+ }
}