* ������Ϣ���� * @param ms {int} >= 0 ʱ���õȴ���ʱʱ��(���뼶��)�� * ������Զ�ȴ�ֱ��������Ϣ�������� * @param found {bool*} �ǿ�ʱ��������Ƿ�����һ����Ϣ������Ҫ���� * ���������ݿն���ʱ�ļ�� * @return {T*} �� NULL ��ʾ���һ����Ϣ������ NULL ʱ����Ҫ����һ * ����飬��������� push ��һ���ն���NULL������������Ҳ���� NULL�� * ����ʱ��Ȼ��Ϊ�����һ����Ϣ����ֻ����Ϊ�ն������ wait_ms ���� * Ϊ -1 ʱ���� NULL ��Ȼ
| 130 | * @override |
| 131 | */ |
| 132 | T* pop(int ms = -1, bool* found = NULL) { |
| 133 | long long us = ((long long) ms) * 1000; |
| 134 | bool found_flag; |
| 135 | |
| 136 | if (! lock_.lock()) { abort(); } |
| 137 | while (true) { |
| 138 | T* t = peek(found_flag); |
| 139 | if (found_flag) { |
| 140 | if (! lock_.unlock()) { abort(); } |
| 141 | if (found) { |
| 142 | *found = found_flag; |
| 143 | } |
| 144 | return t; |
| 145 | } |
| 146 | |
| 147 | // ע�����˳�����ȵ��� wait ���ж� wait_ms |
| 148 | waiters_++; |
| 149 | if (! cond_.wait(us, true) && us >= 0) { |
| 150 | waiters_--; |
| 151 | if (! lock_.unlock()) { abort(); } |
| 152 | if (found) { |
| 153 | *found = false; |
| 154 | } |
| 155 | return NULL; |
| 156 | } |
| 157 | waiters_--; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // @override |
| 162 | size_t pop( std::vector<T*>& out, size_t max, int ms) { |