MCPcopy Create free account
hub / github.com/comaps/comaps / DeferredTask

Method DeferredTask

libs/base/deferred_task.cpp:5–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3namespace base
4{
5DeferredTask::DeferredTask(Duration const & duration) : m_duration(duration)
6{
7 m_thread = threads::SimpleThread([this]
8 {
9 std::unique_lock l(m_mutex);
10 while (!m_terminate)
11 {
12 if (!m_fn)
13 {
14 m_cv.wait(l);
15 continue;
16 }
17
18 if (m_cv.wait_for(l, m_duration) != std::cv_status::timeout || !m_fn)
19 continue;
20
21 auto fn = std::move(m_fn);
22 m_fn = nullptr;
23
24 l.unlock();
25 fn();
26 l.lock();
27 }
28 });
29}
30
31DeferredTask::~DeferredTask()
32{

Callers

nothing calls this directly

Calls 4

SimpleThreadClass · 0.85
waitMethod · 0.80
unlockMethod · 0.80
lockMethod · 0.80

Tested by

no test coverage detected