Date: Fri, 26 Jun 2009 20:04:41 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 165280 for review Message-ID: <200906262004.n5QK4ffY065026@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=165280 Change 165280 by syl@syl_atuin on 2009/06/26 20:04:31 Changes suggested by Hans Petter Selasky. - Move static inline to global functions(). - Create a macro for UNEXPORTED functions. Affected files ... .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#49 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#11 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#17 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#49 (text+ko) ==== @@ -44,6 +44,28 @@ /* Library initialisation / deinitialisation */ +UNEXPORTED void +dprintf(libusb_context *ctx, int debug, char *str) +{ + if (ctx->debug != debug) + return ; + + switch (ctx->debug) { + case LIBUSB_DEBUG_NO: + break ; + case LIBUSB_DEBUG_FUNCTION: + printf("LIBUSB FUNCTION : %s\n", str); + break ; + case LIBUSB_DEBUG_TRANSFER: + printf("LIBUSB TRANSFER : %s\n", str); + break ; + default: + printf("LIBUSB UNKNOW DEBUG\n"); + break ; + } + return ; +} + void libusb_set_debug(libusb_context * ctx, int level) { ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#11 (text+ko) ==== @@ -74,28 +74,7 @@ #define MAX(a,b) (((a)>(b))?(a):(b)) #define USB_TIMED_OUT (1<<0) - -static inline void -dprintf(libusb_context *ctx, int debug, char *str) -{ - if (ctx->debug != debug) - return ; - - switch (ctx->debug) { - case LIBUSB_DEBUG_NO: - break ; - case LIBUSB_DEBUG_FUNCTION: - printf("LIBUSB FUNCTION : %s\n", str); - break ; - case LIBUSB_DEBUG_TRANSFER: - printf("LIBUSB TRANSFER : %s\n", str); - break ; - default: - printf("LIBUSB UNKNOW DEBUG\n"); - break ; - } - return ; -} +#define UNEXPORTED __attribute__((__visibility__("hidden"))) struct usb_pollfd { struct libusb_pollfd pollfd; @@ -110,127 +89,11 @@ uint8_t flags; }; -static inline int -usb_add_pollfd(libusb_context *ctx, int fd, short events) -{ - struct usb_pollfd *pollfd; - - if (ctx == NULL) - return (LIBUSB_ERROR_INVALID_PARAM); - - pollfd = malloc(sizeof(*pollfd)); - if (pollfd == NULL) - return (LIBUSB_ERROR_NO_MEM); - - pollfd->pollfd.fd = fd; - pollfd->pollfd.events = events; - - pthread_mutex_lock(&ctx->pollfds_lock); - LIST_ADD_TAIL(&pollfd->list, &ctx->pollfds); - pthread_mutex_unlock(&ctx->pollfds_lock); - - if (ctx->fd_added_cb) - ctx->fd_added_cb(fd, events, ctx->fd_cb_user_data); - return (0); -} - -static inline void -usb_remove_pollfd(libusb_context *ctx, int fd) -{ - struct usb_pollfd *pollfd; - int found; - - found = 0; - pthread_mutex_lock(&ctx->pollfds_lock); - - LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list) { - if (pollfd->pollfd.fd == fd) { - found = 1; - break ; - } - } - - if (found == 0) { - pthread_mutex_unlock(&ctx->pollfds_lock); - return ; - } - - LIST_DEL(&pollfd->list); - pthread_mutex_unlock(&ctx->pollfds_lock); - free(pollfd); - - if (ctx->fd_removed_cb) - ctx->fd_removed_cb(fd, ctx->fd_cb_user_data); -} - -static inline void -usb_handle_transfer_completion(struct usb_transfer *uxfer, - enum libusb_transfer_status status) -{ - libusb_transfer *xfer; - libusb_context *ctx; - int len; - - xfer = (struct libusb_transfer *) ((uint8_t *)uxfer + - sizeof(struct usb_transfer)); - ctx = xfer->dev_handle->dev->ctx; - - pthread_mutex_lock(&ctx->flying_transfers_lock); - LIST_DEL(&uxfer->list); - pthread_mutex_unlock(&ctx->flying_transfers_lock); - - if (status == LIBUSB_TRANSFER_COMPLETED && xfer->flags & - LIBUSB_TRANSFER_SHORT_NOT_OK) { - len = xfer->length; - if (xfer->type == LIBUSB_TRANSFER_TYPE_CONTROL) - len -= sizeof(libusb_control_setup); - if (len != uxfer->transferred) { - status = LIBUSB_TRANSFER_ERROR; - } - } - - xfer->status = status; - xfer->actual_length = uxfer->transferred; - - if (xfer->callback) - xfer->callback(xfer); - if (xfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER) - libusb_free_transfer(xfer); - - pthread_mutex_lock(&ctx->event_waiters_lock); - pthread_cond_broadcast(&ctx->event_waiters_cond); - pthread_mutex_unlock(&ctx->event_waiters_lock); -} - -static inline void -usb_handle_disconnect(struct libusb_device_handle *devh) -{ - struct libusb_context *ctx; - struct libusb_transfer *xfer; - struct usb_transfer *cur; - struct usb_transfer *to_cancel; - - ctx = devh->dev->ctx; - - while (1) { - pthread_mutex_lock(&ctx->flying_transfers_lock); - to_cancel = NULL; - LIST_FOREACH_ENTRY(cur, &ctx->flying_transfers, list) { - xfer = (struct libusb_transfer *) ((uint8_t *)cur + - sizeof(struct usb_transfer)); - if (xfer->dev_handle == devh) { - to_cancel = cur; - break ; - } - } - pthread_mutex_unlock(&ctx->flying_transfers_lock); - - if (to_cancel == NULL) - break ; - - usb_handle_transfer_completion(to_cancel, LIBUSB_TRANSFER_NO_DEVICE); - } - return ; -} +UNEXPORTED void dprintf(libusb_context *ctx, int debug, char *str); +UNEXPORTED int usb_add_pollfd(libusb_context *ctx, int fd, short events); +UNEXPORTED void usb_remove_pollfd(libusb_context *ctx, int fd); +UNEXPORTED void usb_handle_transfer_completion(struct usb_transfer *uxfer, + enum libusb_transfer_status status); +UNEXPORTED void usb_handle_disconnect(struct libusb_device_handle *devh); #endif /*__LIBUSB10_H__*/ ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#17 (text+ko) ==== @@ -38,7 +38,130 @@ #include "libusb.h" #include "libusb10.h" -static int +UNEXPORTED int +usb_add_pollfd(libusb_context *ctx, int fd, short events) +{ + struct usb_pollfd *pollfd; + + if (ctx == NULL) + return (LIBUSB_ERROR_INVALID_PARAM); + + pollfd = malloc(sizeof(*pollfd)); + if (pollfd == NULL) + return (LIBUSB_ERROR_NO_MEM); + + pollfd->pollfd.fd = fd; + pollfd->pollfd.events = events; + + pthread_mutex_lock(&ctx->pollfds_lock); + LIST_ADD_TAIL(&pollfd->list, &ctx->pollfds); + pthread_mutex_unlock(&ctx->pollfds_lock); + + if (ctx->fd_added_cb) + ctx->fd_added_cb(fd, events, ctx->fd_cb_user_data); + return (0); +} + +UNEXPORTED void +usb_remove_pollfd(libusb_context *ctx, int fd) +{ + struct usb_pollfd *pollfd; + int found; + + found = 0; + pthread_mutex_lock(&ctx->pollfds_lock); + + LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list) { + if (pollfd->pollfd.fd == fd) { + found = 1; + break ; + } + } + + if (found == 0) { + pthread_mutex_unlock(&ctx->pollfds_lock); + return ; + } + + LIST_DEL(&pollfd->list); + pthread_mutex_unlock(&ctx->pollfds_lock); + free(pollfd); + + if (ctx->fd_removed_cb) + ctx->fd_removed_cb(fd, ctx->fd_cb_user_data); +} + +UNEXPORTED void +usb_handle_transfer_completion(struct usb_transfer *uxfer, + enum libusb_transfer_status status) +{ + libusb_transfer *xfer; + libusb_context *ctx; + int len; + + xfer = (struct libusb_transfer *) ((uint8_t *)uxfer + + sizeof(struct usb_transfer)); + ctx = xfer->dev_handle->dev->ctx; + + pthread_mutex_lock(&ctx->flying_transfers_lock); + LIST_DEL(&uxfer->list); + pthread_mutex_unlock(&ctx->flying_transfers_lock); + + if (status == LIBUSB_TRANSFER_COMPLETED && xfer->flags & + LIBUSB_TRANSFER_SHORT_NOT_OK) { + len = xfer->length; + if (xfer->type == LIBUSB_TRANSFER_TYPE_CONTROL) + len -= sizeof(libusb_control_setup); + if (len != uxfer->transferred) { + status = LIBUSB_TRANSFER_ERROR; + } + } + + xfer->status = status; + xfer->actual_length = uxfer->transferred; + + if (xfer->callback) + xfer->callback(xfer); + if (xfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER) + libusb_free_transfer(xfer); + + pthread_mutex_lock(&ctx->event_waiters_lock); + pthread_cond_broadcast(&ctx->event_waiters_cond); + pthread_mutex_unlock(&ctx->event_waiters_lock); +} + +UNEXPORTED void +usb_handle_disconnect(struct libusb_device_handle *devh) +{ + struct libusb_context *ctx; + struct libusb_transfer *xfer; + struct usb_transfer *cur; + struct usb_transfer *to_cancel; + + ctx = devh->dev->ctx; + + while (1) { + pthread_mutex_lock(&ctx->flying_transfers_lock); + to_cancel = NULL; + LIST_FOREACH_ENTRY(cur, &ctx->flying_transfers, list) { + xfer = (struct libusb_transfer *) ((uint8_t *)cur + + sizeof(struct usb_transfer)); + if (xfer->dev_handle == devh) { + to_cancel = cur; + break ; + } + } + pthread_mutex_unlock(&ctx->flying_transfers_lock); + + if (to_cancel == NULL) + break ; + + usb_handle_transfer_completion(to_cancel, LIBUSB_TRANSFER_NO_DEVICE); + } + return ; +} + +UNEXPORTED int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out) { struct timeval timeout; @@ -60,7 +183,7 @@ return (0); } -static int +UNEXPORTED int handle_timeouts(struct libusb_context *ctx) { struct timespec sys_ts; @@ -103,7 +226,7 @@ return (ret); } -static int +UNEXPORTED int handle_events(struct libusb_context *ctx, struct timeval *tv) { struct libusb_pollfd *tmppollfd;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906262004.n5QK4ffY065026>