5 #include <condition_variable>
27 std::lock_guard<std::mutex> lock(
m_mtx);
33 template <
class Clock,
class Duration>
34 bool waitUntil(
const std::chrono::time_point<Clock, Duration>& point)
36 std::unique_lock<std::mutex> lock(
m_mtx);
37 if(!
m_cv.wait_until(lock, point, [
this]() { return m_count > 0 || m_unlock; }))
54 std::condition_variable
m_cv;
70 template <
typename _Clock = std::chrono::steady_clock,
71 typename _Duration = std::chrono::steady_clock::duration>
77 m_th = std::thread([
this] {
run(); });
92 uint64_t
add(std::chrono::milliseconds milliseconds, std::function<
void(
bool)> handler)
95 item.
end = _Clock::now() + milliseconds;
96 item.
handler = std::move(handler);
98 std::unique_lock<std::mutex> lk(
m_mtx);
121 std::unique_lock<std::mutex> lk(
m_mtx);
124 if(item.id ==
id && item.handler)
128 newItem.
end = std::chrono::time_point<_Clock, _Duration>();
135 newItem.
handler = std::move(item.handler);
136 item.handler =
nullptr;
137 m_items.push(std::move(newItem));
155 std::unique_lock<std::mutex> lk(
m_mtx);
160 item.end = std::chrono::time_point<_Clock, _Duration>();
202 std::pair<bool, std::chrono::time_point<_Clock, _Duration>>
calcWaitTime()
204 std::lock_guard<std::mutex> lk(
m_mtx);
210 return std::make_pair(
true,
m_items.top().end);
221 return std::make_pair(
false, std::chrono::time_point<_Clock, _Duration>());
226 std::unique_lock<std::mutex> lk(
m_mtx);
248 std::chrono::time_point<_Clock, _Duration>
end;
260 :
public std::priority_queue<WorkItem, std::vector<WorkItem>, std::greater<WorkItem>>