diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-10 08:57:15 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-10 08:57:15 +0000 |
commit | 0c8232561f94cbf801c8c5415841d05fac9402f7 (patch) | |
tree | f5da1c1c9af6ae1222db123df16ae8fdb2424888 /src/modules | |
parent | 28f76deeabfe071bf78f19f438b795ee7f0a10c4 (diff) |
write locks for MDatabaseCache
git-svn-id: http://svn.miranda-ng.org/main/trunk@4410 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/database/database.h | 1 | ||||
-rw-r--r-- | src/modules/database/mdatabasecache.cpp | 25 |
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;
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
|