Changeset 2a72f38548208044dc3aa62681419d006c35732d in libusb


Ignore:
Timestamp:
02/15/10 21:07:44 (7 months ago)
Author:
Daniel Drake <dan@…>
Children:
161893cfbefefe315f657677705abe090fc526f2
Parents:
a4186794d87124503db2f5f51f51ce90bb95daa7
git-author:
Nathan Hjelm <hjelmn@mac.com> / 2010-02-15T14:07:44Z-0600
git-committer:
Daniel Drake <dan@reactivated.net> / 2010-02-15T14:07:44Z-0600
Message:

Darwin: support multiple calls to libusb_init

Credit to Orin Eman for finding this bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libusb/os/darwin_usb.c

    r9cc6bf r2a72f3  
    4545static mach_port_t  libusb_darwin_mp = 0; /* master port */ 
    4646static CFRunLoopRef libusb_darwin_acfl = NULL; /* async cf loop */ 
     47static int initCount = 0; 
    4748 
    4849/* async event thread */ 
     
    310311  IOReturn kresult; 
    311312 
    312   /* Create the master port for talking to IOKit */ 
    313   if (!libusb_darwin_mp) { 
    314     kresult = IOMasterPort (MACH_PORT_NULL, &libusb_darwin_mp); 
    315  
    316     if (kresult != kIOReturnSuccess || !libusb_darwin_mp) 
    317       return darwin_to_libusb (kresult); 
    318   } 
    319  
    320   pthread_create (&libusb_darwin_at, NULL, event_thread_main, (void *)ctx); 
    321  
    322   while (!libusb_darwin_acfl) 
    323     usleep (10); 
     313  if (!(initCount++)) { 
     314    /* Create the master port for talking to IOKit */ 
     315    if (!libusb_darwin_mp) { 
     316      kresult = IOMasterPort (MACH_PORT_NULL, &libusb_darwin_mp); 
     317 
     318      if (kresult != kIOReturnSuccess || !libusb_darwin_mp) 
     319        return darwin_to_libusb (kresult); 
     320    } 
     321 
     322    pthread_create (&libusb_darwin_at, NULL, event_thread_main, (void *)ctx); 
     323 
     324    while (!libusb_darwin_acfl) 
     325      usleep (10); 
     326  } 
    324327 
    325328  return 0; 
     
    327330 
    328331static void darwin_exit (void) { 
    329   void *ret; 
    330  
    331   /* stop the async runloop */ 
    332   CFRunLoopStop (libusb_darwin_acfl); 
    333   pthread_join (libusb_darwin_at, &ret); 
    334  
    335   if (libusb_darwin_mp) 
    336     mach_port_deallocate(mach_task_self(), libusb_darwin_mp); 
    337  
    338   libusb_darwin_mp = 0; 
     332  if (!(--initCount)) { 
     333    void *ret; 
     334 
     335    /* stop the async runloop */ 
     336    CFRunLoopStop (libusb_darwin_acfl); 
     337    pthread_join (libusb_darwin_at, &ret); 
     338 
     339    if (libusb_darwin_mp) 
     340      mach_port_deallocate(mach_task_self(), libusb_darwin_mp); 
     341 
     342    libusb_darwin_mp = 0; 
     343  } 
    339344} 
    340345 
Note: See TracChangeset for help on using the changeset viewer.