Date: Sun, 17 May 2009 15:27:41 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 162214 for review Message-ID: <200905171527.n4HFRfP3044742@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=162214 Change 162214 by syl@syl_atuin on 2009/05/17 15:27:04 Add default context handling Affected files ... .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#12 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#9 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#12 (text+ko) ==== @@ -39,7 +39,6 @@ /* * XXX TODO - * - default context handling. * - implement debug messages. * - implement last io funcs. */ @@ -79,16 +78,22 @@ &pos->member != (head); \ pos = n, n = LIST_ENT(n->member.next, typeof(*n), member)) -/* fetxh libusb20_transfer from libusb20_device */ +/* fetch libusb20_transfer from libusb20_device */ #define GET_XFER(xfer, endpoint, pdev)\ xfer = libusb20_tr_get_pointer(pdev, \ (2 *endpoint)|(endpoint/0x80)); \ if (xfer == NULL) \ return (LIBUSB_ERROR_OTHER); + struct libusb_context *usbi_default_context = NULL; static pthread_mutex_t default_context_lock = PTHREAD_MUTEX_INITIALIZER; +/* if ctx is NULL use default context*/ + +#define GET_CONTEXT(ctx) \ + if (ctx == NULL) ctx = usbi_default_context; + /* Library initialisation / deinitialisation */ struct usb_pollfd { @@ -107,6 +112,7 @@ void libusb_set_debug(libusb_context * ctx, int level) { + GET_CONTEXT(ctx); if (ctx) ctx->debug = level; } @@ -247,6 +253,7 @@ struct libusb20_backend *usb_backend; int i; + GET_CONTEXT(ctx); usb_backend = libusb20_be_alloc_default(); if (usb_backend == NULL) return (-1); @@ -256,7 +263,7 @@ while ((pdev = libusb20_be_device_foreach(usb_backend, pdev))) i++; - if (!list) { + if (list == NULL) { libusb20_be_free(usb_backend); return (LIBUSB_ERROR_INVALID_PARAM); } @@ -822,6 +829,7 @@ { int ret; + GET_CONTEXT(ctx); pthread_mutex_lock(&ctx->pollfd_modify_lock); ret = ctx->pollfd_modify; pthread_mutex_unlock(&ctx->pollfd_modify_lock); @@ -841,6 +849,7 @@ void libusb_lock_events(libusb_context * ctx) { + GET_CONTEXT(ctx); pthread_mutex_lock(&ctx->events_lock); ctx->event_handler_active = 1; } @@ -848,6 +857,7 @@ void libusb_unlock_events(libusb_context * ctx) { + GET_CONTEXT(ctx); ctx->event_handler_active = 0; pthread_mutex_unlock(&ctx->events_lock); @@ -861,9 +871,11 @@ { int ret; + GET_CONTEXT(ctx); pthread_mutex_lock(&ctx->pollfd_modify_lock); ret = ctx->pollfd_modify; pthread_mutex_unlock(&ctx->pollfd_modify_lock); + if (ret) return (0); return (1); @@ -874,9 +886,11 @@ { int ret; + GET_CONTEXT(ctx); pthread_mutex_lock(&ctx->pollfd_modify_lock); ret = ctx->pollfd_modify; pthread_mutex_unlock(&ctx->pollfd_modify_lock); + if (ret) return (1); return (ctx->event_handler_active); @@ -885,6 +899,7 @@ void libusb_lock_event_waiters(libusb_context * ctx) { + GET_CONTEXT(ctx); pthread_mutex_lock(&ctx->event_waiters_lock); return; } @@ -892,6 +907,7 @@ void libusb_unlock_event_waiters(libusb_context * ctx) { + GET_CONTEXT(ctx); pthread_mutex_unlock(&ctx->event_waiters_lock); return; } @@ -902,6 +918,7 @@ int ret; struct timespec ts; + GET_CONTEXT(ctx); if (tv == NULL) { pthread_cond_wait(&ctx->event_waiters_cond, &ctx->event_waiters_lock); @@ -930,6 +947,7 @@ int libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv) { + GET_CONTEXT(ctx); return (0); } @@ -946,6 +964,7 @@ int libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv) { + GET_CONTEXT(ctx); return (0); } @@ -959,6 +978,7 @@ int found; int ret; + GET_CONTEXT(ctx); found = 0; pthread_mutex_lock(&ctx->flying_transfers_lock); if (USB_LIST_EMPTY(&ctx->flying_transfers)) @@ -998,6 +1018,7 @@ libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data) { + GET_CONTEXT(ctx); ctx->fd_added_cb = added_cb; ctx->fd_removed_cb = removed_cb; ctx->fd_cb_user_data = user_data; @@ -1010,6 +1031,7 @@ libusb_pollfd **ret; int i; + GET_CONTEXT(ctx); i = 0; pthread_mutex_lock(&ctx->pollfds_lock); LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list) ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#9 (text+ko) ====
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905171527.n4HFRfP3044742>