From 72a44178e92cc103507e2bdc1a52e709de83b767 Mon Sep 17 00:00:00 2001 From: vjpai <vpai@google.com> Date: Thu, 16 Jul 2015 21:44:44 -0700 Subject: [PATCH] ThreadPoolInterface::ScheduleCallback --> ThreadPoolInterface::Add --- include/grpc++/fixed_size_thread_pool.h | 2 +- include/grpc++/thread_pool_interface.h | 2 +- src/cpp/server/fixed_size_thread_pool.cc | 3 +-- src/cpp/server/server.cc | 2 +- test/cpp/server/fixed_size_thread_pool_test.cc | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/grpc++/fixed_size_thread_pool.h b/include/grpc++/fixed_size_thread_pool.h index 9f0cbfbae9..bf67cce7b1 100644 --- a/include/grpc++/fixed_size_thread_pool.h +++ b/include/grpc++/fixed_size_thread_pool.h @@ -50,7 +50,7 @@ class FixedSizeThreadPool GRPC_FINAL : public ThreadPoolInterface { explicit FixedSizeThreadPool(int num_threads); ~FixedSizeThreadPool(); - void ScheduleCallback(const std::function<void()>& callback) GRPC_OVERRIDE; + void Add(const std::function<void()>& callback) GRPC_OVERRIDE; private: grpc::mutex mu_; diff --git a/include/grpc++/thread_pool_interface.h b/include/grpc++/thread_pool_interface.h index ac4458d530..d080b31dcc 100644 --- a/include/grpc++/thread_pool_interface.h +++ b/include/grpc++/thread_pool_interface.h @@ -44,7 +44,7 @@ class ThreadPoolInterface { virtual ~ThreadPoolInterface() {} // Schedule the given callback for execution. - virtual void ScheduleCallback(const std::function<void()>& callback) = 0; + virtual void Add(const std::function<void()>& callback) = 0; }; ThreadPoolInterface* CreateDefaultThreadPool(); diff --git a/src/cpp/server/fixed_size_thread_pool.cc b/src/cpp/server/fixed_size_thread_pool.cc index 710bcbb573..bafbc5802a 100644 --- a/src/cpp/server/fixed_size_thread_pool.cc +++ b/src/cpp/server/fixed_size_thread_pool.cc @@ -76,8 +76,7 @@ FixedSizeThreadPool::~FixedSizeThreadPool() { } } -void FixedSizeThreadPool::ScheduleCallback( - const std::function<void()>& callback) { +void FixedSizeThreadPool::Add(const std::function<void()>& callback) { grpc::lock_guard<grpc::mutex> lock(mu_); callbacks_.push(callback); cv_.notify_one(); diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index e6761d6244..ab87b22f5f 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -383,7 +383,7 @@ void Server::ScheduleCallback() { grpc::unique_lock<grpc::mutex> lock(mu_); num_running_cb_++; } - thread_pool_->ScheduleCallback(std::bind(&Server::RunRpc, this)); + thread_pool_->Add(std::bind(&Server::RunRpc, this)); } void Server::RunRpc() { diff --git a/test/cpp/server/fixed_size_thread_pool_test.cc b/test/cpp/server/fixed_size_thread_pool_test.cc index d62f4e8132..442e974fc1 100644 --- a/test/cpp/server/fixed_size_thread_pool_test.cc +++ b/test/cpp/server/fixed_size_thread_pool_test.cc @@ -54,12 +54,12 @@ void Callback(std::mutex* mu, std::condition_variable* cv, bool* done) { cv->notify_all(); } -TEST_F(FixedSizeThreadPoolTest, ScheduleCallback) { +TEST_F(FixedSizeThreadPoolTest, Add) { std::mutex mu; std::condition_variable cv; bool done = false; std::function<void()> callback = std::bind(Callback, &mu, &cv, &done); - thread_pool_.ScheduleCallback(callback); + thread_pool_.Add(callback); // Wait for the callback to finish. std::unique_lock<std::mutex> lock(mu); -- GitLab