Remove std::thread, keep everything else unchanged (#13)

pull/14459/head
Vijay Pai 7 years ago committed by GitHub
parent 46ac366038
commit 162ae4f50c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/cpp/server/dynamic_thread_pool.cc
  2. 4
      src/cpp/server/dynamic_thread_pool.h
  3. 15
      src/cpp/thread_manager/thread_manager.cc
  4. 10
      src/cpp/thread_manager/thread_manager.h

@ -19,20 +19,24 @@
#include "src/cpp/server/dynamic_thread_pool.h"
#include <mutex>
#include <thread>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/thd.h"
namespace grpc {
DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool)
: pool_(pool),
thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc,
this)) {}
DynamicThreadPool::DynamicThread::~DynamicThread() {
thd_->join();
thd_.reset();
thd_("dynamic thread pool thread",
[](void* th) {
reinterpret_cast<DynamicThreadPool::DynamicThread*>(th)
->ThreadFunc();
},
this) {
thd_.Start();
}
DynamicThreadPool::DynamicThread::~DynamicThread() { thd_.Join(); }
void DynamicThreadPool::DynamicThread::ThreadFunc() {
pool_->ThreadFunc();

@ -24,10 +24,10 @@
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
#include <grpcpp/support/config.h>
#include "src/core/lib/gprpp/thd.h"
#include "src/cpp/server/thread_pool_interface.h"
namespace grpc {
@ -47,7 +47,7 @@ class DynamicThreadPool final : public ThreadPoolInterface {
private:
DynamicThreadPool* pool_;
std::unique_ptr<std::thread> thd_;
grpc_core::Thread thd_;
void ThreadFunc();
};
std::mutex mu_;

@ -20,18 +20,24 @@
#include <climits>
#include <mutex>
#include <thread>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/thd.h"
namespace grpc {
ThreadManager::WorkerThread::WorkerThread(ThreadManager* thd_mgr)
: thd_mgr_(thd_mgr) {
// Make thread creation exclusive with respect to its join happening in
// ~WorkerThread().
std::lock_guard<std::mutex> lock(wt_mu_);
thd_ = std::thread(&ThreadManager::WorkerThread::Run, this);
thd_ = grpc_core::Thread(
"sync server thread",
[](void* th) {
reinterpret_cast<ThreadManager::WorkerThread*>(th)->Run();
},
this);
thd_.Start();
}
void ThreadManager::WorkerThread::Run() {
@ -41,8 +47,7 @@ void ThreadManager::WorkerThread::Run() {
ThreadManager::WorkerThread::~WorkerThread() {
// Don't join until the thread is fully constructed.
std::lock_guard<std::mutex> lock(wt_mu_);
thd_.join();
thd_.Join();
}
ThreadManager::ThreadManager(int min_pollers, int max_pollers)

@ -23,10 +23,11 @@
#include <list>
#include <memory>
#include <mutex>
#include <thread>
#include <grpcpp/support/config.h>
#include "src/core/lib/gprpp/thd.h"
namespace grpc {
class ThreadManager {
@ -84,8 +85,8 @@ class ThreadManager {
virtual void Wait();
private:
// Helper wrapper class around std::thread. This takes a ThreadManager object
// and starts a new std::thread to calls the Run() function.
// Helper wrapper class around grpc_core::Thread. Takes a ThreadManager object
// and starts a new grpc_core::Thread to calls the Run() function.
//
// The Run() function calls ThreadManager::MainWorkLoop() function and once
// that completes, it marks the WorkerThread completed by calling
@ -101,8 +102,7 @@ class ThreadManager {
void Run();
ThreadManager* const thd_mgr_;
std::mutex wt_mu_;
std::thread thd_;
grpc_core::Thread thd_;
};
// The main funtion in ThreadManager

Loading…
Cancel
Save