Mercurial > hg > orthanc
comparison Core/MultiThreading/BagOfRunnablesBySteps.cpp @ 1453:c0bdc47165ef
code to warn about possible threading problems
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 Jul 2015 12:26:44 +0200 |
parents | 6e7e5ed91c2d |
children | f967bdf8534e |
comparison
equal
deleted
inserted
replaced
1452:b737acb13da5 | 1453:c0bdc47165ef |
---|---|
33 #include "../PrecompiledHeaders.h" | 33 #include "../PrecompiledHeaders.h" |
34 #include "BagOfRunnablesBySteps.h" | 34 #include "BagOfRunnablesBySteps.h" |
35 | 35 |
36 #include <stack> | 36 #include <stack> |
37 #include <boost/thread.hpp> | 37 #include <boost/thread.hpp> |
38 #include <glog/logging.h> | |
38 | 39 |
39 namespace Orthanc | 40 namespace Orthanc |
40 { | 41 { |
41 struct BagOfRunnablesBySteps::PImpl | 42 struct BagOfRunnablesBySteps::PImpl |
42 { | 43 { |
126 } | 127 } |
127 | 128 |
128 | 129 |
129 BagOfRunnablesBySteps::~BagOfRunnablesBySteps() | 130 BagOfRunnablesBySteps::~BagOfRunnablesBySteps() |
130 { | 131 { |
131 StopAll(); | 132 if (!pimpl_->stopFinishListener_) |
132 | |
133 // Stop the finish listener | |
134 pimpl_->stopFinishListener_ = true; | |
135 pimpl_->oneThreadIsStopped_.notify_one(); // Awakens the listener | |
136 | |
137 if (pimpl_->finishListener_->joinable()) | |
138 { | 133 { |
139 pimpl_->finishListener_->join(); | 134 LOG(ERROR) << "INTERNAL ERROR: BagOfRunnablesBySteps::Finalize() should be invoked manually to avoid mess in the destruction order!"; |
135 Finalize(); | |
140 } | 136 } |
141 } | 137 } |
142 | 138 |
143 | 139 |
144 void BagOfRunnablesBySteps::Add(IRunnableBySteps* runnable) | 140 void BagOfRunnablesBySteps::Add(IRunnableBySteps* runnable) |
163 pimpl_->oneThreadIsJoined_.wait(lock); | 159 pimpl_->oneThreadIsJoined_.wait(lock); |
164 } | 160 } |
165 | 161 |
166 pimpl_->continue_ = true; | 162 pimpl_->continue_ = true; |
167 } | 163 } |
164 | |
165 | |
166 | |
167 void BagOfRunnablesBySteps::Finalize() | |
168 { | |
169 if (!pimpl_->stopFinishListener_) | |
170 { | |
171 StopAll(); | |
172 | |
173 // Stop the finish listener | |
174 pimpl_->stopFinishListener_ = true; | |
175 pimpl_->oneThreadIsStopped_.notify_one(); // Awakens the listener | |
176 | |
177 if (pimpl_->finishListener_->joinable()) | |
178 { | |
179 pimpl_->finishListener_->join(); | |
180 } | |
181 } | |
182 } | |
183 | |
168 } | 184 } |