From 50e246b1c7980fe9c521a1a005ef5e2412f407c8 Mon Sep 17 00:00:00 2001 From: hselasky Date: Fri, 28 Sep 2018 10:28:22 +0000 Subject: [PATCH] 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 MFC after: 1 week Approved by: re (kib) Sponsored by: Mellanox Technologies --- 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 13c9e786c00e..53f5b040436d 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -312,6 +312,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); @@ -330,6 +333,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);