From owner-p4-projects@FreeBSD.ORG Fri May 29 18:36:24 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 17BDE106567C; Fri, 29 May 2009 18:36:24 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C25191065679 for ; Fri, 29 May 2009 18:36:23 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 9C2FA8FC26 for ; Fri, 29 May 2009 18:36:23 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n4TIaNW0086666 for ; Fri, 29 May 2009 18:36:23 GMT (envelope-from syl@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n4TIaN6t086664 for perforce@freebsd.org; Fri, 29 May 2009 18:36:23 GMT (envelope-from syl@FreeBSD.org) Date: Fri, 29 May 2009 18:36:23 GMT Message-Id: <200905291836.n4TIaN6t086664@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to syl@FreeBSD.org using -f From: Sylvestre Gallon To: Perforce Change Reviews Cc: Subject: PERFORCE change 163035 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 May 2009 18:36:25 -0000 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) ====