aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/ThreadPool
diff options
context:
space:
mode:
authorGravatar Rasmus Munk Larsen <rmlarsen@google.com>2018-08-23 12:10:08 -0700
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2018-08-23 12:10:08 -0700
commit6e0464004a7bcd666d3b5962c3c999ff78f416f1 (patch)
tree8c16bf24dcfdb4c94ee74873e26bdec9b56c9bdd /unsupported/Eigen/CXX11/src/ThreadPool
parente51d9e473aa1f882d3b3106ec2427a44d2a76ceb (diff)
Store std::unique_ptr instead of raw pointers in per_thread_map_.
Diffstat (limited to 'unsupported/Eigen/CXX11/src/ThreadPool')
-rw-r--r--unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h16
1 files changed, 4 insertions, 12 deletions
diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h b/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h
index a800e827f..1ac4de3b5 100644
--- a/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h
+++ b/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h
@@ -58,9 +58,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
}
}
queues_.resize(num_threads_);
- for (int i = 0; i < num_threads_; i++) {
- queues_.push_back(new Queue());
- }
#ifndef EIGEN_THREAD_LOCAL
init_barrier_.reset(new Barrier(num_threads_));
#endif
@@ -93,9 +90,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
// Join threads explicitly to avoid destruction order issues.
threads_.resize(0);
queues_.resize(0);
-#ifndef EIGEN_THREAD_LOCAL
- for (auto it : per_thread_map_) delete it.second;
-#endif
}
void Schedule(std::function<void()> fn) {
@@ -176,21 +170,19 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
#ifndef EIGEN_THREAD_LOCAL
std::unique_ptr<Barrier> init_barrier_;
std::mutex mu; // Protects per_thread_map_.
- std::unordered_map<uint64_t, PerThread*> per_thread_map_;
+ std::unordered_map<uint64_t, std::unique_ptr<PerThread>> per_thread_map_;
#endif
// Main worker thread loop.
void WorkerLoop(int thread_id) {
#ifndef EIGEN_THREAD_LOCAL
- PerThread* pt = new PerThread();
mu.lock();
- per_thread_map_[GlobalThreadIdHash()] = pt;
+ eigen_assert(per_thread_map_.emplace(GlobalThreadIdHash(), new PerThread()).second);
mu.unlock();
init_barrier_->Notify();
init_barrier_->Wait();
-#else
- PerThread* pt = GetPerThread();
#endif
+ PerThread* pt = GetPerThread();
pt->pool = this;
pt->rand = GlobalThreadIdHash();
pt->thread_id = thread_id;
@@ -355,7 +347,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
if (it == per_thread_map_.end()) {
return &dummy;
} else {
- return it->second;
+ return it->second.get();
}
#else
EIGEN_THREAD_LOCAL PerThread per_thread_;