-C Modify\sthe\slemon\sparser\stemplate\sto\savoid\susing\szero-initialized\sconstants\nwhen\scompiled\swith\sC++.\s\sTicket\s#3288.\s(CVS\s5571)
-D 2008-08-20T17:48:21
+C Comment\sand\sfunction\snaming\stweaks\sto\spcache.\s\sNo\sfunctionality\schanges.\s(CVS\s5572)
+D 2008-08-20T21:47:46
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 0b1c022000f55221454a7846022f11674d8024bf
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/os_os2.c 676ed273b17bd260f905df81375c9f9950d85517
F src/os_unix.c fe0dbc35bcd3de49e46b132abfc0f45d6dd6a864
F src/os_win.c aefe9ee26430678a19a058a874e4e2bd91398142
-F src/pager.c 9f813a8f26680ff510335e2bbd01910b2a77277b
+F src/pager.c 79d4d33245462c054a7e815e29ec6500c667ef26
F src/pager.h fb9376af5ba8e1eb78ee3b4f15eb0f60658ffd65
F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8
-F src/pcache.c c1a9abb5e2aa3d1d52a2995c8e0a36535d4d1bc2
+F src/pcache.c cf7a7c81366e42330ff9c84d1f3591c905289c3d
F src/pcache.h 71ade7a84ed87d9d20507315260b1d91808d7c9a
F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d
F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P aef5b909e960c31527c795bc09a1de846f8afcbb
-R ba6058aa52b7f536a969626105129ff5
+P 71992f4a3723418df5f16093aec92f1f95f0b604
+R 1864568c91564440b5d8de8411bca79f
U drh
-Z a81a89f6460671859f4d4500f7e3aaad
+Z 8ae3b66a71a20677fcd2b2a4e9762a73
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.470 2008/08/20 14:49:24 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.471 2008/08/20 21:47:46 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#define pager_datahash(X,Y) 0
#define pager_pagehash(X) 0
#define CHECK_PAGE(x)
-#endif
+#endif /* SQLITE_CHECK_PAGES */
/*
** When this is called the journal file for pager pPager must be open.
return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc);
}
nExtra = FORCE_ALIGNMENT(nExtra);
- sqlite3PcacheOpen(szPageDflt, nExtra, !memDb, xDesc, !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
+ sqlite3PcacheOpen(szPageDflt, nExtra, !memDb, xDesc,
+ !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename);
IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
*************************************************************************
** This file implements that page cache.
**
-** @(#) $Id: pcache.c,v 1.1 2008/08/20 14:49:25 danielk1977 Exp $
+** @(#) $Id: pcache.c,v 1.2 2008/08/20 21:47:46 drh Exp $
*/
#include "sqliteInt.h"
PCache *pAll; /* list of all page caches */
int nPage; /* Number of pages */
int nPurgeable; /* Number of pages in purgable caches */
- int mxPage; /* Globally configured page maximum */
+ int mxPage; /* Globally configured page maximum */
int mxPagePurgeable; /* Purgeable page maximum */
PgHdr *pLruHead, *pLruTail; /* Global LRU list of unused pages */
int szSlot; /* Size of each free slot */
** mutex released (in that order) before making the call.
*/
-#define enterPcacheGlobal() sqlite3_mutex_enter(pcache.mutex_lru)
-#define exitPcacheGlobal() sqlite3_mutex_leave(pcache.mutex_lru)
+#define pcacheEnterGlobal() sqlite3_mutex_enter(pcache.mutex_lru)
+#define pcacheExitGlobal() sqlite3_mutex_leave(pcache.mutex_lru)
/*
** Increment the reference count on both page p and its cache by n.
*/
-static void page_ref(PgHdr *p, int n){
+static void pcacheRef(PgHdr *p, int n){
/* This next block assert()s that the number of references to the
** PCache is the sum of the number of references to all pages in
** the PCache. This is a bit expensive to leave turned on all the
/********************************** Linked List Management ********************/
-static int check_hash_count(PCache *pCache){
+#ifndef NDEBUG
+/*
+** This routine verifies that the number of entries in the hash table
+** is pCache->nPage. This routine is used within assert() statements
+** only and is therefore disabled during production builds.
+*/
+static int pcacheCheckHashCount(PCache *pCache){
int i;
int nPage = 0;
for(i=0; i<pCache->nHash; i++){
assert( nPage==pCache->nPage );
return 1;
}
+#endif
/*
** Remove a page from its hash table (PCache.apHash[]).
pPage->pNextHash->pPrevHash = pPage->pPrevHash;
}
pPage->pCache->nPage--;
- assert( check_hash_count(pPage->pCache) );
+ assert( pcacheCheckHashCount(pPage->pCache) );
}
/*
}
pCache->apHash[h] = pPage;
pCache->nPage++;
- assert( check_hash_count(pCache) );
+ assert( pcacheCheckHashCount(pCache) );
}
/*
-** Resize the hash table to nHash buckets.
+** Attempt to increase the size the hash table to contain
+** at least nHash buckets.
*/
static int pcacheResizeHash(PCache *pCache, int nHash){
#ifdef SQLITE_MALLOC_SOFT_LIMIT
- if( nHash*sizeof(PgHdr *)>SQLITE_MALLOC_SOFT_LIMIT ){
+ if( nHash*sizeof(PgHdr*)>SQLITE_MALLOC_SOFT_LIMIT ){
nHash = SQLITE_MALLOC_SOFT_LIMIT/sizeof(PgHdr *);
}
#endif
if( nHash>pCache->nHash ){
PgHdr *p;
- PgHdr **pNew = (PgHdr **)sqlite3_malloc(sizeof(PgHdr *)*nHash);
+ PgHdr **pNew = (PgHdr **)sqlite3_malloc(sizeof(PgHdr*)*nHash);
if( !pNew ){
return SQLITE_NOMEM;
}
}
void *sqlite3PageMalloc(sz){
void *p;
- enterPcacheGlobal();
+ pcacheEnterGlobal();
p = pcacheMalloc(sz);
- exitPcacheGlobal();
+ pcacheExitGlobal();
return p;
}
}
}
void sqlite3PageFree(void *p){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheFree(p);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/*
assert( pcache.isInit );
assert( sqlite3_mutex_notheld(pcache.mutex_lru) );
- enterPcacheGlobal();
+ pcacheEnterGlobal();
if( (pcache.mxPage && pcache.nPage>=pcache.mxPage)
|| (!pcache.mxPage && bPurg && pcache.nPurgeable>=pcache.mxPagePurgeable)
assert( pCsr->iInUseMM==0 );
pCsr->iInUseMM = 1;
if( pCsr->xStress && (pCsr->iInUseDB==0 || pCache==pCsr) ){
- exitPcacheGlobal();
+ pcacheExitGlobal();
pCsr->xStress(pCsr->pStress);
- enterPcacheGlobal();
+ pcacheEnterGlobal();
}
pCsr->iInUseMM = 0;
}
p = pcachePageAlloc(szPage, szExtra, bPurg);
}
- exitPcacheGlobal();
+ pcacheExitGlobal();
return p;
}
p->nMax = 100;
if( bPurgeable ){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcache.mxPagePurgeable += p->nMax;
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/* Add the new pager-cache to the list of caches starting at pcache.pAll */
sqlite3_mutex_leave(pcache.mutex_mem2);
}
+/*
+** Change the page size for PCache object. This can only happen
+** when the cache is empty.
+*/
void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
assert(pCache->nPage==0);
pCache->szPage = szPage;
for(pPage=pCache->apHash[h]; pPage; pPage=pPage->pNextHash){
if( pPage->pgno==pgno ){
if( pPage->nRef==0 && (pPage->flags & PGHDR_DIRTY)==0 ){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheRemoveFromLruList(pPage);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
- page_ref(pPage, 1);
+ pcacheRef(pPage, 1);
*ppPage = pPage;
return SQLITE_OK;
}
pPage->nRef = 0;
pPage->pgno = pgno;
pPage->pCache = pCache;
- page_ref(pPage, 1);
+ pcacheRef(pPage, 1);
pcacheAddToList(&pCache->pClean, pPage);
pcacheAddToHash(pPage);
}else{
void sqlite3PcacheRelease(PgHdr *p){
assert( p->nRef>0 );
assert( p->pCache->iInUseDB || p->pCache->iInUseMM );
- page_ref(p, -1);
+ pcacheRef(p, -1);
if( p->nRef!=0 ) return;
if( p->pCache->xDestroy ){
p->pCache->xDestroy(p);
}
if( (p->flags & PGHDR_DIRTY)!=0 ) return;
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheAddToLruList(p);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
void sqlite3PcacheRef(PgHdr *p){
assert(p->nRef>=0);
- page_ref(p, 1);
+ pcacheRef(p, 1);
}
/*
pcacheRemoveFromList(&pCache->pClean, p);
}
pcacheRemoveFromHash(p);
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcachePageFree(p);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/*
pcacheAddToList(&pCache->pClean, p);
p->flags &= ~PGHDR_DIRTY;
if( p->nRef==0 ){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheAddToLruList(p);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
}
pcacheAddToList(&pCache->pClean, p);
p->flags &= ~PGHDR_DIRTY;
if( p->nRef==0 ){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheAddToLruList(p);
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
}
}
p->pgno = newPgno;
if( newPgno==0 ){
p->flags |= PGHDR_REUSE_UNLIKELY;
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheFree(p->apSave[0]);
pcacheFree(p->apSave[1]);
- exitPcacheGlobal();
+ pcacheExitGlobal();
p->apSave[0] = 0;
p->apSave[1] = 0;
sqlite3PcacheMakeClean(p);
** Set the global maximum number of pages. Return the previous value.
*/
void sqlite3PcacheGlobalMax(int mx){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcache.mxPage = mx;
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/*
PgHdr *p, *pNext;
PgHdr *pDirty = pCache->pDirty;
assert( pCache->iInUseDB );
- enterPcacheGlobal();
+ pcacheEnterGlobal();
for(p=pCache->pClean; p||pDirty; p=pNext){
if( !p ){
p = pDirty;
}
}
}
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/* Free all the pages used by this pager and remove them from the LRU
** list. This requires the protection of the MUTEX_STATIC_LRU mutex.
*/
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheClear(pCache);
if( pCache->bPurgeable ){
pcache.mxPagePurgeable -= pCache->nMax;
}
sqlite3_free(pCache->apHash);
- exitPcacheGlobal();
+ pcacheExitGlobal();
/* Now remove the pager-cache structure itself from the list of
** all such structures headed by pcache.pAll. This required the
void sqlite3PcacheCommit(PCache *pCache, int idJournal){
PgHdr *p;
assert( pCache->iInUseDB );
- enterPcacheGlobal(); /* Mutex is required to call pcacheFree() */
+ pcacheEnterGlobal(); /* Mutex is required to call pcacheFree() */
for(p=pCache->pDirty; p; p=p->pNext){
if( p->apSave[idJournal] ){
pcacheFree(p->apSave[idJournal]);
p->apSave[idJournal] = 0;
}
}
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/*
PgHdr *p;
int sz;
assert( pCache->iInUseDB );
- enterPcacheGlobal(); /* Mutex is required to call pcacheFree() */
+ pcacheEnterGlobal(); /* Mutex is required to call pcacheFree() */
sz = pCache->szPage;
for(p=pCache->pDirty; p; p=p->pNext){
if( p->apSave[idJournal] ){
p->apSave[idJournal] = 0;
}
}
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
/*
int sqlite3PcacheClear(PCache *pCache){
assert( pCache->iInUseDB );
assert(pCache->nRef==0);
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcacheClear(pCache);
- exitPcacheGlobal();
+ pcacheExitGlobal();
return SQLITE_OK;
}
mxPage = 10;
}
if( pCache->bPurgeable ){
- enterPcacheGlobal();
+ pcacheEnterGlobal();
pcache.mxPagePurgeable -= pCache->nMax;
pcache.mxPagePurgeable += mxPage;
- exitPcacheGlobal();
+ pcacheExitGlobal();
}
pCache->nMax = mxPage;
}
pCache->iInUseDB--;
assert( pCache->iInUseDB>=0 );
}
-