server/state: Fix more unload synchronization
parent
bde862d05c
commit
40bf6f6bf0
|
@ -729,10 +729,13 @@ struct CState: public State, public interface::Server
|
|||
}
|
||||
|
||||
// Direct version; internal and unsafe
|
||||
// Call with m_modules_mutex locked.
|
||||
// Call with no mutexes locked.
|
||||
void unload_module_u(const ss_ &module_name)
|
||||
{
|
||||
log_i(MODULE, "unload_module_u(): module_name=%s", cs(module_name));
|
||||
sp_<ModuleContainer> mc;
|
||||
{
|
||||
interface::MutexScope ms(m_modules_mutex);
|
||||
// Get and lock module
|
||||
auto it = m_modules.find(module_name);
|
||||
if(it == m_modules.end()){
|
||||
|
@ -740,7 +743,7 @@ struct CState: public State, public interface::Server
|
|||
cs(module_name));
|
||||
return;
|
||||
}
|
||||
sp_<ModuleContainer> mc = it->second;
|
||||
mc = it->second;
|
||||
{
|
||||
interface::MutexScope mc_ms(mc->mutex);
|
||||
// Delete subscriptions
|
||||
|
@ -764,10 +767,15 @@ struct CState: public State, public interface::Server
|
|||
// Remove server-wide reference to module container
|
||||
m_modules.erase(module_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Destruct module
|
||||
log_t(MODULE, "unload_module_u[%s]: Deleting module", cs(module_name));
|
||||
mc->thread_request_stop();
|
||||
mc->thread_join();
|
||||
|
||||
{
|
||||
interface::MutexScope ms(m_modules_mutex);
|
||||
// So, hopefully this is the last reference because we're going to
|
||||
// unload the shared executable...
|
||||
if(!mc.unique())
|
||||
|
@ -785,6 +793,7 @@ struct CState: public State, public interface::Server
|
|||
emit_event(Event("core:module_unloaded",
|
||||
new interface::ModuleUnloadedEvent(module_name)));
|
||||
}
|
||||
}
|
||||
|
||||
ss_ get_modules_path()
|
||||
{
|
||||
|
@ -1081,14 +1090,11 @@ struct CState: public State, public interface::Server
|
|||
module->event(Event::t("core:unload"), nullptr);
|
||||
});
|
||||
}
|
||||
// Unload modules using unload_module_u()
|
||||
{
|
||||
interface::MutexScope ms(m_modules_mutex);
|
||||
// Unload modules
|
||||
for(const ss_ &module_name : unloads_requested){
|
||||
log_i(MODULE, "Unloading %s", cs(module_name));
|
||||
unload_module_u(module_name);
|
||||
}
|
||||
}
|
||||
// Load modules
|
||||
for(const interface::ModuleInfo &info : loads_requested){
|
||||
log_i(MODULE, "Loading %s (reload requested)", cs(info.name));
|
||||
|
|
Loading…
Reference in New Issue