提交 4f59690b 编写于 作者: X Xin Pan

clean unused codes

test=develop
上级 784a19ec
...@@ -52,8 +52,7 @@ void ThreadPool::Init() { ...@@ -52,8 +52,7 @@ void ThreadPool::Init() {
} }
} }
ThreadPool::ThreadPool(int num_threads) ThreadPool::ThreadPool(int num_threads) : running_(true) {
: total_threads_(num_threads), idle_threads_(num_threads), running_(true) {
threads_.resize(num_threads); threads_.resize(num_threads);
for (auto& thread : threads_) { for (auto& thread : threads_) {
// TODO(Yancey1989): binding the thread on the specify CPU number // TODO(Yancey1989): binding the thread on the specify CPU number
...@@ -82,7 +81,6 @@ void ThreadPool::TaskLoop() { ...@@ -82,7 +81,6 @@ void ThreadPool::TaskLoop() {
scheduled_.wait( scheduled_.wait(
lock, [this] { return !this->tasks_.empty() || !this->running_; }); lock, [this] { return !this->tasks_.empty() || !this->running_; });
std::lock_guard<std::mutex> l(mutex_);
if (!running_ || tasks_.empty()) { if (!running_ || tasks_.empty()) {
return; return;
} }
...@@ -90,8 +88,6 @@ void ThreadPool::TaskLoop() { ...@@ -90,8 +88,6 @@ void ThreadPool::TaskLoop() {
// pop a task from the task queue // pop a task from the task queue
auto task = std::move(tasks_.front()); auto task = std::move(tasks_.front());
tasks_.pop(); tasks_.pop();
--idle_threads_;
lock.unlock(); lock.unlock();
// run the task // run the task
......
...@@ -107,14 +107,11 @@ class ThreadPool { ...@@ -107,14 +107,11 @@ class ThreadPool {
static std::once_flag init_flag_; static std::once_flag init_flag_;
std::vector<std::unique_ptr<std::thread>> threads_; std::vector<std::unique_ptr<std::thread>> threads_;
const size_t total_threads_;
size_t idle_threads_;
std::queue<Task> tasks_; std::queue<Task> tasks_;
std::mutex mutex_; std::mutex mutex_;
bool running_; bool running_;
std::condition_variable scheduled_; std::condition_variable scheduled_;
std::condition_variable completed_;
}; };
class ThreadPoolIO : ThreadPool { class ThreadPoolIO : ThreadPool {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册