| | |
| | | |
| | | class ShmMsgQueue : public StaticDataRef<std::atomic<uint64_t>, ShmMsgQueue> |
| | | { |
| | | typedef ShmObject<SharedQ63<4>> Shmq; |
| | | // typedef ShmObject<SharedQueue<int64_t>> 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; |
| | | typedef robust::FMutex Mutex; |
| | | typedef robust::Guard<Mutex> Guard; |
| | | |
| | | public: |
| | | typedef uint64_t MQId; |
| | |
| | | MQId Id() const { return id_; } |
| | | ShmType &shm() const { return queue_.shm(); } |
| | | |
| | | bool Recv(MsgI &msg, const int timeout_ms) { return queue().Read(msg.OffsetRef(), timeout_ms); } |
| | | bool TryRecv(MsgI &msg) { return queue().TryRead(msg.OffsetRef()); } |
| | | bool Recv(MsgI &msg, const int timeout_ms) |
| | | { |
| | | Guard lock(GetMutex(Id())); |
| | | return queue().Read(msg.OffsetRef(), timeout_ms); |
| | | } |
| | | bool TryRecv(MsgI &msg) |
| | | { |
| | | Guard lock(GetMutex(Id())); |
| | | 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: |
| | | static Mutex &GetMutex(const MQId id); |
| | | MQId id_; |
| | | Queue &queue() { return *queue_.data(); } |
| | | Shmq queue_; |