summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-05 23:14:24 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-05 23:14:24 +0300
commit909c090503ce1021a69e7793c550b857ef025e77 (patch)
treecda68b2aff3f4ff7a47c592a1f6d83e9dd3f12fa
parent94c711953d71b21e4cc4c950dec921b253ae0d54 (diff)
switch to the locking schema of db3x_mmap, it's safer
-rw-r--r--plugins/Dbx_mdbx/src/dbsettings.cpp39
-rw-r--r--src/mir_app/src/mdatabasecache.cpp4
2 files changed, 23 insertions, 20 deletions
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp
index b4491189bf..d17543fbd8 100644
--- a/plugins/Dbx_mdbx/src/dbsettings.cpp
+++ b/plugins/Dbx_mdbx/src/dbsettings.cpp
@@ -44,6 +44,8 @@ int CDbxMDBX::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCST
size_t settingNameLen = strlen(szSetting);
size_t moduleNameLen = strlen(szModule);
+ mir_cslock lck(m_csDbAccess);
+
LBL_Seek:
char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
@@ -259,6 +261,7 @@ LBL_WriteString:
return 1;
}
+ mir_cslockfull lck(m_csDbAccess);
char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen);
// we don't cache blobs and passwords
@@ -280,6 +283,7 @@ LBL_WriteString:
m_cache->SetCachedVariant(&dbcwWork.value, pCachedValue);
}
if (szCachedSettingName[-1] != 0) {
+ lck.unlock();
NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwWork);
return 0;
}
@@ -339,6 +343,7 @@ LBL_WriteString:
}
// notify
+ lck.unlock();
NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwNotif);
return 0;
}
@@ -350,26 +355,28 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR sz
size_t settingNameLen = strlen(szSetting);
size_t moduleNameLen = strlen(szModule);
-
- char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
-
- if (szCachedSettingName[-1] == 0) // it's not a resident variable
{
- DBSettingKey *keyVal = (DBSettingKey*)_alloca(sizeof(DBSettingKey) + settingNameLen);
- keyVal->hContact = contactID;
- keyVal->dwModuleId = GetModuleID(szModule);
- memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1);
+ mir_cslock lck(m_csDbAccess);
+ char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
+
+ if (szCachedSettingName[-1] == 0) // it's not a resident variable
+ {
+ DBSettingKey *keyVal = (DBSettingKey*)_alloca(sizeof(DBSettingKey) + settingNameLen);
+ keyVal->hContact = contactID;
+ keyVal->dwModuleId = GetModuleID(szModule);
+ memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1);
+
+ txn_ptr trnlck(m_env);
+ MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen };
+ if (mdbx_del(trnlck, m_dbSettings, &key, nullptr) != MDBX_SUCCESS)
+ return 1;
+ if (trnlck.commit() != MDBX_SUCCESS)
+ return 1;
+ }
- txn_ptr trnlck(m_env);
- MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen };
- if (mdbx_del(trnlck, m_dbSettings, &key, nullptr) != MDBX_SUCCESS)
- return 1;
- if (trnlck.commit() != MDBX_SUCCESS)
- return 1;
+ m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1);
}
- m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1);
-
// notify
DBCONTACTWRITESETTING dbcws = { 0 };
dbcws.szModule = szModule;
diff --git a/src/mir_app/src/mdatabasecache.cpp b/src/mir_app/src/mdatabasecache.cpp
index 30a6639a8a..5c33fcf8c7 100644
--- a/src/mir_app/src/mdatabasecache.cpp
+++ b/src/mir_app/src/mdatabasecache.cpp
@@ -184,7 +184,6 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID,
if (index != -1) {
V = m_lGlobalSettings[index];
if (bAllocate == -1) {
- mir_cslock lck(m_csVal);
FreeCachedVariant(&V->value);
m_lGlobalSettings.remove(index);
mir_free(V);
@@ -195,7 +194,6 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID,
if (bAllocate != 1)
return nullptr;
- mir_cslock lck(m_csVal);
V = (DBCachedGlobalValue*)mir_calloc(sizeof(DBCachedGlobalValue));
V->name = szSetting;
m_lGlobalSettings.insert(V);
@@ -224,7 +222,6 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID,
if (bAllocate != 1)
return nullptr;
- mir_cslock lck(m_csVal);
V = (DBCachedContactValue *)mir_calloc(sizeof(DBCachedContactValue));
if (cc->last)
cc->last->next = V;
@@ -234,7 +231,6 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID,
V->name = szSetting;
}
else if (bAllocate == -1) {
- mir_cslock lck(m_csVal);
m_lastVL = nullptr;
FreeCachedVariant(&V->value);
if (cc->first == V) {