Date: Tue, 19 Jun 2012 06:52:21 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r237262 - stable/8/lib/libusb Message-ID: <201206190652.q5J6qLF2026848@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Tue Jun 19 06:52:21 2012 New Revision: 237262 URL: http://svn.freebsd.org/changeset/base/237262 Log: MFC r236944: LibUSB v1.0 API compliance and bugfixes. Modified: stable/8/lib/libusb/Makefile stable/8/lib/libusb/libusb10.c stable/8/lib/libusb/libusb10_io.c Directory Properties: stable/8/lib/libusb/ (props changed) Modified: stable/8/lib/libusb/Makefile ============================================================================== --- stable/8/lib/libusb/Makefile Tue Jun 19 06:46:54 2012 (r237261) +++ stable/8/lib/libusb/Makefile Tue Jun 19 06:52:21 2012 (r237262) @@ -16,6 +16,9 @@ MAN= libusb.3 libusb20.3 MKLINT= no NOGCCERROR= +DPADD= ${LIBPTHREAD} +LDADD= -lpthread + MLINKS+= libusb.3 usb.3 # libusb 0.1 compat Modified: stable/8/lib/libusb/libusb10.c ============================================================================== --- stable/8/lib/libusb/libusb10.c Tue Jun 19 06:46:54 2012 (r237261) +++ stable/8/lib/libusb/libusb10.c Tue Jun 19 06:52:21 2012 (r237262) @@ -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: stable/8/lib/libusb/libusb10_io.c ============================================================================== --- stable/8/lib/libusb/libusb10_io.c Tue Jun 19 06:46:54 2012 (r237261) +++ stable/8/lib/libusb/libusb10_io.c Tue Jun 19 06:52:21 2012 (r237262) @@ -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++;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206190652.q5J6qLF2026848>