Merge "adb: add sysdeps/chrono.h for chrono literals on Win32." am: e631e470e0

am: 27bbe8bfb2

Change-Id: Ib5069a8811f8c5e4b21cc849f9e57c4c4d488276
This commit is contained in:
Josh Gao 2016-11-16 22:37:29 +00:00 committed by android-build-merger
commit c98fa1a51c
8 changed files with 68 additions and 22 deletions

View file

@ -28,7 +28,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <chrono>
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
@ -40,6 +39,7 @@
#include "adb_io.h" #include "adb_io.h"
#include "adb_utils.h" #include "adb_utils.h"
#include "socket_spec.h" #include "socket_spec.h"
#include "sysdeps/chrono.h"
static TransportType __adb_transport = kTransportAny; static TransportType __adb_transport = kTransportAny;
static const char* __adb_serial = NULL; static const char* __adb_serial = NULL;
@ -191,7 +191,7 @@ int adb_connect(const std::string& service, std::string* error) {
fprintf(stdout,"* daemon started successfully *\n"); fprintf(stdout,"* daemon started successfully *\n");
} }
// Give the server some time to start properly and detect devices. // Give the server some time to start properly and detect devices.
std::this_thread::sleep_for(std::chrono::seconds(3)); std::this_thread::sleep_for(3s);
// fall through to _adb_connect // fall through to _adb_connect
} else { } else {
// If a server is already running, check its version matches. // If a server is already running, check its version matches.
@ -236,7 +236,7 @@ int adb_connect(const std::string& service, std::string* error) {
} }
/* XXX can we better detect its death? */ /* XXX can we better detect its death? */
std::this_thread::sleep_for(std::chrono::seconds(2)); std::this_thread::sleep_for(2s);
goto start_server; goto start_server;
} }
} }

View file

@ -20,7 +20,6 @@
#include <unistd.h> #include <unistd.h>
#include <chrono>
#include <thread> #include <thread>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>

View file

@ -31,7 +31,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <chrono>
#include <memory> #include <memory>
#include <string> #include <string>
#include <thread> #include <thread>
@ -61,6 +60,7 @@
#include "file_sync_service.h" #include "file_sync_service.h"
#include "services.h" #include "services.h"
#include "shell_service.h" #include "shell_service.h"
#include "sysdeps/chrono.h"
static int install_app(TransportType t, const char* serial, int argc, const char** argv); static int install_app(TransportType t, const char* serial, int argc, const char** argv);
static int install_multiple_app(TransportType t, const char* serial, int argc, const char** argv); static int install_multiple_app(TransportType t, const char* serial, int argc, const char** argv);
@ -1082,7 +1082,7 @@ static bool adb_root(const char* command) {
// Give adbd some time to kill itself and come back up. // Give adbd some time to kill itself and come back up.
// We can't use wait-for-device because devices (e.g. adb over network) might not come back. // We can't use wait-for-device because devices (e.g. adb over network) might not come back.
std::this_thread::sleep_for(std::chrono::seconds(3)); std::this_thread::sleep_for(3s);
return true; return true;
} }

View file

@ -19,7 +19,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <array> #include <array>
#include <chrono>
#include <limits> #include <limits>
#include <queue> #include <queue>
#include <string> #include <string>
@ -33,6 +32,7 @@
#include "fdevent_test.h" #include "fdevent_test.h"
#include "socket.h" #include "socket.h"
#include "sysdeps.h" #include "sysdeps.h"
#include "sysdeps/chrono.h"
struct ThreadArg { struct ThreadArg {
int first_read_fd; int first_read_fd;
@ -46,7 +46,7 @@ static void FdEventThreadFunc(void*) {
fdevent_loop(); fdevent_loop();
} }
constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100); constexpr auto SLEEP_FOR_FDEVENT = 100ms;
TEST_F(LocalSocketTest, smoke) { TEST_F(LocalSocketTest, smoke) {
// Join two socketpairs with a chain of intermediate socketpairs. // Join two socketpairs with a chain of intermediate socketpairs.
@ -231,7 +231,7 @@ static void ClientThreadFunc() {
std::string error; std::string error;
int fd = network_loopback_client(5038, SOCK_STREAM, &error); int fd = network_loopback_client(5038, SOCK_STREAM, &error);
ASSERT_GE(fd, 0) << error; ASSERT_GE(fd, 0) << error;
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(200ms);
ASSERT_EQ(0, adb_close(fd)); ASSERT_EQ(0, adb_close(fd));
} }

46
adb/sysdeps/chrono.h Normal file
View file

@ -0,0 +1,46 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <chrono>
#if defined(_WIN32)
// We don't have C++14 on Windows yet.
// Reimplement std::chrono_literals ourselves until we do.
// Silence the following warning (which gets promoted to an error):
// error: literal operator suffixes not preceded by _ are reserved for future standardization
#pragma GCC system_header
constexpr std::chrono::seconds operator"" s(unsigned long long s) {
return std::chrono::seconds(s);
}
constexpr std::chrono::duration<long double> operator"" s(long double s) {
return std::chrono::duration<long double>(s);
}
constexpr std::chrono::milliseconds operator"" ms(unsigned long long ms) {
return std::chrono::milliseconds(ms);
}
constexpr std::chrono::duration<long double, std::milli> operator"" ms(long double ms) {
return std::chrono::duration<long double, std::milli>(ms);
}
#else
using namespace std::chrono_literals;
#endif

View file

@ -18,15 +18,15 @@
#include <unistd.h> #include <unistd.h>
#include <atomic> #include <atomic>
#include <chrono>
#include <condition_variable> #include <condition_variable>
#include <thread> #include <thread>
#include "adb_io.h" #include "adb_io.h"
#include "sysdeps.h" #include "sysdeps.h"
#include "sysdeps/chrono.h"
static void increment_atomic_int(void* c) { static void increment_atomic_int(void* c) {
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(1s);
reinterpret_cast<std::atomic<int>*>(c)->fetch_add(1); reinterpret_cast<std::atomic<int>*>(c)->fetch_add(1);
} }
@ -37,7 +37,7 @@ TEST(sysdeps_thread, smoke) {
ASSERT_TRUE(adb_thread_create(increment_atomic_int, &counter)); ASSERT_TRUE(adb_thread_create(increment_atomic_int, &counter));
} }
std::this_thread::sleep_for(std::chrono::seconds(2)); std::this_thread::sleep_for(2s);
ASSERT_EQ(100, counter.load()); ASSERT_EQ(100, counter.load());
} }
@ -258,15 +258,15 @@ TEST(sysdeps_mutex, mutex_smoke) {
ASSERT_FALSE(m.try_lock()); ASSERT_FALSE(m.try_lock());
m.lock(); m.lock();
finished.store(true); finished.store(true);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(200ms);
m.unlock(); m.unlock();
}, nullptr); }, nullptr);
ASSERT_FALSE(finished.load()); ASSERT_FALSE(finished.load());
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(100ms);
ASSERT_FALSE(finished.load()); ASSERT_FALSE(finished.load());
m.unlock(); m.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(100ms);
m.lock(); m.lock();
ASSERT_TRUE(finished.load()); ASSERT_TRUE(finished.load());
m.unlock(); m.unlock();
@ -282,13 +282,13 @@ TEST(sysdeps_mutex, recursive_mutex_smoke) {
adb_thread_create([](void*) { adb_thread_create([](void*) {
ASSERT_FALSE(m.try_lock()); ASSERT_FALSE(m.try_lock());
m.lock(); m.lock();
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(500ms);
m.unlock(); m.unlock();
}, nullptr); }, nullptr);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(100ms);
m.unlock(); m.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(100ms);
ASSERT_FALSE(m.try_lock()); ASSERT_FALSE(m.try_lock());
m.lock(); m.lock();
m.unlock(); m.unlock();

View file

@ -25,7 +25,6 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <chrono>
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -41,6 +40,7 @@
#include "adb.h" #include "adb.h"
#include "adb_io.h" #include "adb_io.h"
#include "adb_utils.h" #include "adb_utils.h"
#include "sysdeps/chrono.h"
#if ADB_HOST #if ADB_HOST
@ -146,7 +146,7 @@ static void PollAllLocalPortsForEmulator() {
// Retry the disconnected local port for 60 times, and sleep 1 second between two retries. // Retry the disconnected local port for 60 times, and sleep 1 second between two retries.
constexpr uint32_t LOCAL_PORT_RETRY_COUNT = 60; constexpr uint32_t LOCAL_PORT_RETRY_COUNT = 60;
constexpr auto LOCAL_PORT_RETRY_INTERVAL = std::chrono::seconds(1); constexpr auto LOCAL_PORT_RETRY_INTERVAL = 1s;
struct RetryPort { struct RetryPort {
int port; int port;
@ -216,7 +216,7 @@ static void server_socket_thread(void* arg) {
serverfd = network_inaddr_any_server(port, SOCK_STREAM, &error); serverfd = network_inaddr_any_server(port, SOCK_STREAM, &error);
if(serverfd < 0) { if(serverfd < 0) {
D("server: cannot bind socket yet: %s", error.c_str()); D("server: cannot bind socket yet: %s", error.c_str());
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(1s);
continue; continue;
} }
close_on_exec(serverfd); close_on_exec(serverfd);

View file

@ -35,6 +35,7 @@
#include <android-base/errors.h> #include <android-base/errors.h>
#include "adb.h" #include "adb.h"
#include "sysdeps/chrono.h"
#include "transport.h" #include "transport.h"
/** Structure usb_handle describes our connection to the usb device via /** Structure usb_handle describes our connection to the usb device via
@ -179,7 +180,7 @@ void device_poll_thread(void*) {
while (true) { while (true) {
find_devices(); find_devices();
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(1s);
} }
} }