comparison OrthancServer/DicomProtocol/ReusableDicomUserConnection.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 d710ea64f0fd
children f967bdf8534e
comparison
equal deleted inserted replaced
1452:b737acb13da5 1453:c0bdc47165ef
129 closeThread_ = boost::thread(CloseThread, this); 129 closeThread_ = boost::thread(CloseThread, this);
130 } 130 }
131 131
132 ReusableDicomUserConnection::~ReusableDicomUserConnection() 132 ReusableDicomUserConnection::~ReusableDicomUserConnection()
133 { 133 {
134 continue_ = false; 134 if (continue_)
135 closeThread_.join(); 135 {
136 Close(); 136 LOG(ERROR) << "INTERNAL ERROR: ReusableDicomUserConnection::Finalize() should be invoked manually to avoid mess in the destruction order!";
137 Finalize();
138 }
137 } 139 }
138 140
139 void ReusableDicomUserConnection::SetMillisecondsBeforeClose(uint64_t ms) 141 void ReusableDicomUserConnection::SetMillisecondsBeforeClose(uint64_t ms)
140 { 142 {
141 boost::mutex::scoped_lock lock(mutex_); 143 boost::mutex::scoped_lock lock(mutex_);
164 } 166 }
165 167
166 lastUse_ = Now(); 168 lastUse_ = Now();
167 mutex_.unlock(); 169 mutex_.unlock();
168 } 170 }
171
172
173 void ReusableDicomUserConnection::Finalize()
174 {
175 if (continue_)
176 {
177 continue_ = false;
178
179 if (closeThread_.joinable())
180 {
181 closeThread_.join();
182 }
183
184 Close();
185 }
186 }
169 } 187 }
170 188