rawinput: fix spicecfg close delay (#715)

## Link to GitHub Issue or related Pull Request, if one exists
#0

## Description of change
Closing spicecfg was blocked for up to ~495 ms. Runtime behavior is
unchanged: same flush interval and same output path during normal
operation. Only shutdown teardown is faster.

## Testing
Opened and closed spicecfg.exe repeatedly; the window closes immediately
with no hang
This commit is contained in:
drmext
2026-05-29 16:33:08 +00:00
committed by GitHub
parent b558df3340
commit 0511dfb6ca
2 changed files with 19 additions and 3 deletions
+17 -3
View File
@@ -1112,7 +1112,16 @@ void rawinput::RawInputManager::flush_start() {
* to button based lighting. * to button based lighting.
*/ */
this->devices_flush_output(false); this->devices_flush_output(false);
Sleep(495);
// wait up to ~500ms, but wake immediately if flush_stop()
// flips the running flag. Without the CV the in-flight
// Sleep() forced launcher::shutdown() to block for the full
// remaining sleep window on every close.
std::unique_lock<std::mutex> lock(this->flush_thread_m);
this->flush_thread_cv.wait_for(
lock,
std::chrono::milliseconds(495),
[this] { return !this->flush_thread_running; });
} }
}); });
} }
@@ -1120,8 +1129,13 @@ void rawinput::RawInputManager::flush_start() {
void rawinput::RawInputManager::flush_stop() { void rawinput::RawInputManager::flush_stop() {
// set stop flag // set stop flag and wake the flush thread immediately so shutdown
this->flush_thread_running = false; // isn't blocked by the in-progress wait inside the loop above.
{
std::lock_guard<std::mutex> lock(this->flush_thread_m);
this->flush_thread_running = false;
}
this->flush_thread_cv.notify_all();
// check if thread is set // check if thread is set
if (this->flush_thread) { if (this->flush_thread) {
+2
View File
@@ -69,6 +69,8 @@ namespace rawinput {
std::thread *input_thread = nullptr; std::thread *input_thread = nullptr;
std::thread *flush_thread = nullptr; std::thread *flush_thread = nullptr;
bool flush_thread_running = false; bool flush_thread_running = false;
std::mutex flush_thread_m;
std::condition_variable flush_thread_cv;
std::thread *output_thread = nullptr; std::thread *output_thread = nullptr;
std::mutex output_thread_m; std::mutex output_thread_m;
bool output_thread_ready = false; bool output_thread_ready = false;