| 3 | namespace base |
| 4 | { |
| 5 | DeferredTask::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 | |
| 31 | DeferredTask::~DeferredTask() |
| 32 | { |
nothing calls this directly
no test coverage detected