File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -522,7 +522,8 @@ namespace
522522 int release ();
523523
524524 private:
525- ~ConfiguredPlugin ();
525+ ~ConfiguredPlugin () {}
526+ void destroy ();
526527
527528 RefPtr<PluginModule> module ;
528529 unsigned int regPlugin;
@@ -685,10 +686,15 @@ namespace
685686
686687 GlobalPtr<PluginsMap> plugins;
687688
688- ConfiguredPlugin::~ConfiguredPlugin ()
689+ void ConfiguredPlugin::destroy ()
689690 {
690- MutexLockGuard g ( plugins->mutex , FB_FUNCTION);
691+ // plugins->mutex must be entered by current thread
691692
693+ #ifdef DEV_BUILD
694+ if (!plugins->mutex .tryEnter (FB_FUNCTION))
695+ fb_assert (false );
696+ plugins->mutex .leave ();
697+ #endif
692698 if (!destroyingPluginsMap)
693699 {
694700 plugins->remove (MapKey (module ->getPlugin (regPlugin).type , plugName));
@@ -733,6 +739,16 @@ namespace
733739
734740 if (x == 0 )
735741 {
742+ { // plugins->mutex scope
743+ MutexLockGuard g (plugins->mutex , FB_FUNCTION);
744+ if (refCounter != 0 )
745+ return 1 ;
746+
747+ destroy ();
748+ }
749+
750+ // Must run out of mutex scope to avoid deadlock with PluginManager::threadDetach()
751+ // called when module is unloaded by dtor
736752 delete this ;
737753 return 0 ;
738754 }
You can’t perform that action at this time.
0 commit comments