Mercurial > hg > orthanc
comparison OrthancFramework/Sources/MultiThreading/RunnableWorkersPool.cpp @ 5450:9ffd6d18daf3 pg-transactions
log lines now contain the thread name
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 05 Dec 2023 16:26:35 +0100 |
parents | 0ea402b4d901 |
children | 48b8dae6dc77 |
comparison
equal
deleted
inserted
replaced
5449:29858f424fc7 | 5450:9ffd6d18daf3 |
---|---|
37 { | 37 { |
38 private: | 38 private: |
39 const bool& continue_; | 39 const bool& continue_; |
40 SharedMessageQueue& queue_; | 40 SharedMessageQueue& queue_; |
41 boost::thread thread_; | 41 boost::thread thread_; |
42 std::string name_; | |
42 | 43 |
43 static void WorkerThread(Worker* that) | 44 static void WorkerThread(Worker* that) |
44 { | 45 { |
46 Logging::SetCurrentThreadName(that->name_); | |
47 | |
45 while (that->continue_) | 48 while (that->continue_) |
46 { | 49 { |
47 try | 50 try |
48 { | 51 { |
49 std::unique_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); | 52 std::unique_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 public: | 85 public: |
83 Worker(const bool& globalContinue, | 86 Worker(const bool& globalContinue, |
84 SharedMessageQueue& queue) : | 87 SharedMessageQueue& queue, |
88 const std::string& name) : | |
85 continue_(globalContinue), | 89 continue_(globalContinue), |
86 queue_(queue) | 90 queue_(queue), |
91 name_(name) | |
87 { | 92 { |
88 thread_ = boost::thread(WorkerThread, this); | 93 thread_ = boost::thread(WorkerThread, this); |
89 } | 94 } |
90 | 95 |
91 void Join() | 96 void Join() |
103 SharedMessageQueue queue_; | 108 SharedMessageQueue queue_; |
104 }; | 109 }; |
105 | 110 |
106 | 111 |
107 | 112 |
108 RunnableWorkersPool::RunnableWorkersPool(size_t countWorkers) : pimpl_(new PImpl) | 113 RunnableWorkersPool::RunnableWorkersPool(size_t countWorkers, const std::string& name) : pimpl_(new PImpl) |
109 { | 114 { |
110 pimpl_->continue_ = true; | 115 pimpl_->continue_ = true; |
111 | 116 |
112 if (countWorkers == 0) | 117 if (countWorkers == 0) |
113 { | 118 { |
116 | 121 |
117 pimpl_->workers_.resize(countWorkers); | 122 pimpl_->workers_.resize(countWorkers); |
118 | 123 |
119 for (size_t i = 0; i < countWorkers; i++) | 124 for (size_t i = 0; i < countWorkers; i++) |
120 { | 125 { |
121 pimpl_->workers_[i] = new PImpl::Worker(pimpl_->continue_, pimpl_->queue_); | 126 std::string workerName = name + boost::lexical_cast<std::string>(i); |
127 pimpl_->workers_[i] = new PImpl::Worker(pimpl_->continue_, pimpl_->queue_, workerName); | |
122 } | 128 } |
123 } | 129 } |
124 | 130 |
125 | 131 |
126 void RunnableWorkersPool::Stop() | 132 void RunnableWorkersPool::Stop() |