Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Sep 2018 10:28:22 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338993 - head/lib/libusb
Message-ID:  <201809281028.w8SASMft060868@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Fri Sep 28 10:28:22 2018
New Revision: 338993
URL: https://svnweb.freebsd.org/changeset/base/338993

Log:
  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 <ludovic.rousseau+freebsd@gmail.com>
  PR:			231742
  MFC after:		1 week
  Approved by:		re (kib)
  Sponsored by:		Mellanox Technologies

Modified:
  head/lib/libusb/libusb10_io.c

Modified: head/lib/libusb/libusb10_io.c
==============================================================================
--- head/lib/libusb/libusb10_io.c	Fri Sep 28 10:02:47 2018	(r338992)
+++ head/lib/libusb/libusb10_io.c	Fri Sep 28 10:28:22 2018	(r338993)
@@ -312,6 +312,9 @@ libusb_wait_for_event(libusb_context *ctx, struct time
 	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 time
 	}
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201809281028.w8SASMft060868>