| 142 | } |
| 143 | |
| 144 | void remove_handler(stub_isr_handle_data* handler) FL_NOEXCEPT { |
| 145 | fl::unique_lock<fl::mutex> lock(mMutex) FL_NOEXCEPT; |
| 146 | |
| 147 | // Remove from vector |
| 148 | for (size_t i = 0; i < mHandlers.size(); ++i) { |
| 149 | if (mHandlers[i] == handler) { |
| 150 | mHandlers.erase(mHandlers.begin() + i); |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Stop thread if no more handlers |
| 156 | if (mHandlers.empty() && mTimerThread) { |
| 157 | mShouldStop = true; |
| 158 | mCondVar.notify_one(); // Wake the thread so it can exit |
| 159 | lock.unlock(); // Unlock before joining |
| 160 | if (mTimerThread->joinable()) { |
| 161 | mTimerThread->join(); |
| 162 | } |
| 163 | mTimerThread.reset(); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | ~TimerThreadManager() { |
| 168 | if (mTimerThread) { |
no test coverage detected