diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-19 08:16:39 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-19 08:16:39 +0000 |
commit | 31ac373a9c9eaac6463c1190628189e2539fc9ce (patch) | |
tree | c23535fb0304e50119ffb49c3cd8f6536d640e3c /plugins/Db3x_mmap/dbcontacts.cpp | |
parent | f45207c731e8d472f57143fb3d152a06ee7bd1f0 (diff) |
cleanup for crit sections
git-svn-id: http://svn.miranda-ng.org/main/trunk@1035 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/dbcontacts.cpp')
-rw-r--r-- | plugins/Db3x_mmap/dbcontacts.cpp | 41 |
1 files changed, 19 insertions, 22 deletions
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;
}
|