core/Database.cpp
changeset 1157 61c7092246c6
parent 1096 8e11b2ebdc22
child 1201 fb159560c3fe
     1.1 --- a/core/Database.cpp	Tue Jul 24 01:18:28 2007 +0000
     1.2 +++ b/core/Database.cpp	Tue Jul 24 02:24:37 2007 +0000
     1.3 @@ -351,6 +351,7 @@
     1.4  	{
     1.5  		IDBThreadOperation *op = (*qiter);
     1.6  		op->CancelThinkPart();
     1.7 +		op->Destroy();
     1.8  	}
     1.9  }
    1.10  
    1.11 @@ -488,8 +489,15 @@
    1.12  	}
    1.13  }
    1.14  
    1.15 +static IdentityToken_t *s_pAddBlock = NULL;
    1.16 +
    1.17  bool DBManager::AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio)
    1.18  {
    1.19 +	if (s_pAddBlock && op->GetOwner() == s_pAddBlock)
    1.20 +	{
    1.21 +		return false;
    1.22 +	}
    1.23 +
    1.24  	if (!m_pWorker)
    1.25  	{
    1.26  		m_pWorker = g_pThreader->MakeWorker(this, true);
    1.27 @@ -599,6 +607,7 @@
    1.28  	m_ThinkQueue.pop();
    1.29  	m_pThinkLock->Unlock();
    1.30  	op->RunThinkPart();
    1.31 +	op->Destroy();
    1.32  }
    1.33  
    1.34  void DBManager::OnTerminate(IThreadHandle *pThread, bool cancel)
    1.35 @@ -606,6 +615,43 @@
    1.36  	/* Do nothing */
    1.37  }
    1.38  
    1.39 +void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
    1.40 +{
    1.41 +	s_pAddBlock = pToken;
    1.42 +
    1.43 +	/* Kill the thread so we can flush everything into the think queue... */
    1.44 +	KillWorkerThread();
    1.45 +
    1.46 +	/* Run all of the think operations.
    1.47 + 	 * Unlike the driver unloading example, we'll let these calls go through, 
    1.48 +	 * since a plugin unloading is far more normal.
    1.49 +	 */
    1.50 +	Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin();
    1.51 +	Queue<IDBThreadOperation *> templist;
    1.52 +	while (iter != m_ThinkQueue.end())
    1.53 +	{
    1.54 +		IDBThreadOperation *op = (*iter);
    1.55 +		if (op->GetOwner() == pToken)
    1.56 +		{
    1.57 +			templist.push(op);
    1.58 +			iter = m_ThinkQueue.erase(iter);
    1.59 +		} else {
    1.60 +			iter++;
    1.61 +		}
    1.62 +	}
    1.63 +
    1.64 +	for (iter = templist.begin();
    1.65 +		iter != templist.end();
    1.66 +		iter++)
    1.67 +	{
    1.68 +		IDBThreadOperation *op = (*iter);
    1.69 +		op->RunThinkPart();
    1.70 +		op->Destroy();
    1.71 +	}
    1.72 +
    1.73 +	s_pAddBlock = NULL;
    1.74 +}
    1.75 +
    1.76  void DBManager::OnPluginUnloaded(IPlugin *plugin)
    1.77  {
    1.78  	/* Kill the thread so we can flush everything into the think queue... */
    1.79 @@ -623,7 +669,7 @@
    1.80  	while (iter != m_ThinkQueue.end())
    1.81  	{
    1.82  		IDBThreadOperation *op = (*iter);
    1.83 -		if (op->GetPlugin() == plugin)
    1.84 +		if (op->GetOwner() == plugin->GetIdentity())
    1.85  		{
    1.86  			templist.push(op);
    1.87  			iter = m_ThinkQueue.erase(iter);
    1.88 @@ -638,6 +684,7 @@
    1.89  	{
    1.90  		IDBThreadOperation *op = (*iter);
    1.91  		op->RunThinkPart();
    1.92 +		op->Destroy();
    1.93  	}
    1.94  }
    1.95