* Receive message object * @param ms {int} When >= 0, set wait timeout (milliseconds), * otherwise wait forever until message object is read or error occurs * @param found {bool*} When not NULL, used to store whether a message object * was obtained, mainly used for * checking when passing null objects is allowed * @return {T*} Non-NULL indicates a message object was obtained. When re
| 140 | * @override |
| 141 | */ |
| 142 | T* pop(int ms = -1, bool* found = NULL) { |
| 143 | long long us = ((long long) ms) * 1000; |
| 144 | bool found_flag; |
| 145 | |
| 146 | if (! lock_.lock()) { abort(); } |
| 147 | while (true) { |
| 148 | T* t = peek(found_flag); |
| 149 | if (found_flag) { |
| 150 | if (! lock_.unlock()) { abort(); } |
| 151 | if (found) { |
| 152 | *found = found_flag; |
| 153 | } |
| 154 | return t; |
| 155 | } |
| 156 | |
| 157 | // Note the call order, must call wait first then check wait_ms |
| 158 | waiters_++; |
| 159 | if (! cond_.wait(us, true) && us >= 0) { |
| 160 | waiters_--; |
| 161 | if (! lock_.unlock()) { abort(); } |
| 162 | if (found) { |
| 163 | *found = false; |
| 164 | } |
| 165 | return NULL; |
| 166 | } |
| 167 | waiters_--; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // @override |
| 172 | size_t pop( std::vector<T*>& out, size_t max, int ms) { |