From 37942ea1e7a5b4765f34d55a0cab8521447c0b91 Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Fri, 17 Jul 2020 02:08:15 -0700 Subject: [PATCH] Windows cleanup (#9508) * Remove unneeded code for Windows * Get rid of usleep() * Make platform_shims includes non-transitive Co-authored-by: Mehrdad --- BUILD.bazel | 12 +- bazel/BUILD.hiredis | 1 - src/ray/common/test_util.cc | 14 +-- src/ray/core_worker/test/core_worker_test.cc | 6 +- .../test/direct_task_transport_test.cc | 3 +- .../gcs_client/service_based_gcs_client.cc | 7 +- .../test/service_based_gcs_client_test.cc | 10 +- src/ray/gcs/pubsub/test/gcs_pub_sub_test.cc | 2 +- src/ray/gcs/redis_client.cc | 6 +- src/ray/gcs/redis_context.cc | 3 +- src/ray/object_manager/plasma/client.cc | 8 +- src/ray/object_manager/plasma/fling.h | 2 + src/ray/object_manager/plasma/io.cc | 9 +- src/ray/object_manager/plasma/io.h | 2 + src/ray/object_manager/plasma/plasma.cc | 2 + src/ray/object_manager/plasma/store_runner.cc | 2 + src/ray/rpc/grpc_server.cc | 3 +- src/ray/thirdparty/ae/ae_select.c | 4 + src/ray/util/logging.cc | 13 ++- src/ray/util/process.cc | 4 +- src/ray/util/sequencer_test.cc | 9 +- src/ray/util/signal_test.cc | 2 +- src/shims/windows/arpa/inet.h | 4 - src/shims/windows/getopt.cc | 103 ------------------ src/shims/windows/getopt.h | 8 -- src/shims/windows/netdb.h | 6 - src/shims/windows/netinet/in.h | 4 - src/shims/windows/netinet/tcp.h | 4 - src/shims/windows/pthread.h | 13 --- src/shims/windows/strings.h | 12 -- src/shims/windows/sys/ioctl.h | 4 - src/shims/windows/sys/select.h | 4 - src/shims/windows/sys/statvfs.h | 4 - src/shims/windows/sys/syslog.h | 4 - src/shims/windows/sys/un.h | 17 --- src/shims/windows/syslog.h | 1 - src/shims/windows/unistd.cc | 13 +-- src/shims/windows/unistd.h | 47 +------- streaming/src/util/streaming_logging.cc | 4 - 39 files changed, 84 insertions(+), 292 deletions(-) delete mode 100644 src/shims/windows/arpa/inet.h delete mode 100644 src/shims/windows/getopt.cc delete mode 100644 src/shims/windows/getopt.h delete mode 100644 src/shims/windows/netdb.h delete mode 100644 src/shims/windows/netinet/in.h delete mode 100644 src/shims/windows/netinet/tcp.h delete mode 100644 src/shims/windows/pthread.h delete mode 100644 src/shims/windows/strings.h delete mode 100644 src/shims/windows/sys/ioctl.h delete mode 100644 src/shims/windows/sys/select.h delete mode 100644 src/shims/windows/sys/statvfs.h delete mode 100644 src/shims/windows/sys/syslog.h delete mode 100644 src/shims/windows/sys/un.h delete mode 100644 src/shims/windows/syslog.h diff --git a/BUILD.bazel b/BUILD.bazel index f74780747..b076ce82f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -341,7 +341,6 @@ cc_library( deps = [ ":object_manager_fbs", ":plasma_fbs", - ":platform_shims", ":ray_common", ":ray_util", "@arrow", @@ -415,7 +414,6 @@ cc_library( deps = [ ":ae", ":plasma_client", - ":platform_shims", "@com_github_google_glog//:glog", ], ) @@ -429,7 +427,6 @@ cc_binary( visibility = ["//visibility:public"], deps = [ ":plasma_store_server_lib", - ":platform_shims", ], ) @@ -1359,11 +1356,9 @@ cc_library( "//conditions:default": [], }), copts = COPTS, - includes = [] + select({ - "@bazel_tools//src/conditions:windows": [ - "src/shims/windows", - ], - "//conditions:default": [], + strip_include_prefix = select({ + "@bazel_tools//src/conditions:windows": "src/shims/windows", + "//conditions:default": "", }), visibility = ["//visibility:public"], ) @@ -1387,7 +1382,6 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ - ":platform_shims", ":sha256", "@boost//:asio", "@com_github_google_glog//:glog", diff --git a/bazel/BUILD.hiredis b/bazel/BUILD.hiredis index 82c26febb..aaf82e71f 100644 --- a/bazel/BUILD.hiredis +++ b/bazel/BUILD.hiredis @@ -44,7 +44,6 @@ cc_library( include_prefix = "hiredis", deps = [ ":_hiredis", - "@//:platform_shims", ], visibility = ["//visibility:public"], ) diff --git a/src/ray/common/test_util.cc b/src/ray/common/test_util.cc index c1824a7c6..c66298907 100644 --- a/src/ray/common/test_util.cc +++ b/src/ray/common/test_util.cc @@ -53,7 +53,7 @@ int TestSetupUtil::StartUpRedisServer(const int &port) { cmdargs.insert(cmdargs.end(), {"--port", std::to_string(actual_port)}); RAY_LOG(INFO) << "Start redis command is: " << CreateCommandLine(cmdargs); RAY_CHECK(!Process::Spawn(cmdargs, true).second); - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); return actual_port; } @@ -71,7 +71,7 @@ void TestSetupUtil::ShutDownRedisServer(const int &port) { if (Process::Call(cmdargs) != std::error_code()) { RAY_LOG(WARNING) << "Failed to stop redis. The redis process may no longer exist."; } - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } void TestSetupUtil::FlushAllRedisServers() { @@ -87,7 +87,7 @@ void TestSetupUtil::FlushRedisServer(const int &port) { if (Process::Call(cmdargs)) { RAY_LOG(WARNING) << "Failed to flush redis. The redis process may no longer exist."; } - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } std::string TestSetupUtil::StartObjectStore( @@ -104,7 +104,7 @@ std::string TestSetupUtil::StartObjectStore( {TEST_STORE_EXEC_PATH, "-m", "10000000", "-s", store_socket_name}); RAY_LOG(DEBUG) << CreateCommandLine(cmdargs); RAY_CHECK(!Process::Spawn(cmdargs, true, store_socket_name + ".pid").second); - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); return store_socket_name; } @@ -120,7 +120,7 @@ std::string TestSetupUtil::StartGcsServer(const std::string &redis_address) { "--config_list=initial_reconstruction_timeout_milliseconds,2000"}); RAY_LOG(INFO) << "Start gcs server command: " << CreateCommandLine(cmdargs); RAY_CHECK(!Process::Spawn(cmdargs, true, gcs_server_socket_name + ".pid").second); - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); RAY_LOG(INFO) << "GCS server started."; return gcs_server_socket_name; } @@ -149,7 +149,7 @@ std::string TestSetupUtil::StartRaylet(const std::string &store_socket_name, "--config_list=initial_reconstruction_timeout_milliseconds,2000"}); RAY_LOG(DEBUG) << "Raylet Start command: " << CreateCommandLine(cmdargs); RAY_CHECK(!Process::Spawn(cmdargs, true, raylet_socket_name + ".pid").second); - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); return raylet_socket_name; } @@ -166,7 +166,7 @@ bool WaitForCondition(std::function condition, int timeout_ms) { // sleep 10ms. const int wait_interval_ms = 10; - usleep(wait_interval_ms * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(wait_interval_ms)); wait_time += wait_interval_ms; if (wait_time > timeout_ms) { break; diff --git a/src/ray/core_worker/test/core_worker_test.cc b/src/ray/core_worker/test/core_worker_test.cc index 18ac0a6c1..b89e21abc 100644 --- a/src/ray/core_worker/test/core_worker_test.cc +++ b/src/ray/core_worker/test/core_worker_test.cc @@ -710,7 +710,7 @@ TEST_F(SingleNodeTest, TestMemoryStoreProvider) { provider.Delete(ids_set, &plasma_object_ids); ASSERT_TRUE(plasma_object_ids.empty()); - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); ASSERT_TRUE(provider.Get(ids_set, 0, ctx, &results, &got_exception).IsTimedOut()); ASSERT_TRUE(!got_exception); ASSERT_EQ(results.size(), 0); @@ -725,7 +725,7 @@ TEST_F(SingleNodeTest, TestMemoryStoreProvider) { } auto thread_func = [&unready_ids, &provider, &buffers]() { - sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); for (size_t i = 0; i < unready_ids.size(); i++) { RAY_CHECK(provider.Put(buffers[i], unready_ids[i])); @@ -821,7 +821,7 @@ TEST_F(SingleNodeTest, TestObjectInterface) { // Note that Delete() calls RayletClient::FreeObjects and would not // wait for objects being deleted, so wait a while for plasma store // to process the command. - usleep(200 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); ASSERT_TRUE(core_worker.Get(ids, 0, &results).ok()); // Since array2 has been deleted from the plasma store, the Get should // return UnreconstructableError for all results. diff --git a/src/ray/core_worker/test/direct_task_transport_test.cc b/src/ray/core_worker/test/direct_task_transport_test.cc index 871550a1e..dd965b41a 100644 --- a/src/ray/core_worker/test/direct_task_transport_test.cc +++ b/src/ray/core_worker/test/direct_task_transport_test.cc @@ -921,7 +921,8 @@ TEST(DirectTaskTransportTest, TestWorkerLeaseTimeout) { // Task 2 runs successfully on the second worker; the worker is returned due to the // timeout. ASSERT_TRUE(raylet_client->GrantWorkerLease("localhost", 1001, ClientID::Nil())); - usleep(10 * 1000); // Sleep for 10ms, causing the lease to time out. + std::this_thread::sleep_for( + std::chrono::milliseconds(10)); // Sleep for 10ms, causing the lease to time out. ASSERT_TRUE(worker_client->ReplyPushTask()); ASSERT_EQ(raylet_client->num_workers_returned, 1); ASSERT_EQ(raylet_client->num_workers_disconnected, 1); diff --git a/src/ray/gcs/gcs_client/service_based_gcs_client.cc b/src/ray/gcs/gcs_client/service_based_gcs_client.cc index 58fcf0f6f..5bc7cfa9a 100644 --- a/src/ray/gcs/gcs_client/service_based_gcs_client.cc +++ b/src/ray/gcs/gcs_client/service_based_gcs_client.cc @@ -112,8 +112,8 @@ bool ServiceBasedGcsClient::GetGcsServerAddressFromRedis( num_attempts++; if (num_attempts < max_attempts) { - usleep(RayConfig::instance().internal_gcs_service_connect_wait_milliseconds() * - 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().internal_gcs_service_connect_wait_milliseconds())); } } @@ -194,7 +194,8 @@ void ServiceBasedGcsClient::ReconnectGcsServer() { break; } } - usleep(RayConfig::instance().ping_gcs_rpc_server_interval_milliseconds() * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().ping_gcs_rpc_server_interval_milliseconds())); } if (index < RayConfig::instance().ping_gcs_rpc_server_max_retries()) { diff --git a/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc b/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc index 47f247309..21edd04ec 100644 --- a/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc +++ b/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc @@ -623,7 +623,7 @@ TEST_F(ServiceBasedGcsClientTest, TestNodeInfo) { // Register local node to GCS. ASSERT_TRUE(RegisterSelf(*gcs_node1_info)); - sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); EXPECT_EQ(gcs_client_->Nodes().GetSelfId(), node1_id); EXPECT_EQ(gcs_client_->Nodes().GetSelfInfo().node_id(), gcs_node1_info->node_id()); EXPECT_EQ(gcs_client_->Nodes().GetSelfInfo().state(), gcs_node1_info->state()); @@ -735,7 +735,7 @@ TEST_F(ServiceBasedGcsClientTest, TestTaskInfo) { ASSERT_TRUE(AddTask(task_table_data)); // Assert unsubscribe succeeded. - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); EXPECT_EQ(task_count, 1); // Delete tasks from GCS. @@ -764,7 +764,7 @@ TEST_F(ServiceBasedGcsClientTest, TestTaskInfo) { ASSERT_TRUE(AddTaskLease(task_lease)); // Assert unsubscribe succeeded. - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); EXPECT_EQ(task_lease_count, 2); // Attempt task reconstruction to GCS. @@ -815,7 +815,7 @@ TEST_F(ServiceBasedGcsClientTest, TestObjectInfo) { ASSERT_TRUE(AddLocation(object_id, node_id)); // Assert unsubscribe succeeded. - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); ASSERT_EQ(object_add_count, 1); } @@ -972,7 +972,7 @@ TEST_F(ServiceBasedGcsClientTest, TestObjectTableResubscribe) { // Cancel subscription to any update of an object's location. UnsubscribeToLocations(object1_id); - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Restart GCS. RestartGcsServer(); diff --git a/src/ray/gcs/pubsub/test/gcs_pub_sub_test.cc b/src/ray/gcs/pubsub/test/gcs_pub_sub_test.cc index 23c0d3aee..727b82814 100644 --- a/src/ray/gcs/pubsub/test/gcs_pub_sub_test.cc +++ b/src/ray/gcs/pubsub/test/gcs_pub_sub_test.cc @@ -126,7 +126,7 @@ TEST_F(GcsPubSubTest, TestPubSubApi) { WaitPendingDone(all_result, 1); Unsubscribe(channel, id); Publish(channel, id, data); - usleep(100 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); EXPECT_EQ(result.size(), 1); Subscribe(channel, id, result); diff --git a/src/ray/gcs/redis_client.cc b/src/ray/gcs/redis_client.cc index 1ce07bd56..21a87a799 100644 --- a/src/ray/gcs/redis_client.cc +++ b/src/ray/gcs/redis_client.cc @@ -41,7 +41,8 @@ static void GetRedisShards(redisContext *context, std::vector *addr // Sleep for a little, and try again if the entry isn't there yet. freeReplyObject(reply); - usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().redis_db_connect_wait_milliseconds())); num_attempts++; } RAY_CHECK(num_attempts < RayConfig::instance().redis_db_connect_retries()) @@ -67,7 +68,8 @@ static void GetRedisShards(redisContext *context, std::vector *addr // Sleep for a little, and try again if not all Redis shard addresses have // been added yet. freeReplyObject(reply); - usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().redis_db_connect_wait_milliseconds())); num_attempts++; } RAY_CHECK(num_attempts < RayConfig::instance().redis_db_connect_retries()) diff --git a/src/ray/gcs/redis_context.cc b/src/ray/gcs/redis_context.cc index 7252d256d..6ad799a26 100644 --- a/src/ray/gcs/redis_context.cc +++ b/src/ray/gcs/redis_context.cc @@ -306,7 +306,8 @@ Status ConnectWithRetries(const std::string &address, int port, } RAY_LOG(WARNING) << "Failed to connect to Redis, retrying."; // Sleep for a little. - usleep(RayConfig::instance().redis_db_connect_wait_milliseconds() * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().redis_db_connect_wait_milliseconds())); *context = connect_function(address.c_str(), port); connection_attempts += 1; } diff --git a/src/ray/object_manager/plasma/client.cc b/src/ray/object_manager/plasma/client.cc index 8a2da049e..440f71072 100644 --- a/src/ray/object_manager/plasma/client.cc +++ b/src/ray/object_manager/plasma/client.cc @@ -20,19 +20,25 @@ #include "ray/object_manager/plasma/client.h" #include +#ifndef _WIN32 #include +#endif #include #include +#ifndef _WIN32 #include -#include +#endif #ifdef _WIN32 #include #else +#include #include #endif #include #include +#ifndef _WIN32 #include +#endif #include #ifndef _WIN32 #include diff --git a/src/ray/object_manager/plasma/fling.h b/src/ray/object_manager/plasma/fling.h index e3cb20e9b..2acfe370b 100644 --- a/src/ray/object_manager/plasma/fling.h +++ b/src/ray/object_manager/plasma/fling.h @@ -28,7 +28,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include // This is necessary for Mac OS X, see http://www.apuebook.com/faqs2e.html diff --git a/src/ray/object_manager/plasma/io.cc b/src/ray/object_manager/plasma/io.cc index 3d160e022..5ec22d7ae 100644 --- a/src/ray/object_manager/plasma/io.cc +++ b/src/ray/object_manager/plasma/io.cc @@ -116,7 +116,9 @@ Status ReadMessage(int fd, MessageType* type, std::vector* buffer) { int ConnectOrListenIpcSock(const std::string& pathname, bool shall_listen) { union { struct sockaddr addr; +#ifndef _WIN32 struct sockaddr_un un; +#endif struct sockaddr_in in; } socket_address; int addrlen; @@ -142,6 +144,10 @@ int ConnectOrListenIpcSock(const std::string& pathname, bool shall_listen) { return -1; } } else { +#ifdef _WIN32 + RAY_LOG(ERROR) << "UNIX domain sockets not supported on Windows: " << pathname; + return -1; +#else addrlen = sizeof(socket_address.un); socket_address.un.sun_family = AF_UNIX; if (pathname.size() + 1 > sizeof(socket_address.un.sun_path)) { @@ -149,6 +155,7 @@ int ConnectOrListenIpcSock(const std::string& pathname, bool shall_listen) { return -1; } strncpy(socket_address.un.sun_path, pathname.c_str(), pathname.size() + 1); +#endif } int socket_fd = socket(socket_address.addr.sa_family, SOCK_STREAM, 0); @@ -207,7 +214,7 @@ Status ConnectIpcSocketRetry(const std::string& pathname, int num_retries, RAY_LOG(ERROR) << "Connection to IPC socket failed for pathname " << pathname << ", retrying " << num_retries << " more times"; // Sleep for timeout milliseconds. - usleep(static_cast(timeout * 1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); *fd = ConnectOrListenIpcSock(pathname, false); --num_retries; } diff --git a/src/ray/object_manager/plasma/io.h b/src/ray/object_manager/plasma/io.h index 906d30bb2..45b54cc76 100644 --- a/src/ray/object_manager/plasma/io.h +++ b/src/ray/object_manager/plasma/io.h @@ -18,8 +18,10 @@ #pragma once #include +#ifndef _WIN32 #include #include +#endif #include #include diff --git a/src/ray/object_manager/plasma/plasma.cc b/src/ray/object_manager/plasma/plasma.cc index 5a20cecab..5a5ad49d3 100644 --- a/src/ray/object_manager/plasma/plasma.cc +++ b/src/ray/object_manager/plasma/plasma.cc @@ -17,7 +17,9 @@ #include "ray/object_manager/plasma/plasma.h" +#ifndef _WIN32 #include +#endif #include #include diff --git a/src/ray/object_manager/plasma/store_runner.cc b/src/ray/object_manager/plasma/store_runner.cc index fa10b57c6..41941279c 100644 --- a/src/ray/object_manager/plasma/store_runner.cc +++ b/src/ray/object_manager/plasma/store_runner.cc @@ -2,7 +2,9 @@ #include #include +#ifndef _WIN32 #include +#endif #include #include diff --git a/src/ray/rpc/grpc_server.cc b/src/ray/rpc/grpc_server.cc index 4cbdafb58..4fc4a191b 100644 --- a/src/ray/rpc/grpc_server.cc +++ b/src/ray/rpc/grpc_server.cc @@ -62,7 +62,8 @@ void GrpcServer::Run() { if (port_ > 0) { break; } - usleep(RayConfig::instance().grpc_server_retry_timeout_milliseconds() * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds( + RayConfig::instance().grpc_server_retry_timeout_milliseconds())); num_retries--; } diff --git a/src/ray/thirdparty/ae/ae_select.c b/src/ray/thirdparty/ae/ae_select.c index c039a8ea3..0afd78168 100644 --- a/src/ray/thirdparty/ae/ae_select.c +++ b/src/ray/thirdparty/ae/ae_select.c @@ -29,7 +29,11 @@ */ +#ifdef _WIN32 +#include +#else #include +#endif #include typedef struct aeApiState { diff --git a/src/ray/util/logging.cc b/src/ray/util/logging.cc index f82a7e206..d9db5d34d 100644 --- a/src/ray/util/logging.cc +++ b/src/ray/util/logging.cc @@ -14,13 +14,17 @@ #include "ray/util/logging.h" -#ifndef _WIN32 +#ifdef _WIN32 +#include +#else #include #endif #include #include +#ifndef _WIN32 #include +#endif #include #include @@ -188,9 +192,14 @@ void RayLog::StartRayLog(const std::string &app_name, RayLogLevel severity_thres char buffer[80]; time_t rawtime; time(&rawtime); +#ifdef _WIN32 + int pid = _getpid(); +#else + pid_t pid = getpid(); +#endif strftime(buffer, sizeof(buffer), "%Y%m%d-%H%M%S", localtime(&rawtime)); std::string path = dir_ends_with_slash + app_name_without_path + "." + buffer + "." + - std::to_string(getpid()) + ".log"; + std::to_string(pid) + ".log"; stream_logger_singleton.out_.open(path.c_str(), std::ios_base::app | std::ios_base::binary); } diff --git a/src/ray/util/process.cc b/src/ray/util/process.cc index 68149bc51..d4ad72bfd 100644 --- a/src/ray/util/process.cc +++ b/src/ray/util/process.cc @@ -22,8 +22,8 @@ #include #include #include -#endif #include +#endif #include #include @@ -445,6 +445,7 @@ namespace std { bool equal_to::operator()(const ray::Process &x, const ray::Process &y) const { + using namespace ray; return !x.IsNull() ? !y.IsNull() ? x.IsValid() @@ -456,6 +457,7 @@ bool equal_to::operator()(const ray::Process &x, } size_t hash::operator()(const ray::Process &value) const { + using namespace ray; return !value.IsNull() ? value.IsValid() ? hash()(value.GetId()) : hash()(value.Get()) : size_t(); diff --git a/src/ray/util/sequencer_test.cc b/src/ray/util/sequencer_test.cc index b11f6a768..a1d4127be 100644 --- a/src/ray/util/sequencer_test.cc +++ b/src/ray/util/sequencer_test.cc @@ -13,7 +13,10 @@ // limitations under the License. #include "ray/util/sequencer.h" -#include + +#include +#include + #include "gtest/gtest.h" #include "ray/util/logging.h" @@ -26,7 +29,7 @@ TEST(SequencerTest, ExecuteOrderedTest) { int size = 100; for (int index = 0; index < size; ++index) { auto operation = [index, &queue](SequencerDoneCallback done_callback) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); queue.push_back(index); done_callback(); }; @@ -34,7 +37,7 @@ TEST(SequencerTest, ExecuteOrderedTest) { } while (queue.size() < (size_t)size) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } for (int index = 0; index < size; ++index) { diff --git a/src/ray/util/signal_test.cc b/src/ray/util/signal_test.cc index 278986826..f57432f26 100644 --- a/src/ray/util/signal_test.cc +++ b/src/ray/util/signal_test.cc @@ -24,7 +24,7 @@ namespace ray { #ifndef _WIN32 -void Sleep() { usleep(100000); } +void Sleep() { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } void TestSendSignal(const std::string &test_name, int signal) { pid_t pid; diff --git a/src/shims/windows/arpa/inet.h b/src/shims/windows/arpa/inet.h deleted file mode 100644 index ee3f2f94f..000000000 --- a/src/shims/windows/arpa/inet.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef INET_H -#define INET_H - -#endif /* INET_H */ diff --git a/src/shims/windows/getopt.cc b/src/shims/windows/getopt.cc deleted file mode 100644 index 92816c2ef..000000000 --- a/src/shims/windows/getopt.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* -From: - http://stackoverflow.com/a/17195644/541686 -Also posted on: - https://gist.github.com/superwills/5815344 -Previously from: - http://www.raspberryginger.com/jbailey/minix/html/lib_2posix_2getopt_8c-source.html -*/ - -/* - * Copyright (c) 1987, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -static char EMSG[] = ""; - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int getopt(int nargc, char *const nargv[], const char *ostr) { - static char *place = EMSG; /* option letter processing */ - const char *oli; /* option letter list index */ - - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; - if (optind >= nargc || *(place = nargv[optind]) != '-') { - place = EMSG; - return (-1); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++optind; - place = EMSG; - return (-1); - } - } /* option letter okay? */ - if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means -1. - */ - if (optopt == (int)'-') return (-1); - if (!*place) ++optind; - if (opterr && *ostr != ':') (void)printf("illegal option -- %c\n", optopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - optarg = NULL; - if (!*place) ++optind; - } else { /* need an argument */ - if (*place) /* no white space */ - optarg = place; - else if (nargc <= ++optind) { /* no arg */ - place = EMSG; - if (*ostr == ':') return (BADARG); - if (opterr) (void)printf("option requires an argument -- %c\n", optopt); - return (BADCH); - } else /* white space */ - optarg = nargv[optind]; - place = EMSG; - ++optind; - } - return (optopt); /* dump back option letter */ -} diff --git a/src/shims/windows/getopt.h b/src/shims/windows/getopt.h deleted file mode 100644 index 48060ed33..000000000 --- a/src/shims/windows/getopt.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef GETOPT_H -#define GETOPT_H - -extern char *optarg; -extern int optind, opterr, optopt; -int getopt(int nargc, char *const nargv[], const char *ostr); - -#endif /* GETOPT_H */ diff --git a/src/shims/windows/netdb.h b/src/shims/windows/netdb.h deleted file mode 100644 index 7afa2197f..000000000 --- a/src/shims/windows/netdb.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef NETDB_H -#define NETDB_H - -#include - -#endif /* NETDB_H */ diff --git a/src/shims/windows/netinet/in.h b/src/shims/windows/netinet/in.h deleted file mode 100644 index a60db3e05..000000000 --- a/src/shims/windows/netinet/in.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef IN_H -#define IN_H - -#endif /* IN_H */ diff --git a/src/shims/windows/netinet/tcp.h b/src/shims/windows/netinet/tcp.h deleted file mode 100644 index 4c6d384e2..000000000 --- a/src/shims/windows/netinet/tcp.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef TCP_H -#define TCP_H - -#endif /* TCP_H */ diff --git a/src/shims/windows/pthread.h b/src/shims/windows/pthread.h deleted file mode 100644 index 88a4eef16..000000000 --- a/src/shims/windows/pthread.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _PTHREAD_H -#define _PTHREAD_H 1 - -#ifndef _INC_WINDOWS -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN 1 -#endif -#include -#endif - -typedef CRITICAL_SECTION pthread_mutex_t; - -#endif /* pthread.h */ diff --git a/src/shims/windows/strings.h b/src/shims/windows/strings.h deleted file mode 100644 index 3cdc86bb6..000000000 --- a/src/shims/windows/strings.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef STRINGS_H -#define STRINGS_H - -#include - -static int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1, s2); } - -static int strncasecmp(const char *s1, const char *s2, size_t n) { - return _strnicmp(s1, s2, n); -} - -#endif /* STRINGS_H */ diff --git a/src/shims/windows/sys/ioctl.h b/src/shims/windows/sys/ioctl.h deleted file mode 100644 index 00f7a55ed..000000000 --- a/src/shims/windows/sys/ioctl.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef IOCTL_H -#define IOCTL_H - -#endif /* IOCTL_H */ diff --git a/src/shims/windows/sys/select.h b/src/shims/windows/sys/select.h deleted file mode 100644 index 8aef7950e..000000000 --- a/src/shims/windows/sys/select.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef SELECT_H -#define SELECT_H - -#endif /* SELECT_H */ diff --git a/src/shims/windows/sys/statvfs.h b/src/shims/windows/sys/statvfs.h deleted file mode 100644 index c86674d71..000000000 --- a/src/shims/windows/sys/statvfs.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef STATVFS_H -#define STATVFS_H 1 - -#endif diff --git a/src/shims/windows/sys/syslog.h b/src/shims/windows/sys/syslog.h deleted file mode 100644 index 37141327a..000000000 --- a/src/shims/windows/sys/syslog.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _SYS_SYSLOG_H -#define _SYS_SYSLOG_H 1 - -#endif /* sys/syslog.h */ diff --git a/src/shims/windows/sys/un.h b/src/shims/windows/sys/un.h deleted file mode 100644 index 531f5e4fe..000000000 --- a/src/shims/windows/sys/un.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef UN_H -#define UN_H - -#include - -#define UNIX_PATH_MAX 108 - -typedef struct sockaddr_un { - ADDRESS_FAMILY sun_family; - char sun_path[UNIX_PATH_MAX]; -} SOCKADDR_UN, *PSOCKADDR_UN; - -#ifndef AF_LOCAL -#define AF_LOCAL AF_UNIX -#endif - -#endif /* UN_H */ diff --git a/src/shims/windows/syslog.h b/src/shims/windows/syslog.h deleted file mode 100644 index 830b4928a..000000000 --- a/src/shims/windows/syslog.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/src/shims/windows/unistd.cc b/src/shims/windows/unistd.cc index 2bcdcdde5..b61ebf2c7 100644 --- a/src/shims/windows/unistd.cc +++ b/src/shims/windows/unistd.cc @@ -22,7 +22,8 @@ typedef NTSTATUS WINAPI NtQueryInformationProcess_t(HANDLE ProcessHandle, static std::atomic NtQueryInformationProcess_ = ATOMIC_VAR_INIT(NULL); -pid_t getppid() { +typedef int pid_t; +int getppid() { NtQueryInformationProcess_t *NtQueryInformationProcess = ::NtQueryInformationProcess_; if (!NtQueryInformationProcess) { NtQueryInformationProcess = reinterpret_cast( @@ -61,13 +62,3 @@ pid_t getppid() { } return result; } - -int usleep(useconds_t usec) { - Sleep((usec + (1000 - 1)) / 1000); - return 0; -} - -unsigned sleep(unsigned seconds) { - Sleep(seconds * 1000); - return 0; -} diff --git a/src/shims/windows/unistd.h b/src/shims/windows/unistd.h index cbc30c3d2..3cf5e4f4f 100644 --- a/src/shims/windows/unistd.h +++ b/src/shims/windows/unistd.h @@ -1,57 +1,12 @@ #ifndef UNISTD_H #define UNISTD_H -#include -#include // open/read/write/close -#include // getpid - -#ifndef EXTERN_C -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C -#endif -#endif -#ifndef DECLSPEC_IMPORT -#define DECLSPEC_IMPORT __declspec(dllimport) -#endif -#ifndef WINBASEAPI -#define WINBASEAPI DECLSPEC_IMPORT -#endif -#ifndef WINAPI -#define WINAPI __stdcall -#endif -typedef int BOOL; -typedef void *HANDLE; -typedef unsigned long DWORD; #ifdef _WIN64 -typedef unsigned long long UINT_PTR; -typedef unsigned long long ULONG_PTR; typedef long long ssize_t; #else -typedef unsigned int UINT_PTR; -typedef unsigned long ULONG_PTR; typedef int ssize_t; #endif -typedef int pid_t /* technically unsigned on Windows, but no practical concern */; -enum { SIGKILL = 9 }; -typedef ULONG_PTR SIZE_T; -EXTERN_C WINBASEAPI void WINAPI Sleep(DWORD dwMilliseconds); -typedef unsigned int useconds_t; -int usleep(useconds_t usec); -unsigned sleep(unsigned seconds); - -pid_t getppid(); - -__declspec( - deprecated("Killing a process by ID has an inherent race condition on Windows" - " and is HIGHLY discouraged. " - "Furthermore, signals other than SIGKILL are NOT portable. " - "Please use a wrapper that keeps the process handle alive" - " and terminates it directly as needed. " - "For SIGTERM or other signals, a different IPC mechanism may be" - " more appropriate (such as window messages on Windows)." - "")) int kill(pid_t pid, int sig); +int getppid(); #endif /* UNISTD_H */ diff --git a/streaming/src/util/streaming_logging.cc b/streaming/src/util/streaming_logging.cc index a27c05654..3b0a730c6 100644 --- a/streaming/src/util/streaming_logging.cc +++ b/streaming/src/util/streaming_logging.cc @@ -1,7 +1,3 @@ -#include -#include -#include - #include "streaming_logging.h" namespace ray {