| 81 | } |
| 82 | |
| 83 | size_t manual_executor::loop_until_impl(size_t max_count, std::chrono::time_point<std::chrono::system_clock> deadline) { |
| 84 | if (max_count == 0) { |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | size_t executed = 0; |
| 89 | deadline += std::chrono::milliseconds(1); |
| 90 | |
| 91 | while (true) { |
| 92 | if (executed == max_count) { |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | const auto now = std::chrono::system_clock::now(); |
| 97 | if (now >= deadline) { |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | std::unique_lock<decltype(m_lock)> lock(m_lock); |
| 102 | const auto found_task = m_condition.wait_until(lock, deadline, [this] { |
| 103 | return !m_tasks.empty() || m_abort; |
| 104 | }); |
| 105 | |
| 106 | if (m_abort) { |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | if (!found_task) { |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | assert(!m_tasks.empty()); |
| 115 | auto task = std::move(m_tasks.front()); |
| 116 | m_tasks.pop_front(); |
| 117 | lock.unlock(); |
| 118 | |
| 119 | task(); |
| 120 | ++executed; |
| 121 | } |
| 122 | |
| 123 | if (shutdown_requested()) { |
| 124 | details::throw_runtime_shutdown_exception(name); |
| 125 | } |
| 126 | |
| 127 | return executed; |
| 128 | } |
| 129 | |
| 130 | void manual_executor::wait_for_tasks_impl(size_t count) { |
| 131 | if (count == 0) { |
nothing calls this directly
no test coverage detected