diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-05 23:14:24 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-05 23:14:24 +0300 |
commit | 909c090503ce1021a69e7793c550b857ef025e77 (patch) | |
tree | cda68b2aff3f4ff7a47c592a1f6d83e9dd3f12fa /plugins/Dbx_mdbx | |
parent | 94c711953d71b21e4cc4c950dec921b253ae0d54 (diff) |
switch to the locking schema of db3x_mmap, it's safer
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbsettings.cpp | 39 |
1 files changed, 23 insertions, 16 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;
|