Make thread_pool.h a public header

Rename ThreadPool -> FixedSizeThreadPool to allow for later introduction
of DynamicSizeThreadPool
pull/2460/head
Vijay Pai 10 years ago
parent e6d12d335c
commit 69f2410086
  1. 4
      BUILD
  2. 2
      Makefile
  3. 4
      build.json
  4. 8
      include/grpc++/thread_pool.h
  5. 2
      include/grpc++/thread_pool_interface.h
  6. 4
      src/cpp/server/create_default_thread_pool.cc
  7. 2
      src/cpp/server/server_builder.cc
  8. 15
      src/cpp/server/thread_pool.cc
  9. 2
      test/cpp/end2end/client_crash_test.cc
  10. 4
      test/cpp/end2end/end2end_test.cc
  11. 4
      test/cpp/end2end/mock_test.cc
  12. 2
      test/cpp/end2end/server_crash_test.cc
  13. 4
      test/cpp/end2end/thread_stress_test.cc
  14. 2
      test/cpp/qps/server_async.cc
  15. 4
      test/cpp/qps/server_sync.cc
  16. 4
      test/cpp/server/thread_pool_test.cc
  17. 4
      test/cpp/util/cli_call_test.cc
  18. 1
      tools/doxygen/Doxyfile.c++
  19. 2
      tools/doxygen/Doxyfile.c++.internal
  20. 12
      tools/run_tests/sources_and_headers.json
  21. 2
      vsprojects/grpc++/grpc++.vcxproj
  22. 6
      vsprojects/grpc++/grpc++.vcxproj.filters
  23. 2
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
  24. 6
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters

@ -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",
],

@ -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 \

@ -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",

@ -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<void()>& 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

@ -47,6 +47,8 @@ class ThreadPoolInterface {
virtual void ScheduleCallback(const std::function<void()>& callback) = 0;
};
ThreadPoolInterface* CreateDefaultThreadPool();
} // namespace grpc
#endif // GRPCXX_THREAD_POOL_INTERFACE_H

@ -32,7 +32,7 @@
*/
#include <grpc/support/cpu.h>
#include "src/cpp/server/thread_pool.h"
#include <grpc++/thread_pool.h>
#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

@ -37,7 +37,7 @@
#include <grpc/support/log.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/server.h>
#include "src/cpp/server/thread_pool.h"
#include <grpc++/thread_pool.h>
namespace grpc {

@ -33,12 +33,11 @@
#include <grpc++/impl/sync.h>
#include <grpc++/impl/thd.h>
#include "src/cpp/server/thread_pool.h"
#include <grpc++/thread_pool.h>
namespace grpc {
void ThreadPool::ThreadFunc() {
void FixedSizeThreadPool::ThreadFunc() {
for (;;) {
// Wait until work is available or we are shutting down.
grpc::unique_lock<grpc::mutex> 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<grpc::mutex> lock(mu_);
shutdown_ = true;
@ -76,7 +76,8 @@ ThreadPool::~ThreadPool() {
}
}
void ThreadPool::ScheduleCallback(const std::function<void()>& callback) {
void FixedSizeThreadPool::ScheduleCallback(
const std::function<void()>& callback) {
grpc::lock_guard<grpc::mutex> lock(mu_);
callbacks_.push(callback);
cv_.notify_one();

@ -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 <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@ -49,6 +48,7 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <grpc++/time.h>
#include <gtest/gtest.h>

@ -35,7 +35,6 @@
#include <thread>
#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 <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <grpc++/time.h>
#include <gtest/gtest.h>
@ -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,

@ -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 <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@ -49,6 +48,7 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <grpc++/time.h>
#include <gtest/gtest.h>
@ -258,7 +258,7 @@ class MockTest : public ::testing::Test {
std::unique_ptr<Server> server_;
std::ostringstream server_address_;
TestServiceImpl service_;
ThreadPool thread_pool_;
FixedSizeThreadPool thread_pool_;
};
// Do one real rpc and one mocked one

@ -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 <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@ -49,6 +48,7 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <grpc++/time.h>
#include <gtest/gtest.h>

@ -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 <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@ -50,6 +49,7 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <grpc++/time.h>
#include <gtest/gtest.h>
@ -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,

@ -51,8 +51,8 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <grpc++/thread_pool.h>
#include <gtest/gtest.h>
#include "src/cpp/server/thread_pool.h"
#include "test/cpp/qps/qpstest.grpc.pb.h"
#include "test/cpp/qps/server.h"

@ -46,7 +46,7 @@
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "src/cpp/server/thread_pool.h"
#include <grpc++/thread_pool.h>
#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<grpc::Server> impl_;
};

@ -35,7 +35,7 @@
#include <functional>
#include <mutex>
#include "src/cpp/server/thread_pool.h"
#include <grpc++/thread_pool.h>
#include <gtest/gtest.h>
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) {

@ -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 <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@ -45,6 +44,7 @@
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/thread_pool.h>
#include "test/core/util/port.h"
#include <gtest/gtest.h>
@ -102,7 +102,7 @@ class CliCallTest : public ::testing::Test {
std::unique_ptr<Server> 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.

@ -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

@ -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 \

@ -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",

@ -182,6 +182,7 @@
<ClInclude Include="..\..\include\grpc++\status.h" />
<ClInclude Include="..\..\include\grpc++\status_code_enum.h" />
<ClInclude Include="..\..\include\grpc++\stream.h" />
<ClInclude Include="..\..\include\grpc++\thread_pool.h" />
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h" />
<ClInclude Include="..\..\include\grpc++\time.h" />
</ItemGroup>
@ -191,7 +192,6 @@
<ClInclude Include="..\..\src\cpp\server\secure_server_credentials.h" />
<ClInclude Include="..\..\src\cpp\client\channel.h" />
<ClInclude Include="..\..\src\cpp\common\create_auth_context.h" />
<ClInclude Include="..\..\src\cpp\server\thread_pool.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\cpp\client\secure_channel_arguments.cc">

@ -198,6 +198,9 @@
<ClInclude Include="..\..\include\grpc++\stream.h">
<Filter>include\grpc++</Filter>
</ClInclude>
<ClInclude Include="..\..\include\grpc++\thread_pool.h">
<Filter>include\grpc++</Filter>
</ClInclude>
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h">
<Filter>include\grpc++</Filter>
</ClInclude>
@ -221,9 +224,6 @@
<ClInclude Include="..\..\src\cpp\common\create_auth_context.h">
<Filter>src\cpp\common</Filter>
</ClInclude>
<ClInclude Include="..\..\src\cpp\server\thread_pool.h">
<Filter>src\cpp\server</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>

@ -182,13 +182,13 @@
<ClInclude Include="..\..\include\grpc++\status.h" />
<ClInclude Include="..\..\include\grpc++\status_code_enum.h" />
<ClInclude Include="..\..\include\grpc++\stream.h" />
<ClInclude Include="..\..\include\grpc++\thread_pool.h" />
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h" />
<ClInclude Include="..\..\include\grpc++\time.h" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\cpp\client\channel.h" />
<ClInclude Include="..\..\src\cpp\common\create_auth_context.h" />
<ClInclude Include="..\..\src\cpp\server\thread_pool.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\cpp\common\insecure_create_auth_context.cc">

@ -186,6 +186,9 @@
<ClInclude Include="..\..\include\grpc++\stream.h">
<Filter>include\grpc++</Filter>
</ClInclude>
<ClInclude Include="..\..\include\grpc++\thread_pool.h">
<Filter>include\grpc++</Filter>
</ClInclude>
<ClInclude Include="..\..\include\grpc++\thread_pool_interface.h">
<Filter>include\grpc++</Filter>
</ClInclude>
@ -200,9 +203,6 @@
<ClInclude Include="..\..\src\cpp\common\create_auth_context.h">
<Filter>src\cpp\common</Filter>
</ClInclude>
<ClInclude Include="..\..\src\cpp\server\thread_pool.h">
<Filter>src\cpp\server</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save