summaryrefslogtreecommitdiff
path: root/lib/libusb
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2012-06-12 07:28:25 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2012-06-12 07:28:25 +0000
commitf7287225df283a4a5eb30839b9215496db221c45 (patch)
treef5c627ab0a90aceb65f1e3857c3d3c2e65b18b94 /lib/libusb
parent77c80e2e5bd34e127da5faaf5c419a12f98cc96e (diff)
downloadsrc-test2-f7287225df283a4a5eb30839b9215496db221c45.tar.gz
src-test2-f7287225df283a4a5eb30839b9215496db221c45.zip
Notes
Diffstat (limited to 'lib/libusb')
-rw-r--r--lib/libusb/Makefile3
-rw-r--r--lib/libusb/libusb10.c25
-rw-r--r--lib/libusb/libusb10_io.c10
3 files changed, 33 insertions, 5 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 7a9bd1b23678..d45dd567b437 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -18,6 +18,9 @@ NOGCCERROR=
WARNS?= 2
+DPADD= ${LIBPTHREAD}
+LDADD= -lpthread
+
MLINKS+= libusb.3 usb.3
# libusb 0.1 compat
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 44331bc6ad3c..256d67e93bc5 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -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;
diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c
index 63f833af8828..302fdb8dda32 100644
--- a/lib/libusb/libusb10_io.c
+++ b/lib/libusb/libusb10_io.c
@@ -307,12 +307,16 @@ libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
&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++;