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:
parent
d4f2d30332
commit
b07a13fab0
@ -70,26 +70,39 @@ MyDatabase::MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent)
|
|||||||
m_Info.driver = NULL;
|
m_Info.driver = NULL;
|
||||||
m_Info.maxTimeout = info->maxTimeout;
|
m_Info.maxTimeout = info->maxTimeout;
|
||||||
m_Info.port = info->port;
|
m_Info.port = info->port;
|
||||||
|
|
||||||
|
m_pRefLock = threader->MakeMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyDatabase::~MyDatabase()
|
MyDatabase::~MyDatabase()
|
||||||
{
|
{
|
||||||
mysql_close(m_mysql);
|
mysql_close(m_mysql);
|
||||||
m_mysql = NULL;
|
m_mysql = NULL;
|
||||||
|
|
||||||
|
m_pRefLock->DestroyThis();
|
||||||
|
if (m_pFullLock)
|
||||||
|
{
|
||||||
|
m_pFullLock->DestroyThis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyDatabase::IncReferenceCount()
|
void MyDatabase::IncReferenceCount()
|
||||||
{
|
{
|
||||||
|
m_pRefLock->Lock();
|
||||||
m_refcount++;
|
m_refcount++;
|
||||||
|
m_pRefLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyDatabase::Close()
|
bool MyDatabase::Close()
|
||||||
{
|
{
|
||||||
|
m_pRefLock->Lock();
|
||||||
if (m_refcount > 1)
|
if (m_refcount > 1)
|
||||||
{
|
{
|
||||||
m_refcount--;
|
m_refcount--;
|
||||||
|
m_pRefLock->Unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
m_pRefLock->Unlock();
|
||||||
|
|
||||||
/* Remove us from the search list */
|
/* Remove us from the search list */
|
||||||
if (m_bPersistent)
|
if (m_bPersistent)
|
||||||
|
@ -33,6 +33,7 @@ private:
|
|||||||
MYSQL *m_mysql;
|
MYSQL *m_mysql;
|
||||||
unsigned int m_refcount;
|
unsigned int m_refcount;
|
||||||
IMutex *m_pFullLock;
|
IMutex *m_pFullLock;
|
||||||
|
IMutex *m_pRefLock;
|
||||||
|
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
DatabaseInfo m_Info;
|
DatabaseInfo m_Info;
|
||||||
|
Loading…
Reference in New Issue
Block a user