]> git.seodisparate.com - UDPConnection/commitdiff
Fix invalid use of mutex in TSLQueue
authorStephen Seo <seo.disparate@gmail.com>
Mon, 23 Oct 2023 06:53:52 +0000 (15:53 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 12 Jan 2024 04:32:05 +0000 (13:32 +0900)
Mutex was removed in favor of the custom SharedSpinLock.

src/TSLQueue.hpp

index 58b468f9d4b97eac3e012d95e18e3c5d2d56ac87..76e29d0f0a4e90d0b69bc8fd4b17503640e6c7d4 100644 (file)
@@ -2,7 +2,6 @@
 #define UDPC_THREADSAFE_LINKEDLIST_QUEUE_HPP
 
 #include <memory>
-#include <mutex>
 #include <thread>
 #include <chrono>
 #include <optional>
@@ -118,9 +117,14 @@ TSLQueue<T>::~TSLQueue() {
 }
 
 template <typename T>
-TSLQueue<T>::TSLQueue(TSLQueue &&other)
+TSLQueue<T>::TSLQueue(TSLQueue &&other) :
+    sharedSpinLock(UDPC::SharedSpinLock::newInstance()),
+    head(std::shared_ptr<TSLQNode>(new TSLQNode())),
+    tail(std::shared_ptr<TSLQNode>(new TSLQNode())),
+    msize(0)
 {
-    std::lock_guard<std::mutex> lock(other.mutex);
+    auto selfWriteLock = sharedSpinLock->spin_write_lock();
+    auto otherWriteLock = other.sharedSpinLock->spin_write_lock();
     head = std::move(other.head);
     tail = std::move(other.tail);
     msize = std::move(other.msize);