summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2016-02-25 21:42:46 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-26 05:43:51 +0000
commit449dde0f87ac33b516a1186398d17edbd75e4ee9 (patch)
tree47542d8f03b6856f2983cb00b9c805d8c4b2455c /device
parent25781b46304acccacc0baa6f69948724f3f6700a (diff)
downloadchromium_src-449dde0f87ac33b516a1186398d17edbd75e4ee9.zip
chromium_src-449dde0f87ac33b516a1186398d17edbd75e4ee9.tar.gz
chromium_src-449dde0f87ac33b516a1186398d17edbd75e4ee9.tar.bz2
Ensure libusb_close is called from the FILE thread.
If libusb_close is called from the UsbEventHandler thread then it will deadlock trying to reacquire libusb's open_devs_lock. To avoid this and generally ensure that libusb calls happen on the FILE thread this patch posts a task if the UsbDeviceHandleImpl destructor is not already running on the FILE thread. BUG=589592 Review URL: https://codereview.chromium.org/1736703002 Cr-Commit-Position: refs/heads/master@{#377821}
Diffstat (limited to 'device')
-rw-r--r--device/usb/usb_device_handle_impl.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/device/usb/usb_device_handle_impl.cc b/device/usb/usb_device_handle_impl.cc
index 716c6c1..cf6ebfb 100644
--- a/device/usb/usb_device_handle_impl.cc
+++ b/device/usb/usb_device_handle_impl.cc
@@ -782,8 +782,14 @@ UsbDeviceHandleImpl::UsbDeviceHandleImpl(
UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
// This class is RefCountedThreadSafe and so the destructor may be called on
- // any thread.
- libusb_close(handle_);
+ // any thread. libusb is not safe to reentrancy so be sure not to try to close
+ // the device from inside a transfer completion callback.
+ if (blocking_task_runner_->RunsTasksOnCurrentThread()) {
+ libusb_close(handle_);
+ } else {
+ blocking_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&libusb_close, handle_));
+ }
}
void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread(