* Receive message object * @param t {T&} Store result object when function returns true * @param ms {int} When >= 0, set wait timeout (milliseconds), * otherwise wait forever until message object is read or error occurs * @return {bool} Whether message object was obtained * @override */
| 93 | * @override |
| 94 | */ |
| 95 | bool pop(T& t, int ms = -1) { |
| 96 | long long us = ((long long) ms) * 1000; |
| 97 | if (!lock_.lock()) { abort(); } |
| 98 | while (true) { |
| 99 | if (peek(t)) { |
| 100 | if (!lock_.unlock()) { abort(); } |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | // Note the call order, must call wait first then check wait_ms |
| 105 | if (!cond_.wait(us, true) && us >= 0) { |
| 106 | if (!lock_.unlock()) { abort(); } |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // @override |
| 113 | size_t pop(std::vector<T>& out, size_t max, int ms) { |