Separate the top of UnloadPlugin into a precursor function.

This commit is contained in:
David Anderson 2015-08-14 17:55:58 -07:00
parent 44bacdc067
commit 9ef8cc7064
3 changed files with 19 additions and 12 deletions

View File

@ -1478,23 +1478,30 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
bool CPluginManager::UnloadPlugin(IPlugin *plugin) bool CPluginManager::UnloadPlugin(IPlugin *plugin)
{ {
CPlugin *pPlugin = (CPlugin *)plugin; return ScheduleUnload((CPlugin *)plugin);
}
/* This prevents removal during insertion or anything else weird */ bool CPluginManager::ScheduleUnload(CPlugin *pPlugin)
if (m_plugins.find(pPlugin) == m_plugins.end()) {
{ // Should not be recursively removing.
return false; assert(m_plugins.find(pPlugin) != m_plugins.end());
}
IPluginContext *pContext = plugin->GetBaseContext(); IPluginContext *pContext = pPlugin->GetBaseContext();
if (pContext != NULL && pContext->IsInExec()) if (pContext && pContext->IsInExec())
{ {
char buffer[255]; char buffer[255];
ke::SafeSprintf(buffer, sizeof(buffer), "sm plugins unload %s\n", plugin->GetFilename()); ke::SafeSprintf(buffer, sizeof(buffer), "sm plugins unload %s\n", pPlugin->GetFilename());
engine->ServerCommand(buffer); engine->ServerCommand(buffer);
return false; return false;
} }
// No need to schedule an unload, we can unload immediately.
UnloadPluginImpl(pPlugin);
return true;
}
void CPluginManager::UnloadPluginImpl(CPlugin *pPlugin)
{
/* Remove us from the lookup table and linked list */ /* Remove us from the lookup table and linked list */
m_plugins.remove(pPlugin); m_plugins.remove(pPlugin);
m_LoadLookup.remove(pPlugin->m_filename); m_LoadLookup.remove(pPlugin->m_filename);
@ -1535,8 +1542,6 @@ bool CPluginManager::UnloadPlugin(IPlugin *plugin)
/* Tell the plugin to delete itself */ /* Tell the plugin to delete itself */
delete pPlugin; delete pPlugin;
return true;
} }
IPlugin *CPluginManager::FindPluginByContext(const sp_context_t *ctx) IPlugin *CPluginManager::FindPluginByContext(const sp_context_t *ctx)

View File

@ -455,6 +455,9 @@ private:
bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength); bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
void _SetPauseState(CPlugin *pPlugin, bool pause); void _SetPauseState(CPlugin *pPlugin, bool pause);
bool ScheduleUnload(CPlugin *plugin);
void UnloadPluginImpl(CPlugin *plugin);
protected: protected:
/** /**
* Caching internal objects * Caching internal objects

View File

@ -392,7 +392,6 @@ static cell_t FormatNativeString(IPluginContext *pContext, const cell_t *params)
} }
/* Get buffer information */ /* Get buffer information */
int err;
char *output_buffer; char *output_buffer;
char *format_buffer; char *format_buffer;