Merge "adb: add sysdeps/chrono.h for chrono literals on Win32."
am: e631e470e0
Change-Id: Ie62e995d9790bf7539f3f9fca05de7b4b359dc7c
This commit is contained in:
commit
27bbe8bfb2
|
@ -28,7 +28,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
@ -40,6 +39,7 @@
|
|||
#include "adb_io.h"
|
||||
#include "adb_utils.h"
|
||||
#include "socket_spec.h"
|
||||
#include "sysdeps/chrono.h"
|
||||
|
||||
static TransportType __adb_transport = kTransportAny;
|
||||
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");
|
||||
}
|
||||
// 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
|
||||
} else {
|
||||
// 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? */
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
std::this_thread::sleep_for(2s);
|
||||
goto start_server;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <android-base/stringprintf.h>
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
@ -61,6 +60,7 @@
|
|||
#include "file_sync_service.h"
|
||||
#include "services.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_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.
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
@ -33,6 +32,7 @@
|
|||
#include "fdevent_test.h"
|
||||
#include "socket.h"
|
||||
#include "sysdeps.h"
|
||||
#include "sysdeps/chrono.h"
|
||||
|
||||
struct ThreadArg {
|
||||
int first_read_fd;
|
||||
|
@ -46,7 +46,7 @@ static void FdEventThreadFunc(void*) {
|
|||
fdevent_loop();
|
||||
}
|
||||
|
||||
constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100);
|
||||
constexpr auto SLEEP_FOR_FDEVENT = 100ms;
|
||||
|
||||
TEST_F(LocalSocketTest, smoke) {
|
||||
// Join two socketpairs with a chain of intermediate socketpairs.
|
||||
|
@ -231,7 +231,7 @@ static void ClientThreadFunc() {
|
|||
std::string error;
|
||||
int fd = network_loopback_client(5038, SOCK_STREAM, &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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -18,15 +18,15 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "adb_io.h"
|
||||
#include "sysdeps.h"
|
||||
#include "sysdeps/chrono.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ TEST(sysdeps_thread, smoke) {
|
|||
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());
|
||||
}
|
||||
|
||||
|
@ -258,15 +258,15 @@ TEST(sysdeps_mutex, mutex_smoke) {
|
|||
ASSERT_FALSE(m.try_lock());
|
||||
m.lock();
|
||||
finished.store(true);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
std::this_thread::sleep_for(200ms);
|
||||
m.unlock();
|
||||
}, nullptr);
|
||||
|
||||
ASSERT_FALSE(finished.load());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(100ms);
|
||||
ASSERT_FALSE(finished.load());
|
||||
m.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(100ms);
|
||||
m.lock();
|
||||
ASSERT_TRUE(finished.load());
|
||||
m.unlock();
|
||||
|
@ -282,13 +282,13 @@ TEST(sysdeps_mutex, recursive_mutex_smoke) {
|
|||
adb_thread_create([](void*) {
|
||||
ASSERT_FALSE(m.try_lock());
|
||||
m.lock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
std::this_thread::sleep_for(500ms);
|
||||
m.unlock();
|
||||
}, nullptr);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(100ms);
|
||||
m.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(100ms);
|
||||
ASSERT_FALSE(m.try_lock());
|
||||
m.lock();
|
||||
m.unlock();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
@ -41,6 +40,7 @@
|
|||
#include "adb.h"
|
||||
#include "adb_io.h"
|
||||
#include "adb_utils.h"
|
||||
#include "sysdeps/chrono.h"
|
||||
|
||||
#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.
|
||||
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 {
|
||||
int port;
|
||||
|
@ -216,7 +216,7 @@ static void server_socket_thread(void* arg) {
|
|||
serverfd = network_inaddr_any_server(port, SOCK_STREAM, &error);
|
||||
if(serverfd < 0) {
|
||||
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;
|
||||
}
|
||||
close_on_exec(serverfd);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <android-base/errors.h>
|
||||
|
||||
#include "adb.h"
|
||||
#include "sysdeps/chrono.h"
|
||||
#include "transport.h"
|
||||
|
||||
/** Structure usb_handle describes our connection to the usb device via
|
||||
|
@ -179,7 +180,7 @@ void device_poll_thread(void*) {
|
|||
|
||||
while (true) {
|
||||
find_devices();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue