Skip to content

Commit 5d7a7c6

Browse files
CopilotYouw
andcommitted
Add clarifying comment explaining hotplug_cbs is already NULL before signal
Agent-Logs-Url: https://github.com/libusb/hidapi/sessions/808d88e5-75a9-4fc7-ba46-9cf6042c46d5 Co-authored-by: Youw <5939659+Youw@users.noreply.github.com>
1 parent f4192e7 commit 5d7a7c6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

libusb/hid.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ static void* hotplug_thread(void* user_data)
12711271
libusb_hotplug_deregister_callback(hid_hotplug_context.context, hid_hotplug_context.callback_handle);
12721272
libusb_exit(hid_hotplug_context.context);
12731273

1274-
/* Forcibly wake up the thread so it can shut down immediately and wait for it to stop */
1274+
/* hotplug_cbs is already NULL here (the loop above exited because of that).
1275+
* Signal callback_thread under the mutex so it can observe the NULL hotplug_cbs
1276+
* and exit cleanly, rather than waiting indefinitely in cond_wait. */
12751277
hidapi_thread_mutex_lock(&hid_hotplug_context.callback_thread);
12761278
hidapi_thread_cond_signal(&hid_hotplug_context.callback_thread);
12771279
hidapi_thread_mutex_unlock(&hid_hotplug_context.callback_thread);

0 commit comments

Comments
 (0)