From owner-svn-src-head@FreeBSD.ORG Tue Jun 12 07:28:26 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1629C106564A; Tue, 12 Jun 2012 07:28:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EB5108FC16; Tue, 12 Jun 2012 07:28:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5C7SPAY036993; Tue, 12 Jun 2012 07:28:25 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5C7SPZ7036989; Tue, 12 Jun 2012 07:28:25 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201206120728.q5C7SPZ7036989@svn.freebsd.org> From: Hans Petter Selasky Date: Tue, 12 Jun 2012 07:28:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236944 - head/lib/libusb X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2012 07:28:26 -0000 Author: hselasky Date: Tue Jun 12 07:28:25 2012 New Revision: 236944 URL: http://svn.freebsd.org/changeset/base/236944 Log: LibUSB v1.0 API compiliance and bugfixes. - Use CLOCK_MONOTONIC instead of CLOCK_REALTIME, because CLOCK_MONOTONIC does not wrap into negative in near future. This fixes any potential problems using "pthread_cond_timedwait()". - Fix a bug where the "libusb_wait_for_event()" function computes an absolute timeout instead of a relative timeout. USB transfers do not depend on this timeout value. - Add dependency towards LibPthread to Makefile, because LibUSB v1.0 needs this library to function correctly. MFC after: 1 week Modified: head/lib/libusb/Makefile head/lib/libusb/libusb10.c head/lib/libusb/libusb10_io.c Modified: head/lib/libusb/Makefile ============================================================================== --- head/lib/libusb/Makefile Tue Jun 12 04:58:52 2012 (r236943) +++ head/lib/libusb/Makefile Tue Jun 12 07:28:25 2012 (r236944) @@ -18,6 +18,9 @@ NOGCCERROR= WARNS?= 2 +DPADD= ${LIBPTHREAD} +LDADD= -lpthread + MLINKS+= libusb.3 usb.3 # libusb 0.1 compat Modified: head/lib/libusb/libusb10.c ============================================================================== --- head/lib/libusb/libusb10.c Tue Jun 12 04:58:52 2012 (r236943) +++ head/lib/libusb/libusb10.c Tue Jun 12 07:28:25 2012 (r236944) @@ -92,6 +92,7 @@ int libusb_init(libusb_context **context) { struct libusb_context *ctx; + pthread_condattr_t attr; char *debug; int ret; @@ -110,8 +111,28 @@ libusb_init(libusb_context **context) TAILQ_INIT(&ctx->pollfds); TAILQ_INIT(&ctx->tr_done); - pthread_mutex_init(&ctx->ctx_lock, NULL); - pthread_cond_init(&ctx->ctx_cond, NULL); + if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { + free(ctx); + return (LIBUSB_ERROR_NO_MEM); + } + if (pthread_condattr_init(&attr) != 0) { + pthread_mutex_destroy(&ctx->ctx_lock); + free(ctx); + return (LIBUSB_ERROR_NO_MEM); + } + if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) { + pthread_mutex_destroy(&ctx->ctx_lock); + pthread_condattr_destroy(&attr); + free(ctx); + return (LIBUSB_ERROR_OTHER); + } + if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) { + pthread_mutex_destroy(&ctx->ctx_lock); + pthread_condattr_destroy(&attr); + free(ctx); + return (LIBUSB_ERROR_NO_MEM); + } + pthread_condattr_destroy(&attr); ctx->ctx_handler = NO_THREAD; Modified: head/lib/libusb/libusb10_io.c ============================================================================== --- head/lib/libusb/libusb10_io.c Tue Jun 12 04:58:52 2012 (r236943) +++ head/lib/libusb/libusb10_io.c Tue Jun 12 07:28:25 2012 (r236944) @@ -307,12 +307,16 @@ libusb_wait_for_event(libusb_context *ct &ctx->ctx_lock); return (0); } - err = clock_gettime(CLOCK_REALTIME, &ts); + err = clock_gettime(CLOCK_MONOTONIC, &ts); if (err < 0) return (LIBUSB_ERROR_OTHER); - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * 1000; + /* + * The "tv" arguments points to a relative time structure and + * not an absolute time structure. + */ + ts.tv_sec += tv->tv_sec; + ts.tv_nsec += tv->tv_usec * 1000; if (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec++;