| | |
| | | using Super::size; |
| | | using Super::capacity; |
| | | const MQId &Id() const { return id_; } |
| | | bool Write(D buf, const int timeout_ms) { |
| | | bool Write(const D &buf, const int timeout_ms) { |
| | | Guard lock(mutex()); |
| | | if (cond_write_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->full(); })) { |
| | | this->push_back(buf); |
| | |
| | | bool Read(D &buf, const int timeout_ms){ |
| | | Guard lock(mutex()); |
| | | if (cond_read_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->empty(); })) { |
| | | buf = this->front(); |
| | | using std::swap; |
| | | swap(buf, this->front()); |
| | | this->pop_front(); |
| | | cond_write_.notify_one(); |
| | | return true; |