diff options
author | Elliott Hughes <enh@google.com> | 2016-11-14 17:08:47 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-11-14 17:08:47 -0800 |
commit | 290a228fdca935ab2e702db77516758314900c3a (patch) | |
tree | bdb1606d717b50aded201e69bb2f29daa451b73e /fastboot/usb_linux.cpp | |
parent | f77d8b04528775e7a2e22255bb9a46b0e1df8ef1 (diff) |
Switch fastboot/init/libprocessgroup to std::this_thread::sleep_for.
Bug: http://b/32878766
Test: boots
Change-Id: Ie0ddfb7e60f2da5f6eefbb10c83a92e88c137ae3
Diffstat (limited to 'fastboot/usb_linux.cpp')
-rw-r--r-- | fastboot/usb_linux.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/fastboot/usb_linux.cpp b/fastboot/usb_linux.cpp index 6db1e2727..cdab4f1d2 100644 --- a/fastboot/usb_linux.cpp +++ b/fastboot/usb_linux.cpp @@ -43,11 +43,15 @@ #include <linux/version.h> #include <linux/usb/ch9.h> +#include <chrono> #include <memory> +#include <thread> #include "fastboot.h" #include "usb.h" +using namespace std::chrono_literals; + #define MAX_RETRIES 5 /* Timeout in seconds for usb_wait_for_disconnect. @@ -426,7 +430,7 @@ ssize_t LinuxUsbTransport::Read(void* _data, size_t len) return -1; } - while(len > 0) { + while (len > 0) { int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len; bulk.ep = handle_->ep_in; @@ -435,18 +439,17 @@ ssize_t LinuxUsbTransport::Read(void* _data, size_t len) bulk.timeout = 0; retry = 0; - do{ - DBG("[ usb read %d fd = %d], fname=%s\n", xfer, handle_->desc, handle_->fname); - n = ioctl(handle_->desc, USBDEVFS_BULK, &bulk); - DBG("[ usb read %d ] = %d, fname=%s, Retry %d \n", xfer, n, handle_->fname, retry); + do { + DBG("[ usb read %d fd = %d], fname=%s\n", xfer, handle_->desc, handle_->fname); + n = ioctl(handle_->desc, USBDEVFS_BULK, &bulk); + DBG("[ usb read %d ] = %d, fname=%s, Retry %d \n", xfer, n, handle_->fname, retry); - if( n < 0 ) { - DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno)); - if ( ++retry > MAX_RETRIES ) return -1; - sleep( 1 ); - } - } - while( n < 0 ); + if (n < 0) { + DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno)); + if (++retry > MAX_RETRIES) return -1; + std::this_thread::sleep_for(1s); + } + } while (n < 0); count += n; len -= n; @@ -488,9 +491,8 @@ int LinuxUsbTransport::WaitForDisconnect() { double deadline = now() + WAIT_FOR_DISCONNECT_TIMEOUT; while (now() < deadline) { - if (access(handle_->fname, F_OK)) - return 0; - usleep(50000); + if (access(handle_->fname, F_OK)) return 0; + std::this_thread::sleep_for(50ms); } return -1; } |