| 160 | } |
| 161 | |
| 162 | acl_int64 aio_timer_callback::trigger() |
| 163 | { |
| 164 | // sanity check |
| 165 | if (tasks_.empty()) { |
| 166 | return TIMER_EMPTY; |
| 167 | } |
| 168 | |
| 169 | acl_assert(length_ > 0); |
| 170 | |
| 171 | set_time(); |
| 172 | |
| 173 | std::list<aio_timer_task*>::iterator it; |
| 174 | std::list<aio_timer_task*> tasks; |
| 175 | aio_timer_task* task; |
| 176 | |
| 177 | // �Ӷ�ʱ����ȡ������Ķ�ʱ���� |
| 178 | for (it = tasks_.begin(); it != tasks_.end();) { |
| 179 | if ((*it)->when > present_) { |
| 180 | break; |
| 181 | } |
| 182 | task = *it; |
| 183 | it = tasks_.erase(it); |
| 184 | length_--; |
| 185 | tasks.push_back(task); |
| 186 | } |
| 187 | |
| 188 | // �п�����Щ����Ķ�ʱ�����Ѿ����û���ǰɾ���� |
| 189 | if (tasks.empty()) { |
| 190 | acl_assert(!tasks_.empty()); |
| 191 | |
| 192 | aio_timer_task* first = tasks_.front(); |
| 193 | acl_int64 delay = first->when - present_; |
| 194 | return delay < 0 ? 0 : delay; |
| 195 | } |
| 196 | |
| 197 | // ������Ķ�ʱ�������·Ż�����ʱ���������б��У� |
| 198 | // ����ʼ�������еĵ���Ķ�ʱ���� |
| 199 | |
| 200 | // ���������ô�������æ״̬���Է�ֹ�����ڻص����� |
| 201 | // �е����˸��������������� |
| 202 | set_locked(); |
| 203 | |
| 204 | // ���ý��������ٱ�־Ϊ false����Ϊ��ǰ�ö�ʱ������ |
| 205 | // ����״̬�����������������ֱ��������ʱ���ٱ��� |
| 206 | // ��������������ñ�ʶ����Ϊ true��������� |
| 207 | // Ӧ���Զ����� |
| 208 | destroy_on_unlock_ = false; |
| 209 | |
| 210 | for (it = tasks.begin(); it != tasks.end(); ++it) { |
| 211 | set_task(*it); |
| 212 | timer_callback((*it)->id); |
| 213 | } |
| 214 | |
| 215 | tasks.clear(); |
| 216 | |
| 217 | // ����֮��IJ����б���������������� |
| 218 | unset_locked(); |
| 219 |
no test coverage detected