Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsEngine.cpp @ 2665:389d050a2e66 jobs
fix deadlock, speed up unit tests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 Jun 2018 13:51:31 +0200 |
parents | 34dc57f4a7d2 |
children | d26dd081df97 |
comparison
equal
deleted
inserted
replaced
2664:a21b244efb37 | 2665:389d050a2e66 |
---|---|
118 { | 118 { |
119 assert(engine != NULL); | 119 assert(engine != NULL); |
120 | 120 |
121 while (engine->IsRunning()) | 121 while (engine->IsRunning()) |
122 { | 122 { |
123 boost::this_thread::sleep(boost::posix_time::milliseconds(200)); | 123 boost::this_thread::sleep(boost::posix_time::milliseconds(engine->threadSleep_)); |
124 engine->GetRegistry().ScheduleRetries(); | 124 engine->GetRegistry().ScheduleRetries(); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 | 128 |
133 | 133 |
134 LOG(INFO) << "Worker thread " << workerIndex << " has started"; | 134 LOG(INFO) << "Worker thread " << workerIndex << " has started"; |
135 | 135 |
136 while (engine->IsRunning()) | 136 while (engine->IsRunning()) |
137 { | 137 { |
138 JobsRegistry::RunningJob running(engine->GetRegistry(), 100); | 138 JobsRegistry::RunningJob running(engine->GetRegistry(), engine->threadSleep_); |
139 | 139 |
140 if (running.IsValid()) | 140 if (running.IsValid()) |
141 { | 141 { |
142 LOG(INFO) << "Executing job with priority " << running.GetPriority() | 142 LOG(INFO) << "Executing job with priority " << running.GetPriority() |
143 << " in worker thread " << workerIndex << ": " << running.GetId(); | 143 << " in worker thread " << workerIndex << ": " << running.GetId(); |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 JobsEngine::JobsEngine() : | 157 JobsEngine::JobsEngine() : |
158 state_(State_Setup), | 158 state_(State_Setup), |
159 threadSleep_(200), | |
159 workers_(1) | 160 workers_(1) |
160 { | 161 { |
161 } | 162 } |
162 | 163 |
163 | 164 |
182 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 183 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
183 } | 184 } |
184 | 185 |
185 workers_.resize(count); | 186 workers_.resize(count); |
186 } | 187 } |
187 | 188 |
189 | |
190 void JobsEngine::SetThreadSleep(unsigned int sleep) | |
191 { | |
192 boost::mutex::scoped_lock lock(stateMutex_); | |
193 | |
194 if (state_ != State_Setup) | |
195 { | |
196 // Can only be invoked before calling "Start()" | |
197 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
198 } | |
199 | |
200 threadSleep_ = sleep; | |
201 } | |
202 | |
188 | 203 |
189 void JobsEngine::Start() | 204 void JobsEngine::Start() |
190 { | 205 { |
191 boost::mutex::scoped_lock lock(stateMutex_); | 206 boost::mutex::scoped_lock lock(stateMutex_); |
192 | 207 |