Browse Source

Restoring authorship annotation for <gridem@yandex-team.ru>. Commit 1 of 2.

gridem 3 years ago
parent
commit
c033c991ec
2 changed files with 86 additions and 86 deletions
  1. 28 28
      util/thread/lfqueue.h
  2. 58 58
      util/thread/lfqueue_ut.cpp

+ 28 - 28
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;

+ 58 - 58
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); 
+    } 
 }