Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/usb_context.h" | 5 #include "device/usb/usb_context.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "device/usb/usb_error.h" | 10 #include "device/usb/usb_error.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 VLOG(1) << "Failed to handle events: " | 54 VLOG(1) << "Failed to handle events: " |
| 55 << ConvertPlatformUsbErrorToString(rv); | 55 << ConvertPlatformUsbErrorToString(rv); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 VLOG(1) << "UsbEventHandler shutting down."; | 59 VLOG(1) << "UsbEventHandler shutting down."; |
| 60 delete this; | 60 delete this; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void UsbContext::UsbEventHandler::Stop() { | 63 void UsbContext::UsbEventHandler::Stop() { |
| 64 base::PlatformThreadHandle thread_handle = thread_handle_; | |
| 64 base::subtle::Release_Store(&running_, 0); | 65 base::subtle::Release_Store(&running_, 0); |
| 65 libusb_interrupt_handle_event(context_); | 66 libusb_interrupt_handle_event(context_); |
|
Reilly Grant (use Gerrit)
2015/08/10 17:14:08
context_ could also have been freed if there was a
| |
| 66 base::PlatformThread::Join(thread_handle_); | 67 base::PlatformThread::Join(thread_handle); |
| 67 } | 68 } |
| 68 | 69 |
| 69 UsbContext::UsbContext(PlatformUsbContext context) : context_(context) { | 70 UsbContext::UsbContext(PlatformUsbContext context) : context_(context) { |
| 70 // Ownership of the PlatformUsbContext is passed to the event handler thread. | 71 // Ownership of the PlatformUsbContext is passed to the event handler thread. |
| 71 event_handler_ = new UsbEventHandler(context_); | 72 event_handler_ = new UsbEventHandler(context_); |
| 72 } | 73 } |
| 73 | 74 |
| 74 UsbContext::~UsbContext() { | 75 UsbContext::~UsbContext() { |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 76 event_handler_->Stop(); | 77 event_handler_->Stop(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace device | 80 } // namespace device |
| OLD | NEW |