comparison OrthancServer/ServerContext.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 5ba7471780ae
children 68827c07e683
comparison
equal deleted inserted replaced
1452:b737acb13da5 1453:c0bdc47165ef
75 75
76 if (obj.get() != NULL) 76 if (obj.get() != NULL)
77 { 77 {
78 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get()); 78 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
79 79
80 boost::mutex::scoped_lock lock(that->listenersMutex_);
80 for (ServerListeners::iterator it = that->listeners_.begin(); 81 for (ServerListeners::iterator it = that->listeners_.begin();
81 it != that->listeners_.end(); ++it) 82 it != that->listeners_.end(); ++it)
82 { 83 {
83 try 84 try
84 { 85 {
117 118
118 119
119 120
120 ServerContext::~ServerContext() 121 ServerContext::~ServerContext()
121 { 122 {
122 Stop(); 123 if (!done_)
124 {
125 LOG(ERROR) << "INTERNAL ERROR: ServerContext::Stop() should be invoked manually to avoid mess in the destruction order!";
126 Stop();
127 }
123 } 128 }
124 129
125 130
126 void ServerContext::Stop() 131 void ServerContext::Stop()
127 { 132 {
131 136
132 if (changeThread_.joinable()) 137 if (changeThread_.joinable())
133 { 138 {
134 changeThread_.join(); 139 changeThread_.join();
135 } 140 }
141
142 scu_.Finalize();
143
144 // Do not change the order below!
145 scheduler_.Stop();
146 index_.Stop();
136 } 147 }
137 } 148 }
138 149
139 150
140 void ServerContext::SetCompressionEnabled(bool enabled) 151 void ServerContext::SetCompressionEnabled(bool enabled)
166 SimplifyTags(simplified, dicom.GetJson()); 177 SimplifyTags(simplified, dicom.GetJson());
167 178
168 // Test if the instance must be filtered out 179 // Test if the instance must be filtered out
169 bool accepted = true; 180 bool accepted = true;
170 181
171 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 182 {
172 { 183 boost::mutex::scoped_lock lock(listenersMutex_);
173 try 184
185 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
174 { 186 {
175 if (!it->GetListener().FilterIncomingInstance(simplified, dicom.GetRemoteAet())) 187 try
176 { 188 {
177 accepted = false; 189 if (!it->GetListener().FilterIncomingInstance(simplified, dicom.GetRemoteAet()))
178 break; 190 {
179 } 191 accepted = false;
180 } 192 break;
181 catch (OrthancException& e) 193 }
182 { 194 }
183 LOG(ERROR) << "Error in the " << it->GetDescription() 195 catch (OrthancException& e)
184 << " callback while receiving an instance: " << e.What(); 196 {
185 throw; 197 LOG(ERROR) << "Error in the " << it->GetDescription()
198 << " callback while receiving an instance: " << e.What();
199 throw;
200 }
186 } 201 }
187 } 202 }
188 203
189 if (!accepted) 204 if (!accepted)
190 { 205 {
249 } 264 }
250 265
251 if (status == StoreStatus_Success || 266 if (status == StoreStatus_Success ||
252 status == StoreStatus_AlreadyStored) 267 status == StoreStatus_AlreadyStored)
253 { 268 {
269 boost::mutex::scoped_lock lock(listenersMutex_);
270
254 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 271 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
255 { 272 {
256 try 273 try
257 { 274 {
258 it->GetListener().SignalStoredInstance(resultPublicId, dicom, simplified); 275 it->GetListener().SignalStoredInstance(resultPublicId, dicom, simplified);
420 void ServerContext::SetPlugins(OrthancPlugins& plugins) 437 void ServerContext::SetPlugins(OrthancPlugins& plugins)
421 { 438 {
422 plugins_ = &plugins; 439 plugins_ = &plugins;
423 440
424 // TODO REFACTOR THIS 441 // TODO REFACTOR THIS
442 boost::mutex::scoped_lock lock(listenersMutex_);
425 listeners_.clear(); 443 listeners_.clear();
426 listeners_.push_back(ServerListener(lua_, "Lua")); 444 listeners_.push_back(ServerListener(lua_, "Lua"));
427 listeners_.push_back(ServerListener(plugins, "plugin")); 445 listeners_.push_back(ServerListener(plugins, "plugin"));
428 } 446 }
429 447
431 void ServerContext::ResetPlugins() 449 void ServerContext::ResetPlugins()
432 { 450 {
433 plugins_ = NULL; 451 plugins_ = NULL;
434 452
435 // TODO REFACTOR THIS 453 // TODO REFACTOR THIS
454 boost::mutex::scoped_lock lock(listenersMutex_);
436 listeners_.clear(); 455 listeners_.clear();
437 listeners_.push_back(ServerListener(lua_, "Lua")); 456 listeners_.push_back(ServerListener(lua_, "Lua"));
438 } 457 }
439 458
440 459