diff options
Diffstat (limited to 'src/modules/database/mdatabasecache.cpp')
-rw-r--r-- | src/modules/database/mdatabasecache.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp index 24dda4f9ee..6074d85bf9 100644 --- a/src/modules/database/mdatabasecache.cpp +++ b/src/modules/database/mdatabasecache.cpp @@ -36,26 +36,29 @@ static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalVal MDatabaseCache::MDatabaseCache() :
m_lSettings(100, stringCompare),
- m_lContacts(50, LIST<DBCachedContact>::FTSortFunc(HandleKeySort)),
+ m_lContacts(50, HandleKeySortT),
m_lGlobalSettings(50, compareGlobals)
{
m_hCacheHeap = HeapCreate(0, 0, 0);
+ InitializeCriticalSection(&m_cs);
}
MDatabaseCache::~MDatabaseCache()
{
- HeapDestroy(m_hCacheHeap);
m_lContacts.destroy();
m_lSettings.destroy();
m_lGlobalSettings.destroy();
+ HeapDestroy(m_hCacheHeap);
+ DeleteCriticalSection(&m_cs);
}
/////////////////////////////////////////////////////////////////////////////////////////
DBCachedContact* MDatabaseCache::AddContactToCache(HANDLE hContact)
{
- DBCachedContact VLtemp = { hContact };
- int index = m_lContacts.getIndex(&VLtemp);
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
if (index == -1) {
DBCachedContact* VL = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact));
VL->hContact = hContact;
@@ -68,15 +71,15 @@ DBCachedContact* MDatabaseCache::AddContactToCache(HANDLE hContact) DBCachedContact* MDatabaseCache::GetCachedContact(HANDLE hContact)
{
- DBCachedContact VLtemp = { hContact };
- int index = m_lContacts.getIndex(&VLtemp);
+ int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
return (index == -1) ? NULL : m_lContacts[index];
}
void MDatabaseCache::FreeCachedContact(HANDLE hContact)
{
- DBCachedContact VLtemp = { hContact };
- int index = m_lContacts.getIndex(&VLtemp);
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
if (index == -1)
return;
@@ -91,6 +94,12 @@ void MDatabaseCache::FreeCachedContact(HANDLE hContact) HeapFree( m_hCacheHeap, 0, VL );
m_lContacts.remove(index);
+
+ for (int i=0; i < m_lContacts.getCount(); i++) {
+ DBCachedContact *cc = m_lContacts[i];
+ if (cc->hNext == hContact)
+ cc->hNext = NULL;
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
|