summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r--plugins/Db3x_mmap/dbcache.cpp13
-rw-r--r--plugins/Db3x_mmap/dbcontacts.cpp41
2 files changed, 21 insertions, 33 deletions
diff --git a/plugins/Db3x_mmap/dbcache.cpp b/plugins/Db3x_mmap/dbcache.cpp
index 1e9369cc85..271de9d512 100644
--- a/plugins/Db3x_mmap/dbcache.cpp
+++ b/plugins/Db3x_mmap/dbcache.cpp
@@ -134,7 +134,7 @@ static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR id
if (FlushViewOfFile(pDbCache, 0) == 0) {
if (flushFailTick == 0)
flushFailTick = GetTickCount();
- else if (GetTickCount() - flushFailTick > 5000)
+ else if (GetTickCount() - flushFailTick > 5000)
DatabaseCorruption(NULL);
}
else
@@ -150,7 +150,7 @@ void DBFlush(int setting)
if (FlushViewOfFile(pDbCache, 0) == 0) {
if (flushFailTick == 0)
flushFailTick = GetTickCount();
- else if (GetTickCount() - flushFailTick > 5000)
+ else if (GetTickCount() - flushFailTick > 5000)
DatabaseCorruption(NULL);
}
else
@@ -163,15 +163,6 @@ void DBFlush(int setting)
flushBuffersTimerId = SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
}
-static INT_PTR CacheSetSafetyMode(WPARAM wParam,LPARAM lParam)
-{
- EnterCriticalSection(&csDbAccess);
- safetyMode = wParam;
- LeaveCriticalSection(&csDbAccess);
- DBFlush(1);
- return 0;
-}
-
int InitCache(void)
{
DWORD x;
diff --git a/plugins/Db3x_mmap/dbcontacts.cpp b/plugins/Db3x_mmap/dbcontacts.cpp
index a827db3385..8abdc02ebc 100644
--- a/plugins/Db3x_mmap/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/dbcontacts.cpp
@@ -103,10 +103,9 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char *szP
VL = AddToCachedContactList(VLtemp.hContact,index);
VL->hNext = (HANDLE)dbc->ofsNext;
- if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto))) {
- LeaveCriticalSection(&csDbAccess);
+ if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto)))
return VL->hNext;
- }
+
VLtemp.hContact = VL->hNext;
} }
@@ -126,12 +125,10 @@ STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
{
mir_cslock lck(csDbAccess);
DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- if (dbc->signature != DBCONTACT_SIGNATURE) {
- LeaveCriticalSection(&csDbAccess);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
return 1;
- }
+
if (hContact == (HANDLE)dbHeader.ofsUser) {
- LeaveCriticalSection(&csDbAccess);
log0("FATAL: del of user chain attempted.");
return 1;
}
@@ -198,7 +195,7 @@ STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
}
dbcPrev->ofsNext = ofsNext;
DBWrite(ofsThis,dbcPrev,sizeof(DBContact));
-
+
DBCachedContactValueList VLtemp;
VLtemp.hContact = (HANDLE)ofsThis;
if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
@@ -219,22 +216,22 @@ STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
STDMETHODIMP_(HANDLE) CDdxMmap::AddContact()
{
log0("add contact");
+ {
+ mir_cslock lck(csDbAccess);
+ DWORD ofsNew = CreateNewSpace(sizeof(DBContact));
+
+ DBContact dbc = { 0 };
+ dbc.signature = DBCONTACT_SIGNATURE;
+ dbc.ofsNext = dbHeader.ofsFirstContact;
+ dbHeader.ofsFirstContact = ofsNew;
+ dbHeader.contactCount++;
+ DBWrite(ofsNew,&dbc,sizeof(DBContact));
+ DBWrite(0,&dbHeader,sizeof(dbHeader));
+ DBFlush(0);
- mir_cslock lck(csDbAccess);
- DWORD ofsNew = CreateNewSpace(sizeof(DBContact));
-
- DBContact dbc = { 0 };
- dbc.signature = DBCONTACT_SIGNATURE;
- dbc.ofsNext = dbHeader.ofsFirstContact;
- dbHeader.ofsFirstContact = ofsNew;
- dbHeader.contactCount++;
- DBWrite(ofsNew,&dbc,sizeof(DBContact));
- DBWrite(0,&dbHeader,sizeof(dbHeader));
- DBFlush(0);
-
- AddToCachedContactList((HANDLE)ofsNew, -1);
+ AddToCachedContactList((HANDLE)ofsNew, -1);
+ }
- LeaveCriticalSection(&csDbAccess);
NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
return (HANDLE)ofsNew;
}