From 69f241008645503e1241272f279dc7f02e183e87 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Wed, 15 Jul 2015 12:33:37 -0700 Subject: [PATCH] Make thread_pool.h a public header Rename ThreadPool -> FixedSizeThreadPool to allow for later introduction of DynamicSizeThreadPool --- BUILD | 4 ++-- Makefile | 2 ++ build.json | 4 ++-- {src/cpp/server => include/grpc++}/thread_pool.h | 8 +++----- include/grpc++/thread_pool_interface.h | 2 ++ src/cpp/server/create_default_thread_pool.cc | 4 ++-- src/cpp/server/server_builder.cc | 2 +- src/cpp/server/thread_pool.cc | 15 ++++++++------- test/cpp/end2end/client_crash_test.cc | 2 +- test/cpp/end2end/end2end_test.cc | 4 ++-- test/cpp/end2end/mock_test.cc | 4 ++-- test/cpp/end2end/server_crash_test.cc | 2 +- test/cpp/end2end/thread_stress_test.cc | 4 ++-- test/cpp/qps/server_async.cc | 2 +- test/cpp/qps/server_sync.cc | 4 ++-- test/cpp/server/thread_pool_test.cc | 4 ++-- test/cpp/util/cli_call_test.cc | 4 ++-- tools/doxygen/Doxyfile.c++ | 1 + tools/doxygen/Doxyfile.c++.internal | 2 +- tools/run_tests/sources_and_headers.json | 12 ++++++------ vsprojects/grpc++/grpc++.vcxproj | 2 +- vsprojects/grpc++/grpc++.vcxproj.filters | 6 +++--- .../grpc++_unsecure/grpc++_unsecure.vcxproj | 2 +- .../grpc++_unsecure.vcxproj.filters | 6 +++--- 24 files changed, 53 insertions(+), 49 deletions(-) rename {src/cpp/server => include/grpc++}/thread_pool.h (93%) diff --git a/BUILD b/BUILD index d75bd4205fd..276920f4b6d 100644 --- a/BUILD +++ b/BUILD @@ -635,7 +635,6 @@ cc_library( "src/cpp/server/secure_server_credentials.h", "src/cpp/client/channel.h", "src/cpp/common/create_auth_context.h", - "src/cpp/server/thread_pool.h", "src/cpp/client/secure_channel_arguments.cc", "src/cpp/client/secure_credentials.cc", "src/cpp/common/secure_auth_context.cc", @@ -703,6 +702,7 @@ cc_library( "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", ], @@ -723,7 +723,6 @@ cc_library( srcs = [ "src/cpp/client/channel.h", "src/cpp/common/create_auth_context.h", - "src/cpp/server/thread_pool.h", "src/cpp/common/insecure_create_auth_context.cc", "src/cpp/client/channel.cc", "src/cpp/client/channel_arguments.cc", @@ -787,6 +786,7 @@ cc_library( "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", ], diff --git a/Makefile b/Makefile index 57ab6fed152..c216a8f445a 100644 --- a/Makefile +++ b/Makefile @@ -3749,6 +3749,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/status.h \ include/grpc++/status_code_enum.h \ include/grpc++/stream.h \ + include/grpc++/thread_pool.h \ include/grpc++/thread_pool_interface.h \ include/grpc++/time.h \ @@ -3990,6 +3991,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/status.h \ include/grpc++/status_code_enum.h \ include/grpc++/stream.h \ + include/grpc++/thread_pool.h \ include/grpc++/thread_pool_interface.h \ include/grpc++/time.h \ diff --git a/build.json b/build.json index 121637204e1..cb4971eb1f3 100644 --- a/build.json +++ b/build.json @@ -64,13 +64,13 @@ "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h" ], "headers": [ "src/cpp/client/channel.h", - "src/cpp/common/create_auth_context.h", - "src/cpp/server/thread_pool.h" + "src/cpp/common/create_auth_context.h" ], "src": [ "src/cpp/client/channel.cc", diff --git a/src/cpp/server/thread_pool.h b/include/grpc++/thread_pool.h similarity index 93% rename from src/cpp/server/thread_pool.h rename to include/grpc++/thread_pool.h index 3b70249bf9a..9f0cbfbae97 100644 --- a/src/cpp/server/thread_pool.h +++ b/include/grpc++/thread_pool.h @@ -45,10 +45,10 @@ namespace grpc { -class ThreadPool GRPC_FINAL : public ThreadPoolInterface { +class FixedSizeThreadPool GRPC_FINAL : public ThreadPoolInterface { public: - explicit ThreadPool(int num_threads); - ~ThreadPool(); + explicit FixedSizeThreadPool(int num_threads); + ~FixedSizeThreadPool(); void ScheduleCallback(const std::function& callback) GRPC_OVERRIDE; @@ -62,8 +62,6 @@ class ThreadPool GRPC_FINAL : public ThreadPoolInterface { void ThreadFunc(); }; -ThreadPoolInterface* CreateDefaultThreadPool(); - } // namespace grpc #endif // GRPC_INTERNAL_CPP_SERVER_THREAD_POOL_H diff --git a/include/grpc++/thread_pool_interface.h b/include/grpc++/thread_pool_interface.h index ead307f6a2f..ac4458d5303 100644 --- a/include/grpc++/thread_pool_interface.h +++ b/include/grpc++/thread_pool_interface.h @@ -47,6 +47,8 @@ class ThreadPoolInterface { virtual void ScheduleCallback(const std::function& callback) = 0; }; +ThreadPoolInterface* CreateDefaultThreadPool(); + } // namespace grpc #endif // GRPCXX_THREAD_POOL_INTERFACE_H diff --git a/src/cpp/server/create_default_thread_pool.cc b/src/cpp/server/create_default_thread_pool.cc index 89c1d7e9295..6d079dfab0b 100644 --- a/src/cpp/server/create_default_thread_pool.cc +++ b/src/cpp/server/create_default_thread_pool.cc @@ -32,7 +32,7 @@ */ #include -#include "src/cpp/server/thread_pool.h" +#include #ifndef GRPC_CUSTOM_DEFAULT_THREAD_POOL @@ -41,7 +41,7 @@ namespace grpc { ThreadPoolInterface* CreateDefaultThreadPool() { int cores = gpr_cpu_num_cores(); if (!cores) cores = 4; - return new ThreadPool(cores); + return new FixedSizeThreadPool(cores); } } // namespace grpc diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 86c78f05ff9..cf7482c73b6 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -37,7 +37,7 @@ #include #include #include -#include "src/cpp/server/thread_pool.h" +#include namespace grpc { diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc index 118cabcb612..3a28d36cbbc 100644 --- a/src/cpp/server/thread_pool.cc +++ b/src/cpp/server/thread_pool.cc @@ -33,12 +33,11 @@ #include #include - -#include "src/cpp/server/thread_pool.h" +#include namespace grpc { -void ThreadPool::ThreadFunc() { +void FixedSizeThreadPool::ThreadFunc() { for (;;) { // Wait until work is available or we are shutting down. grpc::unique_lock lock(mu_); @@ -58,13 +57,14 @@ void ThreadPool::ThreadFunc() { } } -ThreadPool::ThreadPool(int num_threads) : shutdown_(false) { +FixedSizeThreadPool::FixedSizeThreadPool(int num_threads) : shutdown_(false) { for (int i = 0; i < num_threads; i++) { - threads_.push_back(new grpc::thread(&ThreadPool::ThreadFunc, this)); + threads_.push_back( + new grpc::thread(&FixedSizeThreadPool::ThreadFunc, this)); } } -ThreadPool::~ThreadPool() { +FixedSizeThreadPool::~FixedSizeThreadPool() { { grpc::lock_guard lock(mu_); shutdown_ = true; @@ -76,7 +76,8 @@ ThreadPool::~ThreadPool() { } } -void ThreadPool::ScheduleCallback(const std::function& callback) { +void FixedSizeThreadPool::ScheduleCallback( + const std::function& callback) { grpc::lock_guard lock(mu_); callbacks_.push(callback); cv_.notify_one(); diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index 645226f3754..0b7f1b8e02d 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -37,7 +37,6 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h" -#include "src/cpp/server/thread_pool.h" #include #include #include @@ -49,6 +48,7 @@ #include #include #include +#include #include #include diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 207dad52827..1283dd072ff 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -35,7 +35,6 @@ #include #include "src/core/security/credentials.h" -#include "src/cpp/server/thread_pool.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h" @@ -52,6 +51,7 @@ #include #include #include +#include #include #include @@ -260,7 +260,7 @@ class End2endTest : public ::testing::Test { TestServiceImpl service_; TestServiceImpl special_service_; TestServiceImplDupPkg dup_pkg_service_; - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; }; static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 2809ab8d3cf..0cffaf6dde8 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -37,7 +37,6 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h" -#include "src/cpp/server/thread_pool.h" #include #include #include @@ -49,6 +48,7 @@ #include #include #include +#include #include #include @@ -258,7 +258,7 @@ class MockTest : public ::testing::Test { std::unique_ptr server_; std::ostringstream server_address_; TestServiceImpl service_; - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; }; // Do one real rpc and one mocked one diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index 4d4d590bdd7..d8b31a9d6e2 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -37,7 +37,6 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h" -#include "src/cpp/server/thread_pool.h" #include #include #include @@ -49,6 +48,7 @@ #include #include #include +#include #include #include diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 0b4d9425666..0d6d542bbb9 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -38,7 +38,6 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/echo_duplicate.grpc.pb.h" #include "test/cpp/util/echo.grpc.pb.h" -#include "src/cpp/server/thread_pool.h" #include #include #include @@ -50,6 +49,7 @@ #include #include #include +#include #include #include @@ -206,7 +206,7 @@ class End2endTest : public ::testing::Test { const int kMaxMessageSize_; TestServiceImpl service_; TestServiceImplDupPkg dup_pkg_service_; - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; }; static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index f5251e961b9..4a91304f45e 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -51,8 +51,8 @@ #include #include #include +#include #include -#include "src/cpp/server/thread_pool.h" #include "test/cpp/qps/qpstest.grpc.pb.h" #include "test/cpp/qps/server.h" diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc index bc00de9cedb..1a8516ded66 100644 --- a/test/cpp/qps/server_sync.cc +++ b/test/cpp/qps/server_sync.cc @@ -46,7 +46,7 @@ #include #include #include -#include "src/cpp/server/thread_pool.h" +#include #include "test/cpp/qps/qpstest.grpc.pb.h" #include "test/cpp/qps/server.h" #include "test/cpp/qps/timer.h" @@ -111,7 +111,7 @@ class SynchronousServer GRPC_FINAL : public grpc::testing::Server { } TestServiceImpl service_; - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; std::unique_ptr impl_; }; diff --git a/test/cpp/server/thread_pool_test.cc b/test/cpp/server/thread_pool_test.cc index 824d7853160..d906f76f429 100644 --- a/test/cpp/server/thread_pool_test.cc +++ b/test/cpp/server/thread_pool_test.cc @@ -35,7 +35,7 @@ #include #include -#include "src/cpp/server/thread_pool.h" +#include #include namespace grpc { @@ -45,7 +45,7 @@ class ThreadPoolTest : public ::testing::Test { ThreadPoolTest() : thread_pool_(4) {} protected: - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; }; void Callback(std::mutex* mu, std::condition_variable* cv, bool* done) { diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc index 6cf86ea89bf..fd2662f6dc5 100644 --- a/test/cpp/util/cli_call_test.cc +++ b/test/cpp/util/cli_call_test.cc @@ -34,7 +34,6 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/cli_call.h" #include "test/cpp/util/echo.grpc.pb.h" -#include "src/cpp/server/thread_pool.h" #include #include #include @@ -45,6 +44,7 @@ #include #include #include +#include #include "test/core/util/port.h" #include @@ -102,7 +102,7 @@ class CliCallTest : public ::testing::Test { std::unique_ptr server_; std::ostringstream server_address_; TestServiceImpl service_; - ThreadPool thread_pool_; + FixedSizeThreadPool thread_pool_; }; // Send a rpc with a normal stub and then a CliCall. Verify they match. diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index feb7ad8bb93..e82e3bca4ed 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -796,6 +796,7 @@ include/grpc++/slice.h \ include/grpc++/status.h \ include/grpc++/status_code_enum.h \ include/grpc++/stream.h \ +include/grpc++/thread_pool.h \ include/grpc++/thread_pool_interface.h \ include/grpc++/time.h diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 67718d8976f..bd09fb55a2b 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -796,6 +796,7 @@ include/grpc++/slice.h \ include/grpc++/status.h \ include/grpc++/status_code_enum.h \ include/grpc++/stream.h \ +include/grpc++/thread_pool.h \ include/grpc++/thread_pool_interface.h \ include/grpc++/time.h \ src/cpp/client/secure_credentials.h \ @@ -803,7 +804,6 @@ src/cpp/common/secure_auth_context.h \ src/cpp/server/secure_server_credentials.h \ src/cpp/client/channel.h \ src/cpp/common/create_auth_context.h \ -src/cpp/server/thread_pool.h \ src/cpp/client/secure_channel_arguments.cc \ src/cpp/client/secure_credentials.cc \ src/cpp/common/secure_auth_context.cc \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 0493e06f58e..b5166ea05ab 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -9524,14 +9524,14 @@ "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", "src/cpp/client/channel.h", "src/cpp/client/secure_credentials.h", "src/cpp/common/create_auth_context.h", "src/cpp/common/secure_auth_context.h", - "src/cpp/server/secure_server_credentials.h", - "src/cpp/server/thread_pool.h" + "src/cpp/server/secure_server_credentials.h" ], "language": "c++", "name": "grpc++", @@ -9572,6 +9572,7 @@ "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", "src/cpp/client/channel.cc", @@ -9604,7 +9605,6 @@ "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", "src/cpp/server/thread_pool.cc", - "src/cpp/server/thread_pool.h", "src/cpp/util/byte_buffer.cc", "src/cpp/util/slice.cc", "src/cpp/util/status.cc", @@ -9695,11 +9695,11 @@ "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", "src/cpp/client/channel.h", - "src/cpp/common/create_auth_context.h", - "src/cpp/server/thread_pool.h" + "src/cpp/common/create_auth_context.h" ], "language": "c++", "name": "grpc++_unsecure", @@ -9740,6 +9740,7 @@ "include/grpc++/status.h", "include/grpc++/status_code_enum.h", "include/grpc++/stream.h", + "include/grpc++/thread_pool.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", "src/cpp/client/channel.cc", @@ -9765,7 +9766,6 @@ "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", "src/cpp/server/thread_pool.cc", - "src/cpp/server/thread_pool.h", "src/cpp/util/byte_buffer.cc", "src/cpp/util/slice.cc", "src/cpp/util/status.cc", diff --git a/vsprojects/grpc++/grpc++.vcxproj b/vsprojects/grpc++/grpc++.vcxproj index c1a32656cfc..9739c16969a 100644 --- a/vsprojects/grpc++/grpc++.vcxproj +++ b/vsprojects/grpc++/grpc++.vcxproj @@ -182,6 +182,7 @@ + @@ -191,7 +192,6 @@ - diff --git a/vsprojects/grpc++/grpc++.vcxproj.filters b/vsprojects/grpc++/grpc++.vcxproj.filters index e63c77a53d8..e8a19e4997a 100644 --- a/vsprojects/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/grpc++/grpc++.vcxproj.filters @@ -198,6 +198,9 @@ include\grpc++ + + include\grpc++ + include\grpc++ @@ -221,9 +224,6 @@ src\cpp\common - - src\cpp\server - diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj index 944e7e00013..3aee96ac152 100644 --- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -182,13 +182,13 @@ + - diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index 73b0a5dccdb..d2dbd2ad42a 100644 --- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -186,6 +186,9 @@ include\grpc++ + + include\grpc++ + include\grpc++ @@ -200,9 +203,6 @@ src\cpp\common - - src\cpp\server -