fixed a possible race condition in the reference counting mechanism of mydatabase

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401108
This commit is contained in:
David Anderson 2007-07-13 21:18:03 +00:00
parent d4f2d30332
commit b07a13fab0
2 changed files with 14 additions and 0 deletions

View File

@ -70,26 +70,39 @@ MyDatabase::MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent)
m_Info.driver = NULL;
m_Info.maxTimeout = info->maxTimeout;
m_Info.port = info->port;
m_pRefLock = threader->MakeMutex();
}
MyDatabase::~MyDatabase()
{
mysql_close(m_mysql);
m_mysql = NULL;
m_pRefLock->DestroyThis();
if (m_pFullLock)
{
m_pFullLock->DestroyThis();
}
}
void MyDatabase::IncReferenceCount()
{
m_pRefLock->Lock();
m_refcount++;
m_pRefLock->Unlock();
}
bool MyDatabase::Close()
{
m_pRefLock->Lock();
if (m_refcount > 1)
{
m_refcount--;
m_pRefLock->Unlock();
return false;
}
m_pRefLock->Unlock();
/* Remove us from the search list */
if (m_bPersistent)

View File

@ -33,6 +33,7 @@ private:
MYSQL *m_mysql;
unsigned int m_refcount;
IMutex *m_pFullLock;
IMutex *m_pRefLock;
/* ---------- */
DatabaseInfo m_Info;