Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: device/usb/usb_device_handle_impl.cc

Issue 1736703002: Ensure libusb_close is called from the FILE thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_handle_impl.cc
diff --git a/device/usb/usb_device_handle_impl.cc b/device/usb/usb_device_handle_impl.cc
index 716c6c196611213a625c5ce329cb0945e1c835a0..cf6ebfb13efd51c91b81f4ca69934e00a132a617 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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698