aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/salticidae/msg.h2
-rw-r--r--include/salticidae/network.h4
-rw-r--r--include/salticidae/queue.h10
3 files changed, 8 insertions, 8 deletions
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<typename MsgType,
typename = typename std::enable_if<
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index b36cbe3..7814d56 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -447,8 +447,8 @@ void MsgNetwork<OpcodeType>::Conn::on_read() {
return;
}
#endif
- mn->incoming_msgs.enqueue(
- std::make_pair(std::move(msg), static_pointer_cast<Conn>(self())));
+ auto conn = static_pointer_cast<Conn>(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<typename T>
struct MPSCQueue: public MPMCQueue<T> {
using MPMCQueue<T>::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;
}