1
0

Removed the cPluginLua::cResettable class.

The functionality provided by that class has been superseded by cLuaState::cCallback, with better multithreading support.
This commit is contained in:
Mattes D 2016-03-01 17:40:15 +01:00
parent d0a04a7a82
commit 5dfcc15d1f
2 changed files with 1 additions and 82 deletions

View File

@ -60,7 +60,6 @@ void cPluginLua::Close(void)
// If already closed, bail out:
if (!m_LuaState.IsValid())
{
ASSERT(m_Resettables.empty());
ASSERT(m_HookMap.empty());
return;
}
@ -70,18 +69,6 @@ void cPluginLua::Close(void)
ClearConsoleCommands();
ClearWebTabs();
// Notify and remove all m_Resettables (unlock the m_CriticalSection while resetting them):
cResettablePtrs resettables;
std::swap(m_Resettables, resettables);
{
cCSUnlock Unlock(Lock);
for (auto resettable: resettables)
{
resettable->Reset();
}
m_Resettables.clear();
} // cCSUnlock (m_CriticalSection)
// Release all the references in the hook map:
m_HookMap.clear();
@ -1244,16 +1231,6 @@ int cPluginLua::CallFunctionFromForeignState(
void cPluginLua::AddResettable(cPluginLua::cResettablePtr a_Resettable)
{
cCSLock Lock(m_CriticalSection);
m_Resettables.push_back(a_Resettable);
}
void cPluginLua::BindCommand(const AString & a_Command, int a_FnRef)
{
ASSERT(m_Commands.find(a_Command) == m_Commands.end());
@ -1322,25 +1299,3 @@ void cPluginLua::ClearWebTabs(void)
////////////////////////////////////////////////////////////////////////////////
// cPluginLua::cResettable:
cPluginLua::cResettable::cResettable(cPluginLua & a_Plugin):
m_Plugin(&a_Plugin)
{
}
void cPluginLua::cResettable::Reset(void)
{
cCSLock Lock(m_CSPlugin);
m_Plugin = nullptr;
}

View File

@ -62,36 +62,6 @@ public:
/** A base class that represents something related to a plugin
The plugin can reset this class so that the instance can continue to exist but will not engage the (possibly non-existent) plugin anymore.
This is used for scheduled tasks etc., so that they can be queued and reset when the plugin is terminated, without removing them from the queue. */
class cResettable
{
public:
/** Creates a new instance bound to the specified plugin. */
cResettable(cPluginLua & a_Plugin);
// Force a virtual destructor in descendants:
virtual ~cResettable() {}
/** Resets the plugin instance stored within.
The instance will continue to exist, but should not call into the plugin anymore. */
virtual void Reset(void);
protected:
/** The plugin that this instance references.
If nullptr, the plugin has already unloaded and the instance should bail out any processing.
Protected against multithreaded access by m_CSPlugin. */
cPluginLua * m_Plugin;
/** The mutex protecting m_Plugin against multithreaded access. */
cCriticalSection m_CSPlugin;
};
typedef SharedPtr<cResettable> cResettablePtr;
typedef std::vector<cResettablePtr> cResettablePtrs;
cPluginLua(const AString & a_PluginDirectory);
~cPluginLua();
@ -223,9 +193,6 @@ public:
return m_LuaState.Call(a_Fn, a_Args...);
}
/** Adds the specified cResettable instance to m_Resettables, so that it is notified when the plugin is being closed. */
void AddResettable(cResettablePtr a_Resettable);
protected:
/** Maps command name into Lua function reference */
typedef std::map<AString, int> CommandMap;
@ -237,15 +204,12 @@ protected:
typedef std::map<int, cLuaCallbacks> cHookMap;
/** The mutex protecting m_LuaState and each of the m_Resettables[] against multithreaded use. */
/** The mutex protecting m_LuaState against multithreaded use. */
cCriticalSection m_CriticalSection;
/** The plugin's Lua state. */
cLuaState m_LuaState;
/** Objects that need notification when the plugin is about to be unloaded. */
cResettablePtrs m_Resettables;
/** In-game commands that the plugin has registered. */
CommandMap m_Commands;