From 12d4f382d6d822dad61887386ff20978c7dcf83c Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sat, 25 Jan 2014 22:35:34 +0100 Subject: [PATCH] erasure-code: allow loading a plugin from factory() The Mutex scope is restricted to only protect the load() method and not the factory() method. This allows a plugin to load another plugin from within the factory() method. Reviewed-By: Christophe Courtaut Signed-off-by: Loic Dachary --- src/erasure-code/ErasureCodePlugin.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/erasure-code/ErasureCodePlugin.cc b/src/erasure-code/ErasureCodePlugin.cc index a76d6140ccab9..63494415de6f9 100644 --- a/src/erasure-code/ErasureCodePlugin.cc +++ b/src/erasure-code/ErasureCodePlugin.cc @@ -68,15 +68,18 @@ int ErasureCodePluginRegistry::factory(const std::string &plugin_name, ErasureCodeInterfaceRef *erasure_code, ostream &ss) { - Mutex::Locker l(lock); - ErasureCodePlugin *plugin = get(plugin_name); - if (plugin == 0) { + ErasureCodePlugin *plugin; + { + Mutex::Locker l(lock); int r = 0; - loading = true; - r = load(plugin_name, parameters, &plugin, ss); - loading = false; - if (r != 0) - return r; + plugin = get(plugin_name); + if (plugin == 0) { + loading = true; + r = load(plugin_name, parameters, &plugin, ss); + loading = false; + if (r != 0) + return r; + } } return plugin->factory(parameters, erasure_code); -- 2.39.5