added amb670 (exposed IDBThreadOperation to extensions)
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401163
This commit is contained in:
parent
8fa974961c
commit
c3cd2ac4a3
@ -351,6 +351,7 @@ void DBManager::RemoveDriver(IDBDriver *pDriver)
|
|||||||
{
|
{
|
||||||
IDBThreadOperation *op = (*qiter);
|
IDBThreadOperation *op = (*qiter);
|
||||||
op->CancelThinkPart();
|
op->CancelThinkPart();
|
||||||
|
op->Destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,8 +489,15 @@ void DBManager::KillWorkerThread()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IdentityToken_t *s_pAddBlock = NULL;
|
||||||
|
|
||||||
bool DBManager::AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio)
|
bool DBManager::AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio)
|
||||||
{
|
{
|
||||||
|
if (s_pAddBlock && op->GetOwner() == s_pAddBlock)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pWorker)
|
if (!m_pWorker)
|
||||||
{
|
{
|
||||||
m_pWorker = g_pThreader->MakeWorker(this, true);
|
m_pWorker = g_pThreader->MakeWorker(this, true);
|
||||||
@ -599,6 +607,7 @@ void DBManager::RunFrame()
|
|||||||
m_ThinkQueue.pop();
|
m_ThinkQueue.pop();
|
||||||
m_pThinkLock->Unlock();
|
m_pThinkLock->Unlock();
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
|
op->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBManager::OnTerminate(IThreadHandle *pThread, bool cancel)
|
void DBManager::OnTerminate(IThreadHandle *pThread, bool cancel)
|
||||||
@ -606,6 +615,43 @@ void DBManager::OnTerminate(IThreadHandle *pThread, bool cancel)
|
|||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||||
|
{
|
||||||
|
s_pAddBlock = pToken;
|
||||||
|
|
||||||
|
/* Kill the thread so we can flush everything into the think queue... */
|
||||||
|
KillWorkerThread();
|
||||||
|
|
||||||
|
/* Run all of the think operations.
|
||||||
|
* Unlike the driver unloading example, we'll let these calls go through,
|
||||||
|
* since a plugin unloading is far more normal.
|
||||||
|
*/
|
||||||
|
Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin();
|
||||||
|
Queue<IDBThreadOperation *> templist;
|
||||||
|
while (iter != m_ThinkQueue.end())
|
||||||
|
{
|
||||||
|
IDBThreadOperation *op = (*iter);
|
||||||
|
if (op->GetOwner() == pToken)
|
||||||
|
{
|
||||||
|
templist.push(op);
|
||||||
|
iter = m_ThinkQueue.erase(iter);
|
||||||
|
} else {
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (iter = templist.begin();
|
||||||
|
iter != templist.end();
|
||||||
|
iter++)
|
||||||
|
{
|
||||||
|
IDBThreadOperation *op = (*iter);
|
||||||
|
op->RunThinkPart();
|
||||||
|
op->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
s_pAddBlock = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void DBManager::OnPluginUnloaded(IPlugin *plugin)
|
void DBManager::OnPluginUnloaded(IPlugin *plugin)
|
||||||
{
|
{
|
||||||
/* Kill the thread so we can flush everything into the think queue... */
|
/* Kill the thread so we can flush everything into the think queue... */
|
||||||
@ -623,7 +669,7 @@ void DBManager::OnPluginUnloaded(IPlugin *plugin)
|
|||||||
while (iter != m_ThinkQueue.end())
|
while (iter != m_ThinkQueue.end())
|
||||||
{
|
{
|
||||||
IDBThreadOperation *op = (*iter);
|
IDBThreadOperation *op = (*iter);
|
||||||
if (op->GetPlugin() == plugin)
|
if (op->GetOwner() == plugin->GetIdentity())
|
||||||
{
|
{
|
||||||
templist.push(op);
|
templist.push(op);
|
||||||
iter = m_ThinkQueue.erase(iter);
|
iter = m_ThinkQueue.erase(iter);
|
||||||
@ -638,6 +684,7 @@ void DBManager::OnPluginUnloaded(IPlugin *plugin)
|
|||||||
{
|
{
|
||||||
IDBThreadOperation *op = (*iter);
|
IDBThreadOperation *op = (*iter);
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
|
op->Destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,16 +44,6 @@ struct ConfDbInfo
|
|||||||
DatabaseInfo info;
|
DatabaseInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IDBThreadOperation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual IDBDriver *GetDriver() =0;
|
|
||||||
virtual CPlugin *GetPlugin() =0;
|
|
||||||
virtual void RunThreadPart() =0;
|
|
||||||
virtual void RunThinkPart() =0;
|
|
||||||
virtual void CancelThinkPart() =0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DBManager :
|
class DBManager :
|
||||||
public IDBManager,
|
public IDBManager,
|
||||||
public SMGlobalClass,
|
public SMGlobalClass,
|
||||||
@ -71,6 +61,7 @@ public:
|
|||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
void OnSourceModLevelChange(const char *mapName);
|
void OnSourceModLevelChange(const char *mapName);
|
||||||
|
void OnSourceModIdentityDropped(IdentityToken_t *pToken);
|
||||||
void OnSourceModShutdown();
|
void OnSourceModShutdown();
|
||||||
public: //IHandleTypeDispatch
|
public: //IHandleTypeDispatch
|
||||||
void OnHandleDestroy(HandleType_t type, void *object);
|
void OnHandleDestroy(HandleType_t type, void *object);
|
||||||
|
@ -56,6 +56,7 @@ class SMGlobalClass
|
|||||||
friend class SourceMod_Core;
|
friend class SourceMod_Core;
|
||||||
friend class SourceModBase;
|
friend class SourceModBase;
|
||||||
friend class CoreConfig;
|
friend class CoreConfig;
|
||||||
|
friend class CExtensionManager;
|
||||||
public:
|
public:
|
||||||
SMGlobalClass();
|
SMGlobalClass();
|
||||||
public:
|
public:
|
||||||
@ -135,6 +136,13 @@ public:
|
|||||||
virtual void OnSourceModGameInitialized()
|
virtual void OnSourceModGameInitialized()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when an identity is dropped (right now, extensions only)
|
||||||
|
*/
|
||||||
|
virtual void OnSourceModIdentityDropped(IdentityToken_t *pToken)
|
||||||
|
{
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
SMGlobalClass *m_pGlobalClassNext;
|
SMGlobalClass *m_pGlobalClassNext;
|
||||||
static SMGlobalClass *head;
|
static SMGlobalClass *head;
|
||||||
|
@ -13,13 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sm_queue.h"
|
#include "sm_queue.h"
|
||||||
|
#include <IDBDriver.h>
|
||||||
enum PrioQueueLevel
|
|
||||||
{
|
|
||||||
PrioQueue_High,
|
|
||||||
PrioQueue_Normal,
|
|
||||||
PrioQueue_Low
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class PrioQueue
|
class PrioQueue
|
||||||
|
@ -138,9 +138,9 @@ public:
|
|||||||
m_pDatabase->Close();
|
m_pDatabase->Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CPlugin *GetPlugin()
|
IdentityToken_t *GetOwner()
|
||||||
{
|
{
|
||||||
return me;
|
return me->GetIdentity();
|
||||||
}
|
}
|
||||||
IDBDriver *GetDriver()
|
IDBDriver *GetDriver()
|
||||||
{
|
{
|
||||||
@ -163,7 +163,6 @@ public:
|
|||||||
m_pFunction->PushString("Driver is unloading");
|
m_pFunction->PushString("Driver is unloading");
|
||||||
m_pFunction->PushCell(m_Data);
|
m_pFunction->PushCell(m_Data);
|
||||||
m_pFunction->Execute(NULL);
|
m_pFunction->Execute(NULL);
|
||||||
delete this;
|
|
||||||
}
|
}
|
||||||
void RunThinkPart()
|
void RunThinkPart()
|
||||||
{
|
{
|
||||||
@ -196,7 +195,9 @@ public:
|
|||||||
{
|
{
|
||||||
g_HandleSys.FreeHandle(qh, &sec);
|
g_HandleSys.FreeHandle(qh, &sec);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void Destroy()
|
||||||
|
{
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@ -222,9 +223,9 @@ public:
|
|||||||
strncopy(dbname, _dbname, sizeof(dbname));
|
strncopy(dbname, _dbname, sizeof(dbname));
|
||||||
me = g_PluginSys.GetPluginByCtx(m_pFunction->GetParentContext()->GetContext());
|
me = g_PluginSys.GetPluginByCtx(m_pFunction->GetParentContext()->GetContext());
|
||||||
}
|
}
|
||||||
CPlugin *GetPlugin()
|
IdentityToken_t *GetOwner()
|
||||||
{
|
{
|
||||||
return me;
|
return me->GetIdentity();
|
||||||
}
|
}
|
||||||
IDBDriver *GetDriver()
|
IDBDriver *GetDriver()
|
||||||
{
|
{
|
||||||
@ -253,7 +254,6 @@ public:
|
|||||||
m_pFunction->PushString("Driver is unloading");
|
m_pFunction->PushString("Driver is unloading");
|
||||||
m_pFunction->PushCell(0);
|
m_pFunction->PushCell(0);
|
||||||
m_pFunction->Execute(NULL);
|
m_pFunction->Execute(NULL);
|
||||||
delete this;
|
|
||||||
}
|
}
|
||||||
void RunThinkPart()
|
void RunThinkPart()
|
||||||
{
|
{
|
||||||
@ -274,6 +274,9 @@ public:
|
|||||||
m_pFunction->PushString(hndl == BAD_HANDLE ? error : "");
|
m_pFunction->PushString(hndl == BAD_HANDLE ? error : "");
|
||||||
m_pFunction->PushCell(0);
|
m_pFunction->PushCell(0);
|
||||||
m_pFunction->Execute(NULL);
|
m_pFunction->Execute(NULL);
|
||||||
|
}
|
||||||
|
void Destroy()
|
||||||
|
{
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@ -382,6 +385,7 @@ static cell_t SQL_TConnect(IPluginContext *pContext, const cell_t *params)
|
|||||||
/* Do everything right now */
|
/* Do everything right now */
|
||||||
op->RunThreadPart();
|
op->RunThreadPart();
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
|
op->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -699,6 +703,7 @@ static cell_t SQL_TQuery(IPluginContext *pContext, const cell_t *params)
|
|||||||
/* Do everything right now */
|
/* Do everything right now */
|
||||||
op->RunThreadPart();
|
op->RunThreadPart();
|
||||||
op->RunThinkPart();
|
op->RunThinkPart();
|
||||||
|
op->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -689,6 +689,17 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IdentityToken_t *pIdentity;
|
||||||
|
if ((pIdentity = pExt->GetIdentity()) != NULL)
|
||||||
|
{
|
||||||
|
SMGlobalClass *glob = SMGlobalClass::head;
|
||||||
|
while (glob)
|
||||||
|
{
|
||||||
|
glob->OnSourceModIdentityDropped(pIdentity);
|
||||||
|
glob = glob->m_pGlobalClassNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete pExt;
|
delete pExt;
|
||||||
|
|
||||||
List<CExtension *>::iterator iter;
|
List<CExtension *>::iterator iter;
|
||||||
|
Loading…
Reference in New Issue
Block a user