Lines Matching refs:h

317 static int usb_bulk_write(usb_handle *h, const void *data, int len)  in usb_bulk_write()  argument
319 struct usbdevfs_urb *urb = &h->urb_out; in usb_bulk_write()
326 urb->endpoint = h->ep_out; in usb_bulk_write()
333 adb_mutex_lock(&h->lock); in usb_bulk_write()
334 if(h->dead) { in usb_bulk_write()
339 res = ioctl(h->desc, USBDEVFS_SUBMITURB, urb); in usb_bulk_write()
347 h->urb_out_busy = 1; in usb_bulk_write()
353 res = pthread_cond_timedwait(&h->notify, &h->lock, &ts); in usb_bulk_write()
354 if(res < 0 || h->dead) { in usb_bulk_write()
357 if(h->urb_out_busy == 0) { in usb_bulk_write()
365 adb_mutex_unlock(&h->lock); in usb_bulk_write()
370 static int usb_bulk_read(usb_handle *h, void *data, int len) in usb_bulk_read() argument
372 struct usbdevfs_urb *urb = &h->urb_in; in usb_bulk_read()
379 urb->endpoint = h->ep_in; in usb_bulk_read()
385 adb_mutex_lock(&h->lock); in usb_bulk_read()
386 if(h->dead) { in usb_bulk_read()
391 res = ioctl(h->desc, USBDEVFS_SUBMITURB, urb); in usb_bulk_read()
398 h->urb_in_busy = 1; in usb_bulk_read()
401 h->reaper_thread = pthread_self(); in usb_bulk_read()
402 adb_mutex_unlock(&h->lock); in usb_bulk_read()
403 res = ioctl(h->desc, USBDEVFS_REAPURB, &out); in usb_bulk_read()
405 adb_mutex_lock(&h->lock); in usb_bulk_read()
406 h->reaper_thread = 0; in usb_bulk_read()
407 if(h->dead) { in usb_bulk_read()
421 if(out == &h->urb_in) { in usb_bulk_read()
423 h->urb_in_busy = 0; in usb_bulk_read()
431 if(out == &h->urb_out) { in usb_bulk_read()
433 h->urb_out_busy = 0; in usb_bulk_read()
434 adb_cond_broadcast(&h->notify); in usb_bulk_read()
438 adb_mutex_unlock(&h->lock); in usb_bulk_read()
444 int usb_write(usb_handle *h, const void *_data, int len) in usb_write() argument
451 if(h->zero_mask) { in usb_write()
456 if(!(len & h->zero_mask)) { in usb_write()
464 n = usb_bulk_write(h, data, xfer); in usb_write()
476 n = usb_bulk_write(h, _data, 0); in usb_write()
484 int usb_read(usb_handle *h, void *_data, int len) in usb_read() argument
493 D("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname); in usb_read()
494 n = usb_bulk_read(h, data, xfer); in usb_read()
495 D("[ usb read %d ] = %d, fname=%s\n", xfer, n, h->fname); in usb_read()
497 if((errno == ETIMEDOUT) && (h->desc != -1)) { in usb_read()
518 void usb_kick(usb_handle *h) in usb_kick() argument
520 D("[ kicking %p (fd = %d) ]\n", h, h->desc); in usb_kick()
521 adb_mutex_lock(&h->lock); in usb_kick()
522 if(h->dead == 0) { in usb_kick()
523 h->dead = 1; in usb_kick()
525 if (h->writeable) { in usb_kick()
530 if (h->reaper_thread) { in usb_kick()
531 pthread_kill(h->reaper_thread, SIGALRM); in usb_kick()
539 ioctl(h->desc, USBDEVFS_DISCARDURB, &h->urb_in); in usb_kick()
540 ioctl(h->desc, USBDEVFS_DISCARDURB, &h->urb_out); in usb_kick()
541 h->urb_in.status = -ENODEV; in usb_kick()
542 h->urb_out.status = -ENODEV; in usb_kick()
543 h->urb_in_busy = 0; in usb_kick()
544 h->urb_out_busy = 0; in usb_kick()
545 adb_cond_broadcast(&h->notify); in usb_kick()
547 unregister_usb_transport(h); in usb_kick()
550 adb_mutex_unlock(&h->lock); in usb_kick()
553 int usb_close(usb_handle *h) in usb_close() argument
557 h->next->prev = h->prev; in usb_close()
558 h->prev->next = h->next; in usb_close()
559 h->prev = 0; in usb_close()
560 h->next = 0; in usb_close()
562 adb_close(h->desc); in usb_close()
563 D("-- usb closed %p (fd = %d) --\n", h, h->desc); in usb_close()
566 free(h); in usb_close()