Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
  • Loading branch information
JanuszL committed May 23, 2022
1 parent 7398e0b commit e4b6c19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions dali/pipeline/util/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

namespace dali {

ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const std::string name)
ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const std::string &name)
: threads_(num_thread), running_(true), work_complete_(true), started_(false)
, active_threads_(0), name_(name) {
, active_threads_(0) {
DALI_ENFORCE(num_thread > 0, "Thread pool must have non-zero size");
#if NVML_ENABLED
// only for the CPU pipeline
Expand All @@ -37,7 +37,8 @@ ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const s
#endif
// Start the threads in the main loop
for (int i = 0; i < num_thread; ++i) {
threads_[i] = std::thread(std::bind(&ThreadPool::ThreadMain, this, i, device_id, set_affinity));
threads_[i] = std::thread(std::bind(&ThreadPool::ThreadMain, this, i, device_id, set_affinity,
make_string("[DALI][TP", i, "]", name)));
}
tl_errors_.resize(num_thread);
}
Expand Down Expand Up @@ -117,8 +118,9 @@ std::vector<std::thread::id> ThreadPool::GetThreadIds() const {
}


void ThreadPool::ThreadMain(int thread_id, int device_id, bool set_affinity) {
SetThreadName(make_string("[DALI][TP", thread_id, "]", name_).c_str());
void ThreadPool::ThreadMain(int thread_id, int device_id, bool set_affinity,
const std::string &name) {
SetThreadName(name.c_str());
DeviceGuard g(device_id);
try {
#if NVML_ENABLED
Expand Down
6 changes: 3 additions & 3 deletions dali/pipeline/util/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DLL_PUBLIC ThreadPool {
typedef std::function<void(int)> Work;

DLL_PUBLIC ThreadPool(int num_thread, int device_id, bool set_affinity,
const std::string name);
const std::string &name);

DLL_PUBLIC ~ThreadPool();

Expand Down Expand Up @@ -68,7 +68,8 @@ class DLL_PUBLIC ThreadPool {
DISABLE_COPY_MOVE_ASSIGN(ThreadPool);

private:
DLL_PUBLIC void ThreadMain(int thread_id, int device_id, bool set_affinity);
DLL_PUBLIC void ThreadMain(int thread_id, int device_id, bool set_affinity,
const std::string &name);

vector<std::thread> threads_;

Expand All @@ -84,7 +85,6 @@ class DLL_PUBLIC ThreadPool {
bool work_complete_;
bool started_;
int active_threads_;
std::string name_;
std::mutex mutex_;
std::condition_variable condition_;
std::condition_variable completed_;
Expand Down
2 changes: 1 addition & 1 deletion dali/pipeline/util/worker_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WorkerThread {
public:
typedef std::function<void(void)> Work;

inline WorkerThread(int device_id, bool set_affinity, const std::string name) :
inline WorkerThread(int device_id, bool set_affinity, const std::string &name) :
running_(true), work_complete_(true), barrier_(2) {
#if NVML_ENABLED
if (device_id != CPU_ONLY_DEVICE_ID) {
Expand Down

0 comments on commit e4b6c19

Please sign in to comment.