diff --git a/manifest b/manifest index c09b213a2c..5dcbd753bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Continuing\swork\son\sadding\sfull\ssupport\sfor\sthe\sSQLITE_OMIT_WSD\r\ncompile-time\soption.\s(CVS\s5658) -D 2008-09-02T00:52:52 +C Modify\spcache.c\sto\swork\swith\sOMIT_WSD.\s(CVS\s5659) +D 2008-09-02T09:38:07 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -97,7 +97,7 @@ F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53 -F src/btree.c a12044e500d4cd8d030e6ce9d59855ada7008564 +F src/btree.c 3c251cac0dbf763020e43aa66afa4a79356c4482 F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107 F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576 F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe @@ -116,7 +116,7 @@ F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/loadext.c 6581a5bbc4d74fcd46dbbcfd695a6a5417f778a2 -F src/main.c 47ce9da041a5aa9a1adadd92be795bde887e2dc9 +F src/main.c 756541b024aeaedee0c803f33e06bf16aef19ab6 F src/malloc.c 2ffd62fb4a299cf3945e50a4c53d27ec1813f8b1 F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9 F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c @@ -138,7 +138,7 @@ F src/os_win.c 3209dc0ed734291764393ea8d534ba0d8696a540 F src/pager.c 032d11049af4ec49bdbaa3584e7ce9887098b66a F src/pager.h c45380ca9d0933ea5bc4ecb3a43958b6d2ec5a9c F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8 -F src/pcache.c 200de27e85b123840a30a11f5055544e06845569 +F src/pcache.c ff79cb5eb797d0f1a244b4332c2d39cb5cfd066b F src/pcache.h 53730c33310cdf7a5c94e8333c853d59a3b30226 F src/pragma.c 9d8127ac1527617cfb31392cd8832bb2c9a02115 F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510 @@ -630,7 +630,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P e0461f8755daa9f57e056810de9ea347ff8dd986 -R c8df4ae84b8bc405c32994ac1b521fda -U drh -Z 207cb363f97da2fc9bf5418da8660bf8 +P ef26ea5c46d3915d206f8ff7f82a24f4c8955f1f +R 7736deee443b4d2230f5bd18a13532e4 +U danielk1977 +Z eee1cf0558cd99e310064b03fee3f582 diff --git a/manifest.uuid b/manifest.uuid index 7c29d364c7..61c82c3a89 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef26ea5c46d3915d206f8ff7f82a24f4c8955f1f \ No newline at end of file +44def90d1bd4e37ab162e16f83e23d32e86b78ab \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 54cd3dc8a4..3dcd4c181f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.506 2008/09/02 00:52:52 drh Exp $ +** $Id: btree.c,v 1.507 2008/09/02 09:38:07 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -62,7 +62,7 @@ static SQLITE_WSD int sqlite3SharedCacheEnabled = 0; ** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2(). */ int sqlite3_enable_shared_cache(int enable){ - GLOBAL(int,sqlite3SharedCacheEnabled) = enable; + GLOBAL(int, sqlite3SharedCacheEnabled) = enable; return SQLITE_OK; } #endif diff --git a/src/main.c b/src/main.c index d473c0d488..664f4a313d 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.495 2008/09/01 18:34:20 danielk1977 Exp $ +** $Id: main.c,v 1.496 2008/09/02 09:38:07 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -160,8 +160,8 @@ int sqlite3_initialize(void){ rc = sqlite3_os_init(); if( rc==SQLITE_OK ){ rc = sqlite3PcacheInitialize(); - sqlite3PCacheBufferSetup(sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, - sqlite3GlobalConfig.nPage); + sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, + sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); } GLOBAL(int, inProgress) = 0; sqlite3GlobalConfig.isInit = (rc==SQLITE_OK ? 1 : 0); diff --git a/src/pcache.c b/src/pcache.c index 3a9bd493e2..ece7571651 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements that page cache. ** -** @(#) $Id: pcache.c,v 1.25 2008/09/01 18:34:20 danielk1977 Exp $ +** @(#) $Id: pcache.c,v 1.26 2008/09/02 09:38:07 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -68,7 +68,7 @@ struct PgFreeslot { /* ** Global data for the page cache. */ -static struct PCacheGlobal { +static SQLITE_WSD struct PCacheGlobal { int isInit; /* True when initialized */ sqlite3_mutex *mutex; /* static mutex MUTEX_STATIC_LRU */ @@ -83,6 +83,13 @@ static struct PCacheGlobal { PgFreeslot *pFree; /* Free page blocks */ } pcache = {0}; +/* +** All code in this file should access the global pcache structure via the +** alias "pcache_g". This ensures that the WSD emulation is used when +** compiling for systems that do not support real WSD. +*/ +#define pcache_g (GLOBAL(struct PCacheGlobal, pcache)) + /* ** All global variables used by this module (all of which are grouped ** together in global structure "pcache" above) are protected by the static @@ -99,9 +106,9 @@ static struct PCacheGlobal { ** entered more than once. The pcacheMutexHeld() macro should only be ** used within an assert() to verify that the mutex is being held. */ -#define pcacheEnterMutex() sqlite3_mutex_enter(pcache.mutex) -#define pcacheExitMutex() sqlite3_mutex_leave(pcache.mutex) -#define pcacheMutexHeld() sqlite3_mutex_held(pcache.mutex) +#define pcacheEnterMutex() sqlite3_mutex_enter(pcache_g.mutex) +#define pcacheExitMutex() sqlite3_mutex_leave(pcache_g.mutex) +#define pcacheMutexHeld() sqlite3_mutex_held(pcache_g.mutex) /* ** Some of the assert() macros in this code are too expensive to run @@ -317,22 +324,22 @@ static void pcacheAddToList(PgHdr **ppHead, PgHdr *pPage){ ** Remove a page from the global LRU list */ static void pcacheRemoveFromLruList(PgHdr *pPage){ - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); assert( (pPage->flags&PGHDR_DIRTY)==0 ); if( pPage->pCache->bPurgeable==0 ) return; if( pPage->pNextLru ){ - assert( pcache.pLruTail!=pPage ); + assert( pcache_g.pLruTail!=pPage ); pPage->pNextLru->pPrevLru = pPage->pPrevLru; }else{ - assert( pcache.pLruTail==pPage ); - pcache.pLruTail = pPage->pPrevLru; + assert( pcache_g.pLruTail==pPage ); + pcache_g.pLruTail = pPage->pPrevLru; } if( pPage->pPrevLru ){ - assert( pcache.pLruHead!=pPage ); + assert( pcache_g.pLruHead!=pPage ); pPage->pPrevLru->pNextLru = pPage->pNextLru; }else{ - assert( pcache.pLruHead==pPage ); - pcache.pLruHead = pPage->pNextLru; + assert( pcache_g.pLruHead==pPage ); + pcache_g.pLruHead = pPage->pNextLru; } } @@ -343,31 +350,31 @@ static void pcacheRemoveFromLruList(PgHdr *pPage){ ** to the end of the LRU list so that it will be the next to be recycled. */ static void pcacheAddToLruList(PgHdr *pPage){ - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); assert( (pPage->flags&PGHDR_DIRTY)==0 ); if( pPage->pCache->bPurgeable==0 ) return; - if( pcache.pLruTail && (pPage->flags & PGHDR_REUSE_UNLIKELY)!=0 ){ + if( pcache_g.pLruTail && (pPage->flags & PGHDR_REUSE_UNLIKELY)!=0 ){ /* If reuse is unlikely. Put the page at the end of the LRU list ** where it will be recycled sooner rather than later. */ - assert( pcache.pLruHead ); + assert( pcache_g.pLruHead ); pPage->pNextLru = 0; - pPage->pPrevLru = pcache.pLruTail; - pcache.pLruTail->pNextLru = pPage; - pcache.pLruTail = pPage; + pPage->pPrevLru = pcache_g.pLruTail; + pcache_g.pLruTail->pNextLru = pPage; + pcache_g.pLruTail = pPage; pPage->flags &= ~PGHDR_REUSE_UNLIKELY; }else{ /* If reuse is possible. the page goes at the beginning of the LRU ** list so that it will be the last to be recycled. */ - if( pcache.pLruHead ){ - pcache.pLruHead->pPrevLru = pPage; + if( pcache_g.pLruHead ){ + pcache_g.pLruHead->pPrevLru = pPage; } - pPage->pNextLru = pcache.pLruHead; - pcache.pLruHead = pPage; + pPage->pNextLru = pcache_g.pLruHead; + pcache_g.pLruHead = pPage; pPage->pPrevLru = 0; - if( pcache.pLruTail==0 ){ - pcache.pLruTail = pPage; + if( pcache_g.pLruTail==0 ){ + pcache_g.pLruTail = pPage; } } } @@ -382,16 +389,16 @@ static void pcacheAddToLruList(PgHdr *pPage){ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ PgFreeslot *p; sz &= ~7; - pcache.szSlot = sz; - pcache.pStart = pBuf; - pcache.pFree = 0; + pcache_g.szSlot = sz; + pcache_g.pStart = pBuf; + pcache_g.pFree = 0; while( n-- ){ p = (PgFreeslot*)pBuf; - p->pNext = pcache.pFree; - pcache.pFree = p; + p->pNext = pcache_g.pFree; + pcache_g.pFree = p; pBuf = (void*)&((char*)pBuf)[sz]; } - pcache.pEnd = pBuf; + pcache_g.pEnd = pBuf; } /* @@ -400,10 +407,10 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ ** in the page cache memory pool, go to the general purpose memory allocator. */ void *pcacheMalloc(int sz, PCache *pCache){ - assert( sqlite3_mutex_held(pcache.mutex) ); - if( sz<=pcache.szSlot && pcache.pFree ){ - PgFreeslot *p = pcache.pFree; - pcache.pFree = p->pNext; + assert( sqlite3_mutex_held(pcache_g.mutex) ); + if( sz<=pcache_g.szSlot && pcache_g.pFree ){ + PgFreeslot *p = pcache_g.pFree; + pcache_g.pFree = p->pNext; sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, sz); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1); return (void*)p; @@ -439,14 +446,14 @@ void *sqlite3PageMalloc(sz){ ** Release a pager memory allocation */ void pcacheFree(void *p){ - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); if( p==0 ) return; - if( p>=pcache.pStart && p=pcache_g.pStart && ppNext = pcache.pFree; - pcache.pFree = pSlot; + pSlot->pNext = pcache_g.pFree; + pcache_g.pFree = pSlot; }else{ int iSize = sqlite3MallocSize(p); sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize); @@ -465,14 +472,14 @@ void sqlite3PageFree(void *p){ static PgHdr *pcachePageAlloc(PCache *pCache){ PgHdr *p; int sz = sizeof(*p) + pCache->szPage + pCache->szExtra; - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); p = pcacheMalloc(sz, pCache); if( p==0 ) return 0; memset(p, 0, sizeof(PgHdr)); p->pData = (void*)&p[1]; p->pExtra = (void*)&((char*)p->pData)[pCache->szPage]; if( pCache->bPurgeable ){ - pcache.nCurrentPage++; + pcache_g.nCurrentPage++; } return p; } @@ -481,9 +488,9 @@ static PgHdr *pcachePageAlloc(PCache *pCache){ ** Deallocate a page */ static void pcachePageFree(PgHdr *p){ - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); if( p->pCache->bPurgeable ){ - pcache.nCurrentPage--; + pcache_g.nCurrentPage--; } pcacheFree(p->apSave[0]); pcacheFree(p->apSave[1]); @@ -496,8 +503,8 @@ static void pcachePageFree(PgHdr *p){ ** the argument is passed to pcachePageFree(). */ static int pcachePageSize(PgHdr *p){ - assert( sqlite3_mutex_held(pcache.mutex) ); - assert( !pcache.pStart ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); + assert( !pcache_g.pStart ); assert( p->apSave[0]==0 ); assert( p->apSave[1]==0 ); assert( p && p->pCache ); @@ -518,9 +525,9 @@ static int pcachePageSize(PgHdr *p){ */ static PgHdr *pcacheRecyclePage(){ PgHdr *p = 0; - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); - if( (p=pcache.pLruTail) ){ + if( (p=pcache_g.pLruTail) ){ assert( (p->flags&PGHDR_DIRTY)==0 ); pcacheRemoveFromLruList(p); pcacheRemoveFromHash(p); @@ -543,8 +550,8 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){ int szPage = pCache->szPage; int szExtra = pCache->szExtra; - assert( pcache.isInit ); - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( pcache_g.isInit ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); *ppPage = 0; @@ -556,7 +563,7 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){ expensive_assert( pcacheCheckSynced(pCache) ); if( pCache->xStress && pCache->pDirty - && pCache->nPinned>=(pcache.nMaxPage+pCache->nMin-pcache.nMinPage) + && pCache->nPinned>=(pcache_g.nMaxPage+pCache->nMin-pcache_g.nMinPage) ){ PgHdr *pPg; assert(pCache->pDirtyTail); @@ -580,7 +587,7 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){ } /* If the global page limit has been reached, try to recycle a page. */ - if( pCache->bPurgeable && pcache.nCurrentPage>=pcache.nMaxPage ){ + if( pCache->bPurgeable && pcache_g.nCurrentPage>=pcache_g.nMaxPage ){ p = pcacheRecyclePage(); } @@ -604,19 +611,19 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){ ** functions are threadsafe. */ int sqlite3PcacheInitialize(void){ - assert( pcache.isInit==0 ); - memset(&pcache, 0, sizeof(pcache)); + assert( pcache_g.isInit==0 ); + memset(&pcache_g, 0, sizeof(pcache)); if( sqlite3GlobalConfig.bCoreMutex ){ /* No need to check the return value of sqlite3_mutex_alloc(). ** Allocating a static mutex cannot fail. */ - pcache.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU); + pcache_g.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU); } - pcache.isInit = 1; + pcache_g.isInit = 1; return SQLITE_OK; } void sqlite3PcacheShutdown(void){ - memset(&pcache, 0, sizeof(pcache)); + memset(&pcache_g, 0, sizeof(pcache)); } /* @@ -637,7 +644,7 @@ void sqlite3PcacheOpen( void *pStress, /* Argument to xStress */ PCache *p /* Preallocated space for the PCache */ ){ - assert( pcache.isInit ); + assert( pcache_g.isInit ); memset(p, 0, sizeof(PCache)); p->szPage = szPage; p->szExtra = szExtra; @@ -650,8 +657,8 @@ void sqlite3PcacheOpen( pcacheEnterMutex(); if( bPurgeable ){ - pcache.nMaxPage += p->nMax; - pcache.nMinPage += p->nMin; + pcache_g.nMaxPage += p->nMax; + pcache_g.nMinPage += p->nMin; } pcacheExitMutex(); @@ -678,7 +685,7 @@ int sqlite3PcacheFetch( int rc = SQLITE_OK; PgHdr *pPage = 0; - assert( pcache.isInit ); + assert( pcache_g.isInit ); assert( pCache!=0 ); assert( pgno>0 ); expensive_assert( pCache->nPinned==pcachePinnedCount(pCache) ); @@ -748,7 +755,7 @@ void sqlite3PcacheRelease(PgHdr *p){ if( (p->flags&PGHDR_DIRTY)==0 ){ pCache->nPinned--; pcacheEnterMutex(); - if( pcache.nCurrentPage>pcache.nMaxPage ){ + if( pcache_g.nCurrentPage>pcache_g.nMaxPage ){ pcacheRemoveFromList(&pCache->pClean, p); pcacheRemoveFromHash(p); pcachePageFree(p); @@ -882,7 +889,7 @@ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){ */ void pcacheClear(PCache *pCache){ PgHdr *p, *pNext; - assert( sqlite3_mutex_held(pcache.mutex) ); + assert( sqlite3_mutex_held(pcache_g.mutex) ); for(p=pCache->pClean; p; p=pNext){ pNext = p->pNext; pcacheRemoveFromLruList(p); @@ -942,8 +949,8 @@ void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){ */ static void pcacheEnforceMaxPage(){ PgHdr *p; - assert( sqlite3_mutex_held(pcache.mutex) ); - while( pcache.nCurrentPage>pcache.nMaxPage && (p = pcacheRecyclePage()) ){ + assert( sqlite3_mutex_held(pcache_g.mutex) ); + while( pcache_g.nCurrentPage>pcache_g.nMaxPage && (p = pcacheRecyclePage()) ){ pcachePageFree(p); } } @@ -957,8 +964,8 @@ void sqlite3PcacheClose(PCache *pCache){ /* Free all the pages used by this pager and remove them from the LRU list. */ pcacheClear(pCache); if( pCache->bPurgeable ){ - pcache.nMaxPage -= pCache->nMax; - pcache.nMinPage -= pCache->nMin; + pcache_g.nMaxPage -= pCache->nMax; + pcache_g.nMinPage -= pCache->nMin; pcacheEnforceMaxPage(); } sqlite3_free(pCache->apHash); @@ -1208,8 +1215,8 @@ void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){ } if( pCache->bPurgeable ){ pcacheEnterMutex(); - pcache.nMaxPage -= pCache->nMax; - pcache.nMaxPage += mxPage; + pcache_g.nMaxPage -= pCache->nMax; + pcache_g.nMaxPage += mxPage; pcacheEnforceMaxPage(); pcacheExitMutex(); } @@ -1228,7 +1235,7 @@ void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){ */ int sqlite3PcacheReleaseMemory(int nReq){ int nFree = 0; - if( pcache.pStart==0 ){ + if( pcache_g.pStart==0 ){ PgHdr *p; pcacheEnterMutex(); while( (nReq<0 || nFreepNextLru){ + for(p=pcache_g.pLruHead; p; p=p->pNextLru){ nRecyclable++; } - *pnCurrent = pcache.nCurrentPage; - *pnMax = pcache.nMaxPage; - *pnMin = pcache.nMinPage; + *pnCurrent = pcache_g.nCurrentPage; + *pnMax = pcache_g.nMaxPage; + *pnMin = pcache_g.nMinPage; *pnRecyclable = nRecyclable; } #endif