summaryrefslogtreecommitdiff
path: root/src/modules/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/database')
-rw-r--r--src/modules/database/database.h1
-rw-r--r--src/modules/database/mdatabasecache.cpp25
2 files changed, 18 insertions, 8 deletions
diff --git a/src/modules/database/database.h b/src/modules/database/database.h
index e484d341e5..dbecd9dc08 100644
--- a/src/modules/database/database.h
+++ b/src/modules/database/database.h
@@ -26,6 +26,7 @@ class MDatabaseCache : public MIDatabaseCache
HANDLE m_hCacheHeap;
char* m_lastSetting;
DBCachedContact *m_lastVL;
+ CRITICAL_SECTION m_cs;
LIST<DBCachedContact> m_lContacts;
LIST<DBCachedGlobalValue> m_lGlobalSettings;
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;
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////