Skip to content

Commit 40e00c1

Browse files
committed
Cleanup. Add extra alignment.
Signed-off-by: Michał Zientkiewicz <[email protected]>
1 parent ecaedcf commit 40e00c1

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

dali/pipeline/util/thread_pool.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727

2828
namespace dali {
2929

30-
#define QUEUE_LOCK queue_lock_
31-
3230
ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const char* name)
33-
: threads_(num_thread), running_(true), started_(false), outstanding_work_(0) {
31+
: threads_(num_thread) {
3432
DALI_ENFORCE(num_thread > 0, "Thread pool must have non-zero size");
3533
#if NVML_ENABLED
3634
// We use NVML only for setting thread affinity
@@ -49,7 +47,7 @@ ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const c
4947
ThreadPool::~ThreadPool() {
5048
WaitForWork(false);
5149

52-
std::unique_lock lock(QUEUE_LOCK);
50+
std::unique_lock lock(queue_lock_);
5351
running_ = false;
5452
lock.unlock();
5553
// Each thread will lower the semaphore by at most 1
@@ -64,12 +62,12 @@ void ThreadPool::AddWork(Work work, int64_t priority, bool start_immediately) {
6462
bool started_before = started_;
6563
outstanding_work_.fetch_add(1);
6664
if (started_before) {
67-
std::lock_guard lock(QUEUE_LOCK);
65+
std::lock_guard lock(queue_lock_);
6866
work_queue_.push({priority, std::move(work)});
6967
} else {
7068
work_queue_.push({priority, std::move(work)});
7169
if (start_immediately) {
72-
std::lock_guard lock(QUEUE_LOCK);
70+
std::lock_guard lock(queue_lock_);
7371
started_ = true;
7472
}
7573
}
@@ -107,7 +105,7 @@ void ThreadPool::WaitForWork(bool checkForErrors) {
107105
void ThreadPool::RunAll(bool wait) {
108106
if (!started_) {
109107
{
110-
std::lock_guard lock(QUEUE_LOCK);
108+
std::lock_guard lock(queue_lock_);
111109
started_ = true;
112110
}
113111
queue_semaphore_.release(work_queue_.size());
@@ -165,7 +163,7 @@ void ThreadPool::ThreadMain(int thread_id, int device_id, bool set_affinity,
165163
queue_semaphore_.acquire();
166164

167165
// This lock guards only the queue, not the condition - that's handled by the semaphore
168-
std::unique_lock lock(QUEUE_LOCK);
166+
std::unique_lock lock(queue_lock_);
169167

170168
if (!running_)
171169
break;

dali/pipeline/util/thread_pool.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ class DLL_PUBLIC ThreadPool {
8989
};
9090
std::priority_queue<PrioritizedWork, std::vector<PrioritizedWork>, SortByPriority> work_queue_;
9191

92-
bool running_;
93-
bool started_;
94-
std::atomic_int outstanding_work_;
95-
std::mutex queue_mutex_, error_mutex_, completed_mutex_;
96-
spinlock queue_lock_;
97-
std::condition_variable completed_;
92+
alignas(64) spinlock queue_lock_;
9893
dali::counting_semaphore queue_semaphore_{0};
94+
bool running_ = true;
95+
bool started_ = false;
96+
alignas(64) std::atomic_int outstanding_work_{0};
97+
std::mutex error_mutex_, completed_mutex_;
98+
std::condition_variable completed_;
9999

100100
// Stored error strings for each thread
101101
vector<std::queue<string>> tl_errors_;

0 commit comments

Comments
 (0)