From 4bc88d46fa9859615521f436511d4f102f20eb67 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 18 Jul 2012 14:11:28 +0000 Subject: databases are still static, but are controlled via classes git-svn-id: http://svn.miranda-ng.org/main/trunk@1014 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x/src/dbcache.cpp | 92 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to 'plugins/Db3x/src/dbcache.cpp') diff --git a/plugins/Db3x/src/dbcache.cpp b/plugins/Db3x/src/dbcache.cpp index 10d34e1ec3..c68db53a0a 100644 --- a/plugins/Db3x/src/dbcache.cpp +++ b/plugins/Db3x/src/dbcache.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define CACHESECTIONSIZE 4096 #define CACHESECTIONCOUNT 32 -static BOOL safetyMode=TRUE; +static BOOL safetyMode = TRUE; static PBYTE pDbCache; static DWORD lastUseCounter; struct DBCacheSectionInfo { @@ -37,23 +37,23 @@ struct DBCacheSectionInfo { static __inline int FindSectionForOffset(const DWORD ofs) { int i; - for(i=0;i=cacheSectionInfo[i].ofsBase && ofs= cacheSectionInfo[i].ofsBase && ofs=cacheSectionInfo[i].ofsBase && ofs=cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end + for(i = 0;i= cacheSectionInfo[i].ofsBase && ofs= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end CopyMemory(pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,CACHESECTIONSIZE); else CopyMemory(pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,bytes-(cacheSectionInfo[i].ofsBase-ofs)); } else { //start at beginning - if(ofs+bytes>=cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end + if (ofs+bytes >= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end CopyMemory(pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE-ofs); else CopyMemory(pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,bytes); } @@ -162,7 +162,7 @@ void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes) PBYTE buf; log3("move %d %08x->%08x",bytes,ofsSource,ofsDest); - buf=(PBYTE)mir_alloc(bytes); + buf = (PBYTE)mir_alloc(bytes); SetFilePointer(hDbFile,ofsSource,NULL,FILE_BEGIN); ReadFile(hDbFile,buf,bytes,&bytesRead,NULL); DBWrite(ofsDest,buf,bytes); @@ -183,35 +183,33 @@ void DBFlush(int setting) { if (!setting) { log0("nflush1"); - if(safetyMode) FlushFileBuffers(hDbFile); + if (safetyMode) FlushFileBuffers(hDbFile); log0("nflush2"); return; } KillTimer(NULL,flushBuffersTimerId); - flushBuffersTimerId=SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc); + flushBuffersTimerId = SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc); } static INT_PTR CacheSetSafetyMode(WPARAM wParam,LPARAM lParam) { EnterCriticalSection(&csDbAccess); - safetyMode=wParam; + safetyMode = wParam; LeaveCriticalSection(&csDbAccess); - if(safetyMode) FlushFileBuffers(hDbFile); + if (safetyMode) FlushFileBuffers(hDbFile); return 0; } int InitCache(void) { - int i; - DWORD bytesRead; - - CreateServiceFunction(MS_DB_SETSAFETYMODE,CacheSetSafetyMode); - pDbCache=(PBYTE)mir_alloc(CACHESECTIONSIZE*CACHESECTIONCOUNT); - lastUseCounter=CACHESECTIONCOUNT; - for(i=0;i