Mercurial > hg > orthanc-stone
annotate Framework/Oracle/ThreadedOracle.cpp @ 1326:55166e57a77c broker
doc
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 24 Mar 2020 21:32:35 +0100 |
parents | 257f2c9a02ac |
children | 297e57d3508c |
rev | line source |
---|---|
748 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
748 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "ThreadedOracle.h" | |
23 | |
24 #include "SleepOracleCommand.h" | |
25 | |
1077 | 26 #include <Core/Logging.h> |
748 | 27 #include <Core/OrthancException.h> |
28 | |
29 namespace OrthancStone | |
30 { | |
31 class ThreadedOracle::Item : public Orthanc::IDynamicObject | |
32 { | |
33 private: | |
1075 | 34 boost::weak_ptr<IObserver> receiver_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
35 std::unique_ptr<IOracleCommand> command_; |
748 | 36 |
37 public: | |
1075 | 38 Item(boost::weak_ptr<IObserver> receiver, |
748 | 39 IOracleCommand* command) : |
40 receiver_(receiver), | |
41 command_(command) | |
42 { | |
43 if (command == NULL) | |
44 { | |
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
46 } | |
47 } | |
48 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
49 boost::weak_ptr<IObserver> GetReceiver() |
748 | 50 { |
51 return receiver_; | |
52 } | |
53 | |
54 IOracleCommand& GetCommand() | |
55 { | |
56 assert(command_.get() != NULL); | |
57 return *command_; | |
58 } | |
59 }; | |
60 | |
61 | |
62 class ThreadedOracle::SleepingCommands : public boost::noncopyable | |
63 { | |
64 private: | |
65 class Item | |
66 { | |
67 private: | |
1075 | 68 boost::weak_ptr<IObserver> receiver_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
69 std::unique_ptr<SleepOracleCommand> command_; |
748 | 70 boost::posix_time::ptime expiration_; |
71 | |
72 public: | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
73 Item(boost::weak_ptr<IObserver> receiver, |
748 | 74 SleepOracleCommand* command) : |
75 receiver_(receiver), | |
76 command_(command) | |
77 { | |
78 if (command == NULL) | |
79 { | |
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
81 } | |
82 | |
760
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
748
diff
changeset
|
83 expiration_ = (boost::posix_time::microsec_clock::local_time() + |
748 | 84 boost::posix_time::milliseconds(command_->GetDelay())); |
85 } | |
86 | |
87 const boost::posix_time::ptime& GetExpirationTime() const | |
88 { | |
89 return expiration_; | |
90 } | |
91 | |
92 void Awake(IMessageEmitter& emitter) | |
93 { | |
94 assert(command_.get() != NULL); | |
95 | |
96 SleepOracleCommand::TimeoutMessage message(*command_); | |
97 emitter.EmitMessage(receiver_, message); | |
98 } | |
99 }; | |
100 | |
101 typedef std::list<Item*> Content; | |
102 | |
103 boost::mutex mutex_; | |
104 Content content_; | |
105 | |
106 public: | |
107 ~SleepingCommands() | |
108 { | |
109 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
110 { | |
111 if (*it != NULL) | |
112 { | |
113 delete *it; | |
114 } | |
115 } | |
116 } | |
117 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
118 void Add(boost::weak_ptr<IObserver> receiver, |
748 | 119 SleepOracleCommand* command) // Takes ownership |
120 { | |
121 boost::mutex::scoped_lock lock(mutex_); | |
122 | |
123 content_.push_back(new Item(receiver, command)); | |
124 } | |
125 | |
126 void AwakeExpired(IMessageEmitter& emitter) | |
127 { | |
128 boost::mutex::scoped_lock lock(mutex_); | |
129 | |
760
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
748
diff
changeset
|
130 const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); |
748 | 131 |
132 Content stillSleeping; | |
133 | |
134 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
135 { | |
136 if (*it != NULL && | |
137 (*it)->GetExpirationTime() <= now) | |
138 { | |
139 (*it)->Awake(emitter); | |
140 delete *it; | |
141 *it = NULL; | |
142 } | |
143 else | |
144 { | |
145 stillSleeping.push_back(*it); | |
146 } | |
147 } | |
148 | |
149 // Compact the still-sleeping commands | |
150 content_ = stillSleeping; | |
151 } | |
152 }; | |
153 | |
154 | |
155 void ThreadedOracle::Step() | |
156 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
157 std::unique_ptr<Orthanc::IDynamicObject> object(queue_.Dequeue(100)); |
748 | 158 |
159 if (object.get() != NULL) | |
160 { | |
161 Item& item = dynamic_cast<Item&>(*object); | |
162 | |
1077 | 163 if (item.GetCommand().GetType() == IOracleCommand::Type_Sleep) |
748 | 164 { |
1077 | 165 SleepOracleCommand& command = dynamic_cast<SleepOracleCommand&>(item.GetCommand()); |
166 | |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
167 std::unique_ptr<SleepOracleCommand> copy(new SleepOracleCommand(command.GetDelay())); |
1077 | 168 |
169 if (command.HasPayload()) | |
748 | 170 { |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
171 copy->AcquirePayload(command.ReleasePayload()); |
748 | 172 } |
1077 | 173 |
174 sleepingCommands_->Add(item.GetReceiver(), copy.release()); | |
748 | 175 } |
1077 | 176 else |
748 | 177 { |
1104 | 178 GenericOracleRunner runner; |
979 | 179 |
1109
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
180 { |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
181 boost::mutex::scoped_lock lock(mutex_); |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
182 runner.SetOrthanc(orthanc_); |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
183 runner.SetRootDirectory(rootDirectory_); |
748 | 184 |
1126 | 185 #if ORTHANC_ENABLE_DCMTK == 1 |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
186 if (dicomCache_) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
187 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
188 runner.SetDicomCache(dicomCache_); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
189 } |
1126 | 190 #endif |
748 | 191 } |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
192 |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
193 runner.Run(item.GetReceiver(), emitter_, item.GetCommand()); |
748 | 194 } |
195 } | |
196 } | |
197 | |
198 | |
199 void ThreadedOracle::Worker(ThreadedOracle* that) | |
200 { | |
201 assert(that != NULL); | |
202 | |
203 for (;;) | |
204 { | |
205 { | |
206 boost::mutex::scoped_lock lock(that->mutex_); | |
207 if (that->state_ != State_Running) | |
208 { | |
209 return; | |
210 } | |
211 } | |
212 | |
213 that->Step(); | |
214 } | |
215 } | |
216 | |
217 | |
218 void ThreadedOracle::SleepingWorker(ThreadedOracle* that) | |
219 { | |
220 assert(that != NULL); | |
221 | |
222 for (;;) | |
223 { | |
224 { | |
225 boost::mutex::scoped_lock lock(that->mutex_); | |
226 if (that->state_ != State_Running) | |
227 { | |
228 return; | |
229 } | |
230 } | |
231 | |
232 that->sleepingCommands_->AwakeExpired(that->emitter_); | |
233 | |
234 boost::this_thread::sleep(boost::posix_time::milliseconds(that->sleepingTimeResolution_)); | |
235 } | |
236 } | |
237 | |
238 | |
239 void ThreadedOracle::StopInternal() | |
240 { | |
241 { | |
242 boost::mutex::scoped_lock lock(mutex_); | |
243 | |
244 if (state_ == State_Setup || | |
245 state_ == State_Stopped) | |
246 { | |
247 return; | |
248 } | |
249 else | |
250 { | |
251 state_ = State_Stopped; | |
252 } | |
253 } | |
254 | |
255 if (sleepingWorker_.joinable()) | |
256 { | |
257 sleepingWorker_.join(); | |
258 } | |
259 | |
260 for (size_t i = 0; i < workers_.size(); i++) | |
261 { | |
262 if (workers_[i] != NULL) | |
263 { | |
264 if (workers_[i]->joinable()) | |
265 { | |
266 workers_[i]->join(); | |
267 } | |
268 | |
269 delete workers_[i]; | |
270 } | |
271 } | |
272 } | |
273 | |
274 | |
275 ThreadedOracle::ThreadedOracle(IMessageEmitter& emitter) : | |
276 emitter_(emitter), | |
1109
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
277 rootDirectory_("."), |
748 | 278 state_(State_Setup), |
279 workers_(4), | |
280 sleepingCommands_(new SleepingCommands), | |
281 sleepingTimeResolution_(50) // By default, time resolution of 50ms | |
282 { | |
283 } | |
284 | |
285 | |
765 | 286 ThreadedOracle::~ThreadedOracle() |
287 { | |
288 if (state_ == State_Running) | |
289 { | |
290 LOG(ERROR) << "The threaded oracle is still running, explicit call to " | |
291 << "Stop() is mandatory to avoid crashes"; | |
292 } | |
293 | |
294 try | |
295 { | |
296 StopInternal(); | |
297 } | |
298 catch (Orthanc::OrthancException& e) | |
299 { | |
300 LOG(ERROR) << "Exception while stopping the threaded oracle: " << e.What(); | |
301 } | |
302 catch (...) | |
303 { | |
304 LOG(ERROR) << "Native exception while stopping the threaded oracle"; | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
305 } |
765 | 306 } |
307 | |
308 | |
748 | 309 void ThreadedOracle::SetOrthancParameters(const Orthanc::WebServiceParameters& orthanc) |
310 { | |
311 boost::mutex::scoped_lock lock(mutex_); | |
1109
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
312 orthanc_ = orthanc; |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
313 } |
748 | 314 |
1109
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
315 |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
316 void ThreadedOracle::SetRootDirectory(const std::string& rootDirectory) |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
317 { |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
318 boost::mutex::scoped_lock lock(mutex_); |
79b1b541fe15
ThreadedOracle::SetRootDirectory()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
319 rootDirectory_ = rootDirectory; |
748 | 320 } |
321 | |
322 | |
760
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
748
diff
changeset
|
323 void ThreadedOracle::SetThreadsCount(unsigned int count) |
748 | 324 { |
325 boost::mutex::scoped_lock lock(mutex_); | |
326 | |
327 if (count <= 0) | |
328 { | |
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
330 } | |
331 else if (state_ != State_Setup) | |
332 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
333 LOG(ERROR) << "ThreadedOracle::SetThreadsCount(): (state_ != State_Setup)"; |
748 | 334 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
335 } | |
336 else | |
337 { | |
338 workers_.resize(count); | |
339 } | |
340 } | |
341 | |
342 | |
343 void ThreadedOracle::SetSleepingTimeResolution(unsigned int milliseconds) | |
344 { | |
345 boost::mutex::scoped_lock lock(mutex_); | |
346 | |
347 if (milliseconds <= 0) | |
348 { | |
349 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
350 } | |
351 else if (state_ != State_Setup) | |
352 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
353 LOG(ERROR) << "ThreadedOracle::SetSleepingTimeResolution(): (state_ != State_Setup)"; |
748 | 354 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
355 } | |
356 else | |
357 { | |
358 sleepingTimeResolution_ = milliseconds; | |
359 } | |
360 } | |
361 | |
362 | |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
363 void ThreadedOracle::SetDicomCacheSize(size_t size) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
364 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
365 #if ORTHANC_ENABLE_DCMTK == 1 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
366 boost::mutex::scoped_lock lock(mutex_); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
367 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
368 if (state_ != State_Setup) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
369 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
370 LOG(ERROR) << "ThreadedOracle::SetDicomCacheSize(): (state_ != State_Setup)"; |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
371 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
372 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
373 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
374 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
375 if (size == 0) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
376 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
377 dicomCache_.reset(); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
378 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
379 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
380 { |
1150 | 381 dicomCache_.reset(new ParsedDicomCache(size)); |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
382 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
383 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
384 #endif |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
385 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
386 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1109
diff
changeset
|
387 |
748 | 388 void ThreadedOracle::Start() |
389 { | |
390 boost::mutex::scoped_lock lock(mutex_); | |
391 | |
392 if (state_ != State_Setup) | |
393 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
819
diff
changeset
|
394 LOG(ERROR) << "ThreadedOracle::Start(): (state_ != State_Setup)"; |
748 | 395 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
396 } | |
397 else | |
398 { | |
1140 | 399 LOG(WARNING) << "Starting oracle with " << workers_.size() << " worker threads"; |
748 | 400 state_ = State_Running; |
401 | |
402 for (unsigned int i = 0; i < workers_.size(); i++) | |
403 { | |
404 workers_[i] = new boost::thread(Worker, this); | |
405 } | |
406 | |
407 sleepingWorker_ = boost::thread(SleepingWorker, this); | |
408 } | |
409 } | |
410 | |
411 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
412 bool ThreadedOracle::Schedule(boost::shared_ptr<IObserver> receiver, |
748 | 413 IOracleCommand* command) |
414 { | |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
415 std::unique_ptr<Item> item(new Item(receiver, command)); |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
416 |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
417 { |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
418 boost::mutex::scoped_lock lock(mutex_); |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
419 |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
420 if (state_ == State_Running) |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
421 { |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
422 //LOG(INFO) << "New oracle command queued"; |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
423 queue_.Enqueue(item.release()); |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
424 return true; |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
425 } |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
426 else |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
427 { |
1140 | 428 LOG(TRACE) << "Command not enqueued, as the oracle has stopped"; |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
429 return false; |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
430 } |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
431 } |
748 | 432 } |
433 } |