File tree Expand file tree Collapse file tree 2 files changed +1
-8
lines changed Expand file tree Collapse file tree 2 files changed +1
-8
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,7 @@ void ThreadPool::Init() {
52
52
}
53
53
}
54
54
55
- ThreadPool::ThreadPool (int num_threads)
56
- : total_threads_(num_threads), idle_threads_(num_threads), running_(true ) {
55
+ ThreadPool::ThreadPool (int num_threads) : running_(true ) {
57
56
threads_.resize (num_threads);
58
57
for (auto & thread : threads_) {
59
58
// TODO(Yancey1989): binding the thread on the specify CPU number
@@ -82,16 +81,13 @@ void ThreadPool::TaskLoop() {
82
81
scheduled_.wait (
83
82
lock, [this ] { return !this ->tasks_ .empty () || !this ->running_ ; });
84
83
85
- std::lock_guard<std::mutex> l (mutex_);
86
84
if (!running_ || tasks_.empty ()) {
87
85
return ;
88
86
}
89
87
90
88
// pop a task from the task queue
91
89
auto task = std::move (tasks_.front ());
92
90
tasks_.pop ();
93
-
94
- --idle_threads_;
95
91
lock.unlock ();
96
92
97
93
// run the task
Original file line number Diff line number Diff line change @@ -107,14 +107,11 @@ class ThreadPool {
107
107
static std::once_flag init_flag_;
108
108
109
109
std::vector<std::unique_ptr<std::thread>> threads_;
110
- const size_t total_threads_;
111
- size_t idle_threads_;
112
110
113
111
std::queue<Task> tasks_;
114
112
std::mutex mutex_;
115
113
bool running_;
116
114
std::condition_variable scheduled_;
117
- std::condition_variable completed_;
118
115
};
119
116
120
117
class ThreadPoolIO : ThreadPool {
You can’t perform that action at this time.
0 commit comments