From 95bd9a67f9f6c90f627784e3f8fbf5c203784e51 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 30 四月 2021 15:36:17 +0800 Subject: [PATCH] change shm socket msg queue to atomic queue. --- src/shm_msg_queue.h | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shm_msg_queue.h b/src/shm_msg_queue.h index c56784c..aff931c 100644 --- a/src/shm_msg_queue.h +++ b/src/shm_msg_queue.h @@ -26,7 +26,8 @@ class ShmMsgQueue : public StaticDataRef<std::atomic<uint64_t>, ShmMsgQueue> { - typedef ShmObject<SharedQueue<MsgI>> Shmq; + typedef ShmObject<SharedQ63<4>> Shmq; + // typedef ShmObject<SharedQueue<int64_t>> Shmq; typedef Shmq::ShmType ShmType; typedef Shmq::Data Queue; typedef std::function<void()> OnSend; @@ -43,15 +44,15 @@ MQId Id() const { return id_; } ShmType &shm() const { return queue_.shm(); } - bool Recv(MsgI &msg, const int timeout_ms) { return queue_.data()->Read(msg, timeout_ms); } - bool TryRecv(MsgI &msg) { return queue_.data()->TryRead(msg); } + bool Recv(MsgI &msg, const int timeout_ms) { return queue().Read(msg.OffsetRef(), timeout_ms); } + bool TryRecv(MsgI &msg) { return queue().TryRead(msg.OffsetRef()); } static Queue *Find(SharedMemory &shm, const MQId remote_id); static bool TrySend(SharedMemory &shm, const MQId remote_id, MsgI msg); bool TrySend(const MQId remote_id, const MsgI &msg) { return TrySend(shm(), remote_id, msg); } private: MQId id_; - Shmq &queue() { return queue_; } + Queue &queue() { return *queue_.data(); } Shmq queue_; }; -- Gitblit v1.8.0