comparison OrthancServer/ServerContext.cpp @ 3947:cf6eb4fc6841 transcoding

fix issue #179: use a shared mutex to avoid deadlock in python plugins
author Alain Mazy <alain@mazy.be>
date Tue, 19 May 2020 16:19:05 +0200
parents 0b3256c3ee14
children 5fe8c6d3212e
comparison
equal deleted inserted replaced
3946:1f33ed7f82e6 3947:cf6eb4fc6841
82 82
83 if (obj.get() != NULL) 83 if (obj.get() != NULL)
84 { 84 {
85 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get()); 85 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
86 86
87 boost::recursive_mutex::scoped_lock lock(that->listenersMutex_); 87 boost::shared_lock<boost::shared_mutex> lock(that->listenersMutex_);
88 for (ServerListeners::iterator it = that->listeners_.begin(); 88 for (ServerListeners::iterator it = that->listeners_.begin();
89 it != that->listeners_.end(); ++it) 89 it != that->listeners_.end(); ++it)
90 { 90 {
91 try 91 try
92 { 92 {
329 void ServerContext::Stop() 329 void ServerContext::Stop()
330 { 330 {
331 if (!done_) 331 if (!done_)
332 { 332 {
333 { 333 {
334 boost::recursive_mutex::scoped_lock lock(listenersMutex_); 334 boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
335 listeners_.clear(); 335 listeners_.clear();
336 } 336 }
337 337
338 done_ = true; 338 done_ = true;
339 339
416 416
417 // Test if the instance must be filtered out 417 // Test if the instance must be filtered out
418 bool accepted = true; 418 bool accepted = true;
419 419
420 { 420 {
421 boost::recursive_mutex::scoped_lock lock(listenersMutex_); 421 boost::shared_lock<boost::shared_mutex> lock(listenersMutex_);
422 422
423 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 423 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
424 { 424 {
425 try 425 try
426 { 426 {
506 } 506 }
507 507
508 if (status == StoreStatus_Success || 508 if (status == StoreStatus_Success ||
509 status == StoreStatus_AlreadyStored) 509 status == StoreStatus_AlreadyStored)
510 { 510 {
511 boost::recursive_mutex::scoped_lock lock(listenersMutex_); 511 boost::shared_lock<boost::shared_mutex> lock(listenersMutex_);
512 512
513 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 513 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
514 { 514 {
515 try 515 try
516 { 516 {
856 856
857 857
858 #if ORTHANC_ENABLE_PLUGINS == 1 858 #if ORTHANC_ENABLE_PLUGINS == 1
859 void ServerContext::SetPlugins(OrthancPlugins& plugins) 859 void ServerContext::SetPlugins(OrthancPlugins& plugins)
860 { 860 {
861 boost::recursive_mutex::scoped_lock lock(listenersMutex_); 861 boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
862 862
863 plugins_ = &plugins; 863 plugins_ = &plugins;
864 864
865 // TODO REFACTOR THIS 865 // TODO REFACTOR THIS
866 listeners_.clear(); 866 listeners_.clear();
869 } 869 }
870 870
871 871
872 void ServerContext::ResetPlugins() 872 void ServerContext::ResetPlugins()
873 { 873 {
874 boost::recursive_mutex::scoped_lock lock(listenersMutex_); 874 boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
875 875
876 plugins_ = NULL; 876 plugins_ = NULL;
877 877
878 // TODO REFACTOR THIS 878 // TODO REFACTOR THIS
879 listeners_.clear(); 879 listeners_.clear();