From c91fdee8e845a2eccbc680c2d88748b2ac95a407 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 27 Mar 2019 11:05:12 -0400 Subject: ... --- include/salticidae/msg.h | 2 +- include/salticidae/network.h | 4 ++-- include/salticidae/queue.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/salticidae/msg.h b/include/salticidae/msg.h index 257ce4f..42a9bc2 100644 --- a/include/salticidae/msg.h +++ b/include/salticidae/msg.h @@ -56,7 +56,7 @@ class MsgBase { mutable bool no_payload; public: - MsgBase(): magic(0x0), no_payload(true) {} + MsgBase(): magic(0x0), opcode(0xff), no_payload(true) {} template::Conn::on_read() { return; } #endif - mn->incoming_msgs.enqueue( - std::make_pair(std::move(msg), static_pointer_cast(self()))); + auto conn = static_pointer_cast(self()); + while (!mn->incoming_msgs.try_enqueue(std::make_pair(msg, conn))); } } } diff --git a/include/salticidae/queue.h b/include/salticidae/queue.h index 1732238..598303c 100644 --- a/include/salticidae/queue.h +++ b/include/salticidae/queue.h @@ -148,7 +148,7 @@ class MPMCQueue { bool try_dequeue(T &e) { for (;;) { - auto h = head.load(std::memory_order_acquire); + auto h = head.load(std::memory_order_relaxed); auto t = h->refcnt.load(std::memory_order_relaxed); if (!t) continue; if (h->refcnt.compare_exchange_weak(t, t + 1, std::memory_order_consume)) @@ -178,13 +178,13 @@ template struct MPSCQueue: public MPMCQueue { using MPMCQueue::MPMCQueue; bool try_dequeue(T &e) { - auto h = this->head.load(std::memory_order_acquire); + auto h = this->head.load(std::memory_order_relaxed); auto nh = h->next.load(std::memory_order_relaxed); - if (nh == nullptr) - return false; std::atomic_thread_fence(std::memory_order_acquire); + if (nh == nullptr) return false; e = std::move(nh->elem); - this->head.store(nh, std::memory_order_release); + std::atomic_thread_fence(std::memory_order_release); + this->head.store(nh, std::memory_order_relaxed); this->blks.push(h); return true; } -- cgit v1.2.3-70-g09d2