| 162 | } |
| 163 | |
| 164 | inline void cancel() { |
| 165 | if (!g_watchdog_active.load()) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | g_watchdog_active.store(false); |
| 170 | g_should_exit.store(true); |
| 171 | |
| 172 | // Wait for watchdog thread to exit |
| 173 | if (g_timer_thread != nullptr) { |
| 174 | WaitForSingleObject(g_timer_thread, 1000); // 1 second timeout |
| 175 | CloseHandle(g_timer_thread); |
| 176 | g_timer_thread = nullptr; |
| 177 | } |
| 178 | |
| 179 | // Clean up main thread handle |
| 180 | if (g_main_thread != nullptr) { |
| 181 | CloseHandle(g_main_thread); |
| 182 | g_main_thread = nullptr; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | #else // Unix/Linux/macOS |
| 187 | |