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