diff options
author | hselasky <hselasky@FreeBSD.org> | 2012-06-12 07:28:25 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2012-06-12 07:28:25 +0000 |
commit | 4dd0cbb180887654865f48b1afa9250ed68d17c7 (patch) | |
tree | f5c627ab0a90aceb65f1e3857c3d3c2e65b18b94 /lib/libusb/libusb10.c | |
parent | fb4fac5af865cb1696d7d1848144bb8828d5413d (diff) | |
download | FreeBSD-src-4dd0cbb180887654865f48b1afa9250ed68d17c7.zip FreeBSD-src-4dd0cbb180887654865f48b1afa9250ed68d17c7.tar.gz |
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
Diffstat (limited to 'lib/libusb/libusb10.c')
-rw-r--r-- | lib/libusb/libusb10.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 44331bc..256d67e 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; |