| 525 | } |
| 526 | |
| 527 | void ThreadManager::Impl::removeExpired(bool justOne) { |
| 528 | // this is always called under a lock |
| 529 | if (tasks_.empty()) { |
| 530 | return; |
| 531 | } |
| 532 | auto now = std::chrono::steady_clock::now(); |
| 533 | |
| 534 | for (auto it = tasks_.begin(); it != tasks_.end(); ) |
| 535 | { |
| 536 | if ((*it)->getExpireTime() && *((*it)->getExpireTime()) < now) { |
| 537 | if (expireCallback_) { |
| 538 | expireCallback_((*it)->getRunnable()); |
| 539 | } |
| 540 | it = tasks_.erase(it); |
| 541 | ++expiredCount_; |
| 542 | if (justOne) { |
| 543 | return; |
| 544 | } |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | ++it; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | void ThreadManager::Impl::setExpireCallback(ExpireCallback expireCallback) { |
| 554 | Guard g(mutex_); |
nothing calls this directly
no test coverage detected