* ������Ϣ���� * @param ms {int} >= 0 ʱ���õȴ���ʱʱ��(���뼶��)�� * ������Զ�ȴ�ֱ��������Ϣ�������� * @param found {bool*} �ǿ�ʱ��������Ƿ�����һ����Ϣ������Ҫ���� * ���������ݿն���ʱ�ļ�� * @return {T*} �� NULL ��ʾ���һ����Ϣ������ NULL ʱ����Ҫ����һ * ����飬��������� push ��һ���ն���NULL������������Ҳ���� NULL�� * ����ʱ��Ȼ��Ϊ�����һ����Ϣ����ֻ����Ϊ�ն������ wait_ms ���� * Ϊ -1 ʱ���� NULL ��Ȼ
| 105 | * @override |
| 106 | */ |
| 107 | T* pop(int ms = -1, bool* found = NULL) { |
| 108 | long long us = ((long long) ms) * 1000; |
| 109 | bool found_flag; |
| 110 | if (! lock_.lock()) { abort(); } |
| 111 | while (true) { |
| 112 | T* t = peek(found_flag); |
| 113 | if (found_flag) { |
| 114 | if (! lock_.unlock()) { abort(); } |
| 115 | if (found) { |
| 116 | *found = found_flag; |
| 117 | } |
| 118 | return t; |
| 119 | } |
| 120 | |
| 121 | // ע�����˳�����ȵ��� wait ���ж� wait_ms |
| 122 | if (! cond_.wait(us, true) && us >= 0) { |
| 123 | if (! lock_.unlock()) { abort(); } |
| 124 | if (found) { |
| 125 | *found = false; |
| 126 | } |
| 127 | return NULL; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // @override |
| 133 | size_t pop( std::vector<T*>& out, size_t max, int ms) { |