@@ -96,7 +96,7 @@ class PluginManager::Impl
9696
9797 bool requires_daytime_settings_;
9898
99- std::unordered_map<std::string, std::shared_ptr <BasePlugin>> instances_;
99+ std::unordered_map<std::string, std::unique_ptr <BasePlugin>> instances_;
100100
101101 std::unordered_set<std::string> enabled_plugins_;
102102 std::unordered_map<std::string, std::function<PluginCreatorType>> plugin_creators_;
@@ -124,10 +124,6 @@ void PluginManager::Impl::unload()
124124
125125 for (auto && id_handle: instances_)
126126 {
127- const auto count = id_handle.second .use_count ();
128- if (count != 1 )
129- self_.warn (fmt::format (" Plugin ({}) is used as {} on somewhere before unloading." , id_handle.first , count));
130-
131127 // delete plugin instance.
132128 id_handle.second .reset ();
133129 }
@@ -154,12 +150,18 @@ std::unique_ptr<BasePlugin> PluginManager::Impl::load_plugin(const std::string&
154150
155151 try
156152 {
157- plugin_creators_[plugin_id] = boost::dll::import_alias<PluginCreatorType>(
153+ auto result = plugin_creators_. insert ({plugin_id, boost::dll::import_alias<PluginCreatorType>(
158154 plugin_path,
159155 " create_plugin" ,
160- boost::dll::load_mode::append_decorations);
156+ boost::dll::load_mode::rtld_global | boost::dll::load_mode::append_decorations)});
157+
158+ if (!result.second )
159+ {
160+ self_.error (fmt::format (" Plugin '{}' was already loaded." , plugin_id));
161+ return nullptr ;
162+ }
161163
162- auto instance = plugin_creators_. at (plugin_id) (pipeline_);
164+ auto instance = result. first -> second (pipeline_);
163165
164166 for (const auto & required_plugin: instance->get_required_plugins ())
165167 {
0 commit comments