Skip to content

Commit

Permalink
reduce write locking
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 12, 2023
1 parent 1aea456 commit 07ab5bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,15 @@ impl Config {
}

pub fn get_or_create_plugin(&self, plugin_name: &str) -> Arc<dyn Plugin> {
if let Some(plugin) = self.plugins.read().unwrap().get(plugin_name) {
return plugin.clone();
}
let plugin = ExternalPlugin::newa(plugin_name.to_string());
self.plugins
.write()
.unwrap()
.entry(plugin_name.to_string())
.or_insert_with(|| ExternalPlugin::newa(plugin_name.to_string()))
.clone()
.insert(plugin_name.to_string(), plugin.clone());
plugin
}
pub fn list_plugins(&self) -> Vec<Arc<dyn Plugin>> {
self.plugins.read().unwrap().values().cloned().collect()
Expand Down

0 comments on commit 07ab5bd

Please sign in to comment.