| Index: device/usb/usb_context.cc
|
| diff --git a/device/usb/usb_context.cc b/device/usb/usb_context.cc
|
| index 742b40d4517316f9e0421b1c1701c1e81f216602..ba9779831710d96421e85e8680cd166b601f9556 100644
|
| --- a/device/usb/usb_context.cc
|
| +++ b/device/usb/usb_context.cc
|
| @@ -6,7 +6,7 @@
|
|
|
| #include "base/atomicops.h"
|
| #include "base/logging.h"
|
| -#include "base/threading/platform_thread.h"
|
| +#include "base/threading/simple_thread.h"
|
| #include "device/usb/usb_error.h"
|
| #include "third_party/libusb/src/libusb/interrupt.h"
|
| #include "third_party/libusb/src/libusb/libusb.h"
|
| @@ -16,36 +16,32 @@ namespace device {
|
| // The UsbEventHandler works around a design flaw in the libusb interface. There
|
| // is currently no way to signal to libusb that any caller into one of the event
|
| // handler calls should return without handling any events.
|
| -class UsbContext::UsbEventHandler : public base::PlatformThread::Delegate {
|
| +class UsbContext::UsbEventHandler : public base::SimpleThread {
|
| public:
|
| explicit UsbEventHandler(libusb_context* context);
|
| ~UsbEventHandler() override;
|
|
|
| - // base::PlatformThread::Delegate
|
| - void ThreadMain() override;
|
| + // base::SimpleThread
|
| + void Run() override;
|
|
|
| void Stop();
|
|
|
| private:
|
| base::subtle::Atomic32 running_;
|
| libusb_context* context_;
|
| - base::PlatformThreadHandle thread_handle_;
|
| DISALLOW_COPY_AND_ASSIGN(UsbEventHandler);
|
| };
|
|
|
| UsbContext::UsbEventHandler::UsbEventHandler(libusb_context* context)
|
| - : context_(context), thread_handle_(0) {
|
| + : base::SimpleThread("UsbEventHandler"), context_(context) {
|
| base::subtle::Release_Store(&running_, 1);
|
| - bool success = base::PlatformThread::Create(0, this, &thread_handle_);
|
| - DCHECK(success) << "Failed to create USB IO handling thread.";
|
| }
|
|
|
| UsbContext::UsbEventHandler::~UsbEventHandler() {
|
| libusb_exit(context_);
|
| }
|
|
|
| -void UsbContext::UsbEventHandler::ThreadMain() {
|
| - base::PlatformThread::SetName("UsbEventHandler");
|
| +void UsbContext::UsbEventHandler::Run() {
|
| VLOG(1) << "UsbEventHandler started.";
|
|
|
| while (base::subtle::Acquire_Load(&running_)) {
|
| @@ -57,24 +53,23 @@ void UsbContext::UsbEventHandler::ThreadMain() {
|
| }
|
|
|
| VLOG(1) << "UsbEventHandler shutting down.";
|
| - delete this;
|
| }
|
|
|
| void UsbContext::UsbEventHandler::Stop() {
|
| - base::PlatformThreadHandle thread_handle = thread_handle_;
|
| base::subtle::Release_Store(&running_, 0);
|
| libusb_interrupt_handle_event(context_);
|
| - base::PlatformThread::Join(thread_handle);
|
| }
|
|
|
| UsbContext::UsbContext(PlatformUsbContext context) : context_(context) {
|
| // Ownership of the PlatformUsbContext is passed to the event handler thread.
|
| - event_handler_ = new UsbEventHandler(context_);
|
| + event_handler_.reset(new UsbEventHandler(context_));
|
| + event_handler_->Start();
|
| }
|
|
|
| UsbContext::~UsbContext() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| event_handler_->Stop();
|
| + event_handler_->Join();
|
| }
|
|
|
| } // namespace device
|
|
|