| | |
| | | using Super::size; |
| | | using Super::capacity; |
| | | const MQId &Id() const { return id_; } |
| | | bool Write(const D &buf, const int timeout_ms) { |
| | | template <class OnWrite> |
| | | bool Write(const D &buf, const int timeout_ms, const OnWrite &onWrite) { |
| | | Guard lock(mutex()); |
| | | if (cond_write_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->full(); })) { |
| | | onWrite(); |
| | | this->push_back(buf); |
| | | cond_read_.notify_one(); |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | } |
| | | bool Write(const D &buf, const int timeout_ms) { return Write(buf, timeout_ms, [](){}); } |
| | | |
| | | bool Read(D &buf, const int timeout_ms){ |
| | | Guard lock(mutex()); |
| | |
| | | bool Recv(MQId &source_id, void *&data, size_t &size, const int timeout_ms); |
| | | const MQId &Id() const { return data()->Id(); } |
| | | bool Send(const MQId &remote_id, const Msg &msg, const int timeout_ms); |
| | | bool Recv(Msg &msg, const int timeout_ms) { return Read(msg, timeout_ms); } |
| | | }; |
| | | |
| | | } // namespace bhome_shm |