From 69fe0759bee3579d743d2e71f36504366ee0d275 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 1 Jun 2015 14:32:38 -0700 Subject: [PATCH] Various minor fixes --- include/grpc++/impl/sync_no_cxx11.h | 6 +++--- include/grpc++/impl/thd_no_cxx11.h | 4 ++++ src/cpp/server/thread_pool.cc | 5 +++-- src/cpp/server/thread_pool.h | 2 +- test/core/support/tls_test.c | 1 + test/cpp/end2end/end2end_test.cc | 1 + test/cpp/end2end/thread_stress_test.cc | 1 + 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/grpc++/impl/sync_no_cxx11.h b/include/grpc++/impl/sync_no_cxx11.h index 5636373b814..dda939bf715 100644 --- a/include/grpc++/impl/sync_no_cxx11.h +++ b/include/grpc++/impl/sync_no_cxx11.h @@ -76,9 +76,9 @@ class lock_guard { template class unique_lock : public lock_guard { public: - unique_lock(mutex &mu) : lock_guard(mu) { } - void lock() { lock_internal(); } - void unlock() { unlock_internal(); } + unique_lock(mutex &mu) : lock_guard(mu) { } + void lock() { this->lock_internal(); } + void unlock() { this->unlock_internal(); } }; class condition_variable { diff --git a/include/grpc++/impl/thd_no_cxx11.h b/include/grpc++/impl/thd_no_cxx11.h index a01b931df86..a6bdd7dfe9e 100644 --- a/include/grpc++/impl/thd_no_cxx11.h +++ b/include/grpc++/impl/thd_no_cxx11.h @@ -82,6 +82,10 @@ class thread { thread_function_base *func_; gpr_thd_id thd_; bool joined_; + + // Disallow copy and assign. + thread(const thread&); + void operator=(const thread&); }; } // namespace grpc diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc index e8d0e89ed21..118cabcb612 100644 --- a/src/cpp/server/thread_pool.cc +++ b/src/cpp/server/thread_pool.cc @@ -60,7 +60,7 @@ void ThreadPool::ThreadFunc() { ThreadPool::ThreadPool(int num_threads) : shutdown_(false) { for (int i = 0; i < num_threads; i++) { - threads_.push_back(grpc::thread(&ThreadPool::ThreadFunc, this)); + threads_.push_back(new grpc::thread(&ThreadPool::ThreadFunc, this)); } } @@ -71,7 +71,8 @@ ThreadPool::~ThreadPool() { cv_.notify_all(); } for (auto t = threads_.begin(); t != threads_.end(); t++) { - t->join(); + (*t)->join(); + delete *t; } } diff --git a/src/cpp/server/thread_pool.h b/src/cpp/server/thread_pool.h index 0f24d6e9b32..26f25611b5e 100644 --- a/src/cpp/server/thread_pool.h +++ b/src/cpp/server/thread_pool.h @@ -57,7 +57,7 @@ class ThreadPool GRPC_FINAL : public ThreadPoolInterface { grpc::condition_variable cv_; bool shutdown_; std::queue> callbacks_; - std::vector threads_; + std::vector threads_; void ThreadFunc(); }; diff --git a/test/core/support/tls_test.c b/test/core/support/tls_test.c index 8632fd44901..0a3c28417f6 100644 --- a/test/core/support/tls_test.c +++ b/test/core/support/tls_test.c @@ -54,6 +54,7 @@ static void thd_body(void *arg) { gpr_tls_set(&test_var, i); GPR_ASSERT(gpr_tls_get(&test_var) == i); } + gpr_tls_set(&test_var, 0); } /* ------------------------------------------------- */ diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 7a15591b44b..f48cf953a4f 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -31,6 +31,7 @@ * */ +#include #include #include "src/core/security/credentials.h" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 310227a29c8..5ee29e40f43 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -31,6 +31,7 @@ * */ +#include #include #include "test/core/util/port.h"