| 151 | } |
| 152 | |
| 153 | bool GpsDevice::stop() { |
| 154 | auto lock = mutex.asScopedLock(); |
| 155 | lock.lock(); |
| 156 | |
| 157 | setState(State::PendingOff); |
| 158 | |
| 159 | if (thread != nullptr) { |
| 160 | threadInterrupted = true; |
| 161 | |
| 162 | // Detach thread, it will auto-delete when leaving the current scope |
| 163 | auto old_thread = std::move(thread); |
| 164 | |
| 165 | if (old_thread->getState() != Thread::State::Stopped) { |
| 166 | // Unlock so thread can lock |
| 167 | lock.unlock(); |
| 168 | // Wait for thread to finish |
| 169 | old_thread->join(); |
| 170 | // Re-lock to continue logic below |
| 171 | lock.lock(); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | setState(State::Off); |
| 176 | |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | bool GpsDevice::isThreadInterrupted() const { |
| 181 | auto lock = mutex.asScopedLock(); |
no test coverage detected