spsc-queue: unrelacy
authorBrian Norris <banorris@uci.edu>
Thu, 11 Oct 2012 00:14:52 +0000 (17:14 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 11 Oct 2012 01:04:30 +0000 (18:04 -0700)
spsc-queue/eventcount.h
spsc-queue/queue.h

index 226603e7b9b3555ddbd7e436fdb7611d555736b6..f64946a556138500880f12684e0321802accf86f 100644 (file)
@@ -1,3 +1,5 @@
+#include <unrelacy.h>
+
 class eventcount
 {
 public:
@@ -8,33 +10,33 @@ public:
 
        void signal_relaxed()
        {
-               unsigned cmp = count($).load(std::memory_order_relaxed);
+               unsigned cmp = count.load(std::memory_order_relaxed);
                signal_impl(cmp);
        }
 
        void signal()
        {
-               unsigned cmp = count($).fetch_add(0, std::memory_order_seq_cst);
+               unsigned cmp = count.fetch_add(0, std::memory_order_seq_cst);
                signal_impl(cmp);
        }
 
        unsigned get()
        {
-               unsigned cmp = count($).fetch_or(0x80000000,
+               unsigned cmp = count.fetch_or(0x80000000,
 std::memory_order_seq_cst);
                return cmp & 0x7FFFFFFF;
        }
 
        void wait(unsigned cmp)
        {
-               unsigned ec = count($).load(std::memory_order_seq_cst);
+               unsigned ec = count.load(std::memory_order_seq_cst);
                if (cmp == (ec & 0x7FFFFFFF))
                {
                        guard.lock($);
-                       ec = count($).load(std::memory_order_seq_cst);
+                       ec = count.load(std::memory_order_seq_cst);
                        if (cmp == (ec & 0x7FFFFFFF))
                        {
-                               waiters($) += 1;
+                               waiters += 1;
                                cv.wait(guard, $);
                        }
                        guard.unlock($);
@@ -52,10 +54,10 @@ private:
                if (cmp & 0x80000000)
                {
                        guard.lock($);
-                       while (false == count($).compare_swap(cmp,
+                       while (false == count.compare_swap(cmp,
                                (cmp + 1) & 0x7FFFFFFF, std::memory_order_relaxed));
                        unsigned w = waiters($);
-                       waiters($) = 0;
+                       waiters = 0;
                        guard.unlock($);
                        if (w)
                                cv.notify_all($);
index d65477bf71d99f62edb54220cd2447b5611fcc52..7a6f29e80c60bd6d9f9b0ef6e5571aae5501db4e 100644 (file)
@@ -1,3 +1,5 @@
+#include <unrelacy.h>
+
 #include "eventcount.h"
 
 template<typename T>
@@ -7,21 +9,21 @@ public:
        spsc_queue()
        {
                node* n = RL_NEW node ();
-               head($) = n;
-               tail($) = n;
+               head = n;
+               tail = n;
        }
 
        ~spsc_queue()
        {
-               RL_ASSERT(head($) == tail($));
+               RL_ASSERT(head == tail);
                RL_DELETE((node*)head($));
        }
 
        void enqueue(T data)
        {
                node* n = RL_NEW node (data);
-               head($)->next($).store(n, std::memory_order_release);
-               head($) = n;
+               head($)->next.store(n, std::memory_order_release);
+               head = n;
                ec.signal_relaxed();
        }
 
@@ -62,12 +64,12 @@ private:
        T try_dequeue()
        {
                node* t = tail($);
-               node* n = t->next($).load(std::memory_order_acquire);
+               node* n = t->next.load(std::memory_order_acquire);
                if (0 == n)
                        return 0;
                T data = n->data($);
                RL_DELETE(t);
-               tail($) = n;
+               tail = n;
                return data;
        }
 };