mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-23 06:43:13 +08:00
Store std::unique_ptr instead of raw pointers in per_thread_map_.
This commit is contained in:
parent
e51d9e473a
commit
6e0464004a
@ -58,9 +58,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
queues_.resize(num_threads_);
|
queues_.resize(num_threads_);
|
||||||
for (int i = 0; i < num_threads_; i++) {
|
|
||||||
queues_.push_back(new Queue());
|
|
||||||
}
|
|
||||||
#ifndef EIGEN_THREAD_LOCAL
|
#ifndef EIGEN_THREAD_LOCAL
|
||||||
init_barrier_.reset(new Barrier(num_threads_));
|
init_barrier_.reset(new Barrier(num_threads_));
|
||||||
#endif
|
#endif
|
||||||
@ -93,9 +90,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
// Join threads explicitly to avoid destruction order issues.
|
// Join threads explicitly to avoid destruction order issues.
|
||||||
threads_.resize(0);
|
threads_.resize(0);
|
||||||
queues_.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) {
|
void Schedule(std::function<void()> fn) {
|
||||||
@ -176,21 +170,19 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
#ifndef EIGEN_THREAD_LOCAL
|
#ifndef EIGEN_THREAD_LOCAL
|
||||||
std::unique_ptr<Barrier> init_barrier_;
|
std::unique_ptr<Barrier> init_barrier_;
|
||||||
std::mutex mu; // Protects per_thread_map_.
|
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
|
#endif
|
||||||
|
|
||||||
// Main worker thread loop.
|
// Main worker thread loop.
|
||||||
void WorkerLoop(int thread_id) {
|
void WorkerLoop(int thread_id) {
|
||||||
#ifndef EIGEN_THREAD_LOCAL
|
#ifndef EIGEN_THREAD_LOCAL
|
||||||
PerThread* pt = new PerThread();
|
|
||||||
mu.lock();
|
mu.lock();
|
||||||
per_thread_map_[GlobalThreadIdHash()] = pt;
|
eigen_assert(per_thread_map_.emplace(GlobalThreadIdHash(), new PerThread()).second);
|
||||||
mu.unlock();
|
mu.unlock();
|
||||||
init_barrier_->Notify();
|
init_barrier_->Notify();
|
||||||
init_barrier_->Wait();
|
init_barrier_->Wait();
|
||||||
#else
|
|
||||||
PerThread* pt = GetPerThread();
|
|
||||||
#endif
|
#endif
|
||||||
|
PerThread* pt = GetPerThread();
|
||||||
pt->pool = this;
|
pt->pool = this;
|
||||||
pt->rand = GlobalThreadIdHash();
|
pt->rand = GlobalThreadIdHash();
|
||||||
pt->thread_id = thread_id;
|
pt->thread_id = thread_id;
|
||||||
@ -355,7 +347,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
if (it == per_thread_map_.end()) {
|
if (it == per_thread_map_.end()) {
|
||||||
return &dummy;
|
return &dummy;
|
||||||
} else {
|
} else {
|
||||||
return it->second;
|
return it->second.get();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
EIGEN_THREAD_LOCAL PerThread per_thread_;
|
EIGEN_THREAD_LOCAL PerThread per_thread_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user