From ab2d4a06b46f6865e3c69885d12f80b22dac2422 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 19 Sep 2014 22:44:50 +0300 Subject: [PATCH] server/state: Fully implement unload_module() --- src/server/state.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/server/state.cpp b/src/server/state.cpp index 13406a9..e064035 100644 --- a/src/server/state.cpp +++ b/src/server/state.cpp @@ -201,17 +201,23 @@ struct CState: public State, public interface::Server // interface::Server version; doesn't directly unload void unload_module(const ss_ &module_name) { + log_v(MODULE, "unload_module(%s)", cs(module_name)); interface::MutexScope ms(m_modules_mutex); auto it = m_modules.find(module_name); - if(it == m_modules.end()) + if(it == m_modules.end()){ + log_w(MODULE, "unload_module(%s): Not loaded", cs(module_name)); return; + } m_unloads_requested.insert(module_name); } void reload_module(const ss_ &module_name, const ss_ &path) { log_i(MODULE, "reload_module(%s)", cs(module_name)); - unload_module_u(module_name); + { + interface::MutexScope ms(m_modules_mutex); + unload_module_u(module_name); + } load_module(module_name, path); // Send core::continue directly to module { @@ -229,10 +235,10 @@ struct CState: public State, public interface::Server } // Direct version; internal and unsafe + // Call with m_modules_mutex locked. void unload_module_u(const ss_ &module_name) { log_i(MODULE, "unload_module_u(): module_name=%s", cs(module_name)); - interface::MutexScope ms(m_modules_mutex); // Get and lock module auto it = m_modules.find(module_name); if(it == m_modules.end()){ @@ -415,9 +421,12 @@ struct CState: public State, public interface::Server } } interface::MutexScope ms(m_modules_mutex); - for(const ss_ &module_name : m_unloads_requested){ - log_w("state", "Unloading %s: not implemented", cs(module_name)); - // TODO: Unload + for(auto it = m_unloads_requested.begin(); + it != m_unloads_requested.end();){ + ss_ module_name = *it; // Copy + it++; // Increment before unload_module_u; it erases this + log_i("state", "Unloading %s as requested", cs(module_name)); + unload_module_u(module_name); } m_unloads_requested.clear(); }