From 36dff4eec10b6c7dbe82a6f81dce49606c3c3244 Mon Sep 17 00:00:00 2001 From: hselasky Date: Fri, 5 Oct 2018 07:50:44 +0000 Subject: [PATCH] MFC r338993: When multiple threads are involved receiving completion events in LibUSB make sure there is always a master polling thread, by setting the "ctx_handler" field in the context. Else the reception of completion events can stop. This happens if event threads are created and destroyed during runtime. Found by: Ludovic Rousseau PR: 231742 Sponsored by: Mellanox Technologies git-svn-id: svn://svn.freebsd.org/base/stable/10@339190 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libusb/libusb10_io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 3b763ec9a..315297f10 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -310,6 +310,9 @@ libusb_wait_for_event(libusb_context *ctx, struct timeval *tv) if (tv == NULL) { pthread_cond_wait(&ctx->ctx_cond, &ctx->ctx_lock); + /* try to grab polling of actual events, if any */ + if (ctx->ctx_handler == NO_THREAD) + ctx->ctx_handler = pthread_self(); return (0); } err = clock_gettime(CLOCK_MONOTONIC, &ts); @@ -328,6 +331,9 @@ libusb_wait_for_event(libusb_context *ctx, struct timeval *tv) } err = pthread_cond_timedwait(&ctx->ctx_cond, &ctx->ctx_lock, &ts); + /* try to grab polling of actual events, if any */ + if (ctx->ctx_handler == NO_THREAD) + ctx->ctx_handler = pthread_self(); if (err == ETIMEDOUT) return (1); -- 2.42.0