Date: Fri, 29 May 2009 18:36:23 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 163035 for review Message-ID: <200905291836.n4TIaN6t086664@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=163035 Change 163035 by syl@syl_rincewind on 2009/05/29 18:35:22 - Free ctx after the close in libusb_init. - Add use of default context in libusb_exit. - Unref device only if unref_device is set in libusb_free_device_list. - Replace libusb_unlock_events; by libusb_unlock_envents(ctx); - Use ugen fd into pollfds. Affected files ... .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#18 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#3 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#18 (text+ko) ==== @@ -111,9 +111,10 @@ } int -libusb_init(libusb_context ** contex) +libusb_init(libusb_context ** context) { struct libusb_context *ctx; + char * debug; int ret; ctx = malloc(sizeof(*ctx)); @@ -122,6 +123,13 @@ memset(ctx, 0, sizeof(*ctx)); + debug = getenv("LIBUSB_DEBUG"); + if (debug != NULL) { + ctx->debug = atoi(debug); + if (ctx->debug != 0) + ctx->debug_fixed = 1; + } + pthread_mutex_init(&ctx->usb_devs_lock, NULL); pthread_mutex_init(&ctx->open_devs_lock, NULL); USB_LIST_INIT(&ctx->usb_devs); @@ -139,19 +147,19 @@ ret = pipe(ctx->ctrl_pipe); if (ret < 0) { - free(ctx); usb_remove_pollfd(ctx, ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[1]); + free(ctx); return (LIBUSB_ERROR_OTHER); } ret = usb_add_pollfd(ctx, ctx->ctrl_pipe[0], POLLIN); if (ret < 0) { - free(ctx); usb_remove_pollfd(ctx, ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[1]); + free(ctx); return ret; } @@ -160,8 +168,8 @@ usbi_default_context = ctx; } - if (contex) - *contex = ctx; + if (context) + *context = ctx; return (0); } @@ -169,6 +177,8 @@ void libusb_exit(libusb_context * ctx) { + GET_CONTEXT(ctx); + usb_remove_pollfd(ctx, ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[0]); close(ctx->ctrl_pipe[1]); @@ -260,10 +270,10 @@ if (list == NULL) return ; - for (i = 0; list[i] != NULL; i++) { - libusb_unref_device(list[i]); + if (unref_devices) { + for (i = 0; list[i] != NULL; i++) + libusb_unref_device(list[i]); } - free(list); } @@ -357,9 +367,10 @@ libusb_context *ctx = dev->ctx; struct libusb20_device *pdev = dev->os_priv; libusb_device_handle *hdl; - unsigned char dummy = 1; + unsigned char dummy; int err; + dummy = 1; if (devh == NULL) return (LIBUSB_ERROR_INVALID_PARAM); @@ -378,6 +389,12 @@ hdl->dev = libusb_ref_device(dev); hdl->claimed_interfaces = 0; hdl->os_priv = dev->os_priv; + err = usb_add_pollfd(ctx, libusb20_dev_get_fd(pdev), POLLOUT); + if (err < 0) { + libusb_unref_device(dev); + free(hdl); + return (err); + } pthread_mutex_lock(&ctx->open_devs_lock); LIST_ADD(&hdl->list, &ctx->open_devs); @@ -402,7 +419,7 @@ pthread_mutex_lock(&ctx->pollfd_modify_lock); ctx->pollfd_modify--; pthread_mutex_unlock(&ctx->pollfd_modify_lock); - libusb_unlock_events; + libusb_unlock_events(ctx); return (0); } @@ -440,6 +457,9 @@ unsigned char dummy = 1; int err; + if (devh == NULL) + return ; + ctx = devh->dev->ctx; pdev = devh->os_priv; @@ -453,6 +473,8 @@ pthread_mutex_lock(&ctx->open_devs_lock); LIST_DEL(&devh->list); pthread_mutex_unlock(&ctx->open_devs_lock); + + usb_remove_pollfd(ctx, libusb20_dev_get_fd(pdev)); libusb_unref_device(devh->dev); libusb20_dev_close(pdev); free(devh); @@ -468,6 +490,8 @@ pthread_mutex_lock(&ctx->open_devs_lock); LIST_DEL(&devh->list); pthread_mutex_unlock(&ctx->open_devs_lock); + + usb_remove_pollfd(ctx, libusb20_dev_get_fd(pdev)); libusb_unref_device(devh->dev); libusb20_dev_close(pdev); free(devh); @@ -500,6 +524,9 @@ return (0); } +/* + * XXX this code is wrong. need update. + */ int libusb_set_configuration(libusb_device_handle * devh, int configuration) ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#3 (text+ko) ====
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905291836.n4TIaN6t086664>