| 103 | inline TaskThread::~TaskThread() { stop(); } |
| 104 | |
| 105 | inline void TaskThread::start (uint32_t repeatIntervalMillisecs, std::function<void()> f) |
| 106 | { |
| 107 | CHOC_ASSERT (f != nullptr); |
| 108 | |
| 109 | stop(); |
| 110 | taskFunction = std::move (f); |
| 111 | interval = repeatIntervalMillisecs; |
| 112 | threadShouldExit = false; |
| 113 | flag.test_and_set (std::memory_order_acquire); |
| 114 | |
| 115 | thread = std::thread ([this] |
| 116 | { |
| 117 | wait(); |
| 118 | |
| 119 | while (! threadShouldExit) |
| 120 | { |
| 121 | taskFunction(); |
| 122 | wait(); |
| 123 | } |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | template<typename Rep, typename Period> |
| 128 | void TaskThread::start (std::chrono::duration<Rep, Period> i, std::function<void()> task) |