From 69fe0759bee3579d743d2e71f36504366ee0d275 Mon Sep 17 00:00:00 2001
From: Yang Gao <yangg@google.com>
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 5636373b81..dda939bf71 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 mutex>
 class unique_lock : public lock_guard<mutex> {
  public:
-  unique_lock(mutex &mu) : lock_guard(mu) { }
-  void lock() { lock_internal(); }
-  void unlock() { unlock_internal(); }
+  unique_lock(mutex &mu) : lock_guard<mutex>(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 a01b931df8..a6bdd7dfe9 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 e8d0e89ed2..118cabcb61 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 0f24d6e9b3..26f25611b5 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<std::function<void()>> callbacks_;
-  std::vector<grpc::thread> threads_;
+  std::vector<grpc::thread*> threads_;
 
   void ThreadFunc();
 };
diff --git a/test/core/support/tls_test.c b/test/core/support/tls_test.c
index 8632fd4490..0a3c28417f 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 7a15591b44..f48cf953a4 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -31,6 +31,7 @@
  *
  */
 
+#include <mutex>
 #include <thread>
 
 #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 310227a29c..5ee29e40f4 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -31,6 +31,7 @@
  *
  */
 
+#include <mutex>
 #include <thread>
 
 #include "test/core/util/port.h"
-- 
GitLab