/ Check-in [44def90d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modify pcache.c to work with OMIT_WSD. (CVS 5659)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:44def90d1bd4e37ab162e16f83e23d32e86b78ab
User & Date: danielk1977 2008-09-02 09:38:07
Context
2008-09-02
10:22
Change some more global variables to work with OMIT_WSD. (CVS 5660) check-in: 46acaf58 user: danielk1977 tags: trunk
09:38
Modify pcache.c to work with OMIT_WSD. (CVS 5659) check-in: 44def90d user: danielk1977 tags: trunk
00:52
Continuing work on adding full support for the SQLITE_OMIT_WSD compile-time option. (CVS 5658) check-in: ef26ea5c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.506 2008/09/02 00:52:52 drh Exp $
           12  +** $Id: btree.c,v 1.507 2008/09/02 09:38:07 danielk1977 Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
    58     58   ** Enable or disable the shared pager and schema features.
    59     59   **
    60     60   ** This routine has no effect on existing database connections.
    61     61   ** The shared cache setting effects only future calls to
    62     62   ** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2().
    63     63   */
    64     64   int sqlite3_enable_shared_cache(int enable){
    65         -  GLOBAL(int,sqlite3SharedCacheEnabled) = enable;
           65  +  GLOBAL(int, sqlite3SharedCacheEnabled) = enable;
    66     66     return SQLITE_OK;
    67     67   }
    68     68   #endif
    69     69   
    70     70   
    71     71   /*
    72     72   ** Forward declaration

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.495 2008/09/01 18:34:20 danielk1977 Exp $
           17  +** $Id: main.c,v 1.496 2008/09/02 09:38:07 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   #ifdef SQLITE_ENABLE_FTS3
    23     23   # include "fts3.h"
    24     24   #endif
................................................................................
   156    156       FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
   157    157       GLOBAL(int, inProgress) = 1;
   158    158       memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
   159    159       sqlite3RegisterGlobalFunctions();
   160    160       rc = sqlite3_os_init();
   161    161       if( rc==SQLITE_OK ){
   162    162         rc = sqlite3PcacheInitialize();
   163         -      sqlite3PCacheBufferSetup(sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, 
   164         -          sqlite3GlobalConfig.nPage);
          163  +      sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, 
          164  +          sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
   165    165       }
   166    166       GLOBAL(int, inProgress) = 0;
   167    167       sqlite3GlobalConfig.isInit = (rc==SQLITE_OK ? 1 : 0);
   168    168     }
   169    169     sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
   170    170   
   171    171     /* Go back under the static mutex and clean up the recursive

Changes to src/pcache.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file implements that page cache.
    13     13   **
    14         -** @(#) $Id: pcache.c,v 1.25 2008/09/01 18:34:20 danielk1977 Exp $
           14  +** @(#) $Id: pcache.c,v 1.26 2008/09/02 09:38:07 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** A complete page cache is an instance of this structure.
    20     20   **
    21     21   ** A cache may only be deleted by its owner and while holding the
................................................................................
    64     64   struct PgFreeslot {
    65     65     PgFreeslot *pNext;  /* Next free slot */
    66     66   };
    67     67   
    68     68   /*
    69     69   ** Global data for the page cache.
    70     70   */
    71         -static struct PCacheGlobal {
           71  +static SQLITE_WSD struct PCacheGlobal {
    72     72     int isInit;                         /* True when initialized */
    73     73     sqlite3_mutex *mutex;               /* static mutex MUTEX_STATIC_LRU */
    74     74   
    75     75     int nMaxPage;                       /* Sum of nMaxPage for purgeable caches */
    76     76     int nMinPage;                       /* Sum of nMinPage for purgeable caches */
    77     77     int nCurrentPage;                   /* Number of purgeable pages allocated */
    78     78     PgHdr *pLruHead, *pLruTail;         /* LRU list of unused clean pgs */
................................................................................
    79     79   
    80     80     /* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
    81     81     int szSlot;                         /* Size of each free slot */
    82     82     void *pStart, *pEnd;                /* Bounds of pagecache malloc range */
    83     83     PgFreeslot *pFree;                  /* Free page blocks */
    84     84   } pcache = {0};
    85     85   
           86  +/*
           87  +** All code in this file should access the global pcache structure via the
           88  +** alias "pcache_g". This ensures that the WSD emulation is used when
           89  +** compiling for systems that do not support real WSD.
           90  +*/
           91  +#define pcache_g (GLOBAL(struct PCacheGlobal, pcache))
           92  +
    86     93   /*
    87     94   ** All global variables used by this module (all of which are grouped 
    88     95   ** together in global structure "pcache" above) are protected by the static 
    89     96   ** SQLITE_MUTEX_STATIC_LRU mutex. A pointer to this mutex is stored in
    90     97   ** variable "pcache.mutex".
    91     98   **
    92     99   ** Some elements of the PCache and PgHdr structures are protected by the 
................................................................................
    95    102   ** marked.
    96    103   **
    97    104   ** Use the following macros must surround all access (read or write)
    98    105   ** of protected elements.  The mutex is not recursive and may not be
    99    106   ** entered more than once.  The pcacheMutexHeld() macro should only be
   100    107   ** used within an assert() to verify that the mutex is being held.
   101    108   */
   102         -#define pcacheEnterMutex() sqlite3_mutex_enter(pcache.mutex)
   103         -#define pcacheExitMutex()  sqlite3_mutex_leave(pcache.mutex)
   104         -#define pcacheMutexHeld()  sqlite3_mutex_held(pcache.mutex)
          109  +#define pcacheEnterMutex() sqlite3_mutex_enter(pcache_g.mutex)
          110  +#define pcacheExitMutex()  sqlite3_mutex_leave(pcache_g.mutex)
          111  +#define pcacheMutexHeld()  sqlite3_mutex_held(pcache_g.mutex)
   105    112   
   106    113   /*
   107    114   ** Some of the assert() macros in this code are too expensive to run
   108    115   ** even during normal debugging.  Use them only rarely on long-running
   109    116   ** tests.  Enable the expensive asserts using the
   110    117   ** -DSQLITE_ENABLE_EXPENSIVE_ASSERT=1 compile-time option.
   111    118   */
................................................................................
   313    320     }
   314    321   }
   315    322   
   316    323   /*
   317    324   ** Remove a page from the global LRU list
   318    325   */
   319    326   static void pcacheRemoveFromLruList(PgHdr *pPage){
   320         -  assert( sqlite3_mutex_held(pcache.mutex) );
          327  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   321    328     assert( (pPage->flags&PGHDR_DIRTY)==0 );
   322    329     if( pPage->pCache->bPurgeable==0 ) return;
   323    330     if( pPage->pNextLru ){
   324         -    assert( pcache.pLruTail!=pPage );
          331  +    assert( pcache_g.pLruTail!=pPage );
   325    332       pPage->pNextLru->pPrevLru = pPage->pPrevLru;
   326    333     }else{
   327         -    assert( pcache.pLruTail==pPage );
   328         -    pcache.pLruTail = pPage->pPrevLru;
          334  +    assert( pcache_g.pLruTail==pPage );
          335  +    pcache_g.pLruTail = pPage->pPrevLru;
   329    336     }
   330    337     if( pPage->pPrevLru ){
   331         -    assert( pcache.pLruHead!=pPage );
          338  +    assert( pcache_g.pLruHead!=pPage );
   332    339       pPage->pPrevLru->pNextLru = pPage->pNextLru;
   333    340     }else{
   334         -    assert( pcache.pLruHead==pPage );
   335         -    pcache.pLruHead = pPage->pNextLru;
          341  +    assert( pcache_g.pLruHead==pPage );
          342  +    pcache_g.pLruHead = pPage->pNextLru;
   336    343     }
   337    344   }
   338    345   
   339    346   /*
   340    347   ** Add a page to the global LRU list.  The page is normally added
   341    348   ** to the front of the list so that it will be the last page recycled.
   342    349   ** However, if the PGHDR_REUSE_UNLIKELY bit is set, the page is added
   343    350   ** to the end of the LRU list so that it will be the next to be recycled.
   344    351   */
   345    352   static void pcacheAddToLruList(PgHdr *pPage){
   346         -  assert( sqlite3_mutex_held(pcache.mutex) );
          353  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   347    354     assert( (pPage->flags&PGHDR_DIRTY)==0 );
   348    355     if( pPage->pCache->bPurgeable==0 ) return;
   349         -  if( pcache.pLruTail && (pPage->flags & PGHDR_REUSE_UNLIKELY)!=0 ){
          356  +  if( pcache_g.pLruTail && (pPage->flags & PGHDR_REUSE_UNLIKELY)!=0 ){
   350    357       /* If reuse is unlikely.  Put the page at the end of the LRU list
   351    358       ** where it will be recycled sooner rather than later. 
   352    359       */
   353         -    assert( pcache.pLruHead );
          360  +    assert( pcache_g.pLruHead );
   354    361       pPage->pNextLru = 0;
   355         -    pPage->pPrevLru = pcache.pLruTail;
   356         -    pcache.pLruTail->pNextLru = pPage;
   357         -    pcache.pLruTail = pPage;
          362  +    pPage->pPrevLru = pcache_g.pLruTail;
          363  +    pcache_g.pLruTail->pNextLru = pPage;
          364  +    pcache_g.pLruTail = pPage;
   358    365       pPage->flags &= ~PGHDR_REUSE_UNLIKELY;
   359    366     }else{
   360    367       /* If reuse is possible. the page goes at the beginning of the LRU
   361    368       ** list so that it will be the last to be recycled.
   362    369       */
   363         -    if( pcache.pLruHead ){
   364         -      pcache.pLruHead->pPrevLru = pPage;
          370  +    if( pcache_g.pLruHead ){
          371  +      pcache_g.pLruHead->pPrevLru = pPage;
   365    372       }
   366         -    pPage->pNextLru = pcache.pLruHead;
   367         -    pcache.pLruHead = pPage;
          373  +    pPage->pNextLru = pcache_g.pLruHead;
          374  +    pcache_g.pLruHead = pPage;
   368    375       pPage->pPrevLru = 0;
   369         -    if( pcache.pLruTail==0 ){
   370         -      pcache.pLruTail = pPage;
          376  +    if( pcache_g.pLruTail==0 ){
          377  +      pcache_g.pLruTail = pPage;
   371    378       }
   372    379     }
   373    380   }
   374    381   
   375    382   /*********************************************** Memory Allocation ***********
   376    383   **
   377    384   ** Initialize the page cache memory pool.
................................................................................
   378    385   **
   379    386   ** This must be called at start-time when no page cache lines are
   380    387   ** checked out. This function is not threadsafe.
   381    388   */
   382    389   void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
   383    390     PgFreeslot *p;
   384    391     sz &= ~7;
   385         -  pcache.szSlot = sz;
   386         -  pcache.pStart = pBuf;
   387         -  pcache.pFree = 0;
          392  +  pcache_g.szSlot = sz;
          393  +  pcache_g.pStart = pBuf;
          394  +  pcache_g.pFree = 0;
   388    395     while( n-- ){
   389    396       p = (PgFreeslot*)pBuf;
   390         -    p->pNext = pcache.pFree;
   391         -    pcache.pFree = p;
          397  +    p->pNext = pcache_g.pFree;
          398  +    pcache_g.pFree = p;
   392    399       pBuf = (void*)&((char*)pBuf)[sz];
   393    400     }
   394         -  pcache.pEnd = pBuf;
          401  +  pcache_g.pEnd = pBuf;
   395    402   }
   396    403   
   397    404   /*
   398    405   ** Allocate a page cache line.  Look in the page cache memory pool first
   399    406   ** and use an element from it first if available.  If nothing is available
   400    407   ** in the page cache memory pool, go to the general purpose memory allocator.
   401    408   */
   402    409   void *pcacheMalloc(int sz, PCache *pCache){
   403         -  assert( sqlite3_mutex_held(pcache.mutex) );
   404         -  if( sz<=pcache.szSlot && pcache.pFree ){
   405         -    PgFreeslot *p = pcache.pFree;
   406         -    pcache.pFree = p->pNext;
          410  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
          411  +  if( sz<=pcache_g.szSlot && pcache_g.pFree ){
          412  +    PgFreeslot *p = pcache_g.pFree;
          413  +    pcache_g.pFree = p->pNext;
   407    414       sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, sz);
   408    415       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
   409    416       return (void*)p;
   410    417     }else{
   411    418       void *p;
   412    419   
   413    420       /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
................................................................................
   435    442     return p;
   436    443   }
   437    444   
   438    445   /*
   439    446   ** Release a pager memory allocation
   440    447   */
   441    448   void pcacheFree(void *p){
   442         -  assert( sqlite3_mutex_held(pcache.mutex) );
          449  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   443    450     if( p==0 ) return;
   444         -  if( p>=pcache.pStart && p<pcache.pEnd ){
          451  +  if( p>=pcache_g.pStart && p<pcache_g.pEnd ){
   445    452       PgFreeslot *pSlot;
   446    453       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
   447    454       pSlot = (PgFreeslot*)p;
   448         -    pSlot->pNext = pcache.pFree;
   449         -    pcache.pFree = pSlot;
          455  +    pSlot->pNext = pcache_g.pFree;
          456  +    pcache_g.pFree = pSlot;
   450    457     }else{
   451    458       int iSize = sqlite3MallocSize(p);
   452    459       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
   453    460       sqlite3_free(p);
   454    461     }
   455    462   }
   456    463   void sqlite3PageFree(void *p){
................................................................................
   461    468   
   462    469   /*
   463    470   ** Allocate a new page.
   464    471   */
   465    472   static PgHdr *pcachePageAlloc(PCache *pCache){
   466    473     PgHdr *p;
   467    474     int sz = sizeof(*p) + pCache->szPage + pCache->szExtra;
   468         -  assert( sqlite3_mutex_held(pcache.mutex) );
          475  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   469    476     p = pcacheMalloc(sz, pCache);
   470    477     if( p==0 ) return 0;
   471    478     memset(p, 0, sizeof(PgHdr));
   472    479     p->pData = (void*)&p[1];
   473    480     p->pExtra = (void*)&((char*)p->pData)[pCache->szPage];
   474    481     if( pCache->bPurgeable ){
   475         -    pcache.nCurrentPage++;
          482  +    pcache_g.nCurrentPage++;
   476    483     }
   477    484     return p;
   478    485   }
   479    486   
   480    487   /*
   481    488   ** Deallocate a page
   482    489   */
   483    490   static void pcachePageFree(PgHdr *p){
   484         -  assert( sqlite3_mutex_held(pcache.mutex) );
          491  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   485    492     if( p->pCache->bPurgeable ){
   486         -    pcache.nCurrentPage--;
          493  +    pcache_g.nCurrentPage--;
   487    494     }
   488    495     pcacheFree(p->apSave[0]);
   489    496     pcacheFree(p->apSave[1]);
   490    497     pcacheFree(p);
   491    498   }
   492    499   
   493    500   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   494    501   /*
   495    502   ** Return the number of bytes that will be returned to the heap when
   496    503   ** the argument is passed to pcachePageFree().
   497    504   */
   498    505   static int pcachePageSize(PgHdr *p){
   499         -  assert( sqlite3_mutex_held(pcache.mutex) );
   500         -  assert( !pcache.pStart );
          506  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
          507  +  assert( !pcache_g.pStart );
   501    508     assert( p->apSave[0]==0 );
   502    509     assert( p->apSave[1]==0 );
   503    510     assert( p && p->pCache );
   504    511     return sqlite3MallocSize(p);
   505    512   }
   506    513   #endif
   507    514   
................................................................................
   514    521   ** There should be no other references to the page.
   515    522   **
   516    523   ** A pointer to the recycled page is returned, or NULL if no page is
   517    524   ** eligible for recycling.
   518    525   */
   519    526   static PgHdr *pcacheRecyclePage(){
   520    527     PgHdr *p = 0;
   521         -  assert( sqlite3_mutex_held(pcache.mutex) );
          528  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   522    529   
   523         -  if( (p=pcache.pLruTail) ){
          530  +  if( (p=pcache_g.pLruTail) ){
   524    531       assert( (p->flags&PGHDR_DIRTY)==0 );
   525    532       pcacheRemoveFromLruList(p);
   526    533       pcacheRemoveFromHash(p);
   527    534       pcacheRemoveFromList(&p->pCache->pClean, p);
   528    535     }
   529    536   
   530    537     return p;
................................................................................
   539    546   */
   540    547   static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){
   541    548     PgHdr *p = 0;
   542    549   
   543    550     int szPage = pCache->szPage;
   544    551     int szExtra = pCache->szExtra;
   545    552   
   546         -  assert( pcache.isInit );
   547         -  assert( sqlite3_mutex_held(pcache.mutex) );
          553  +  assert( pcache_g.isInit );
          554  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   548    555   
   549    556     *ppPage = 0;
   550    557   
   551    558     /* If we have reached the limit for pinned/dirty pages, and there is at
   552    559     ** least one dirty page, invoke the xStress callback to cause a page to
   553    560     ** become clean.
   554    561     */
   555    562     expensive_assert( pCache->nPinned==pcachePinnedCount(pCache) );
   556    563     expensive_assert( pcacheCheckSynced(pCache) );
   557    564     if( pCache->xStress
   558    565      && pCache->pDirty
   559         -   && pCache->nPinned>=(pcache.nMaxPage+pCache->nMin-pcache.nMinPage)
          566  +   && pCache->nPinned>=(pcache_g.nMaxPage+pCache->nMin-pcache_g.nMinPage)
   560    567     ){
   561    568       PgHdr *pPg;
   562    569       assert(pCache->pDirtyTail);
   563    570   
   564    571       for(pPg=pCache->pSynced; 
   565    572           pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); 
   566    573           pPg=pPg->pPrev
................................................................................
   576    583         if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
   577    584           return rc;
   578    585         }
   579    586       }
   580    587     }
   581    588   
   582    589     /* If the global page limit has been reached, try to recycle a page. */
   583         -  if( pCache->bPurgeable && pcache.nCurrentPage>=pcache.nMaxPage ){
          590  +  if( pCache->bPurgeable && pcache_g.nCurrentPage>=pcache_g.nMaxPage ){
   584    591       p = pcacheRecyclePage();
   585    592     }
   586    593   
   587    594     /* If a page has been recycled but it is the wrong size, free it. */
   588    595     if( p && (p->pCache->szPage!=szPage || p->pCache->szPage!=szExtra) ){
   589    596       pcachePageFree(p);
   590    597       p = 0;
................................................................................
   600    607   
   601    608   /*************************************************** General Interfaces ******
   602    609   **
   603    610   ** Initialize and shutdown the page cache subsystem. Neither of these 
   604    611   ** functions are threadsafe.
   605    612   */
   606    613   int sqlite3PcacheInitialize(void){
   607         -  assert( pcache.isInit==0 );
   608         -  memset(&pcache, 0, sizeof(pcache));
          614  +  assert( pcache_g.isInit==0 );
          615  +  memset(&pcache_g, 0, sizeof(pcache));
   609    616     if( sqlite3GlobalConfig.bCoreMutex ){
   610    617       /* No need to check the return value of sqlite3_mutex_alloc(). 
   611    618       ** Allocating a static mutex cannot fail.
   612    619       */
   613         -    pcache.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
          620  +    pcache_g.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
   614    621     }
   615         -  pcache.isInit = 1;
          622  +  pcache_g.isInit = 1;
   616    623     return SQLITE_OK;
   617    624   }
   618    625   void sqlite3PcacheShutdown(void){
   619         -  memset(&pcache, 0, sizeof(pcache));
          626  +  memset(&pcache_g, 0, sizeof(pcache));
   620    627   }
   621    628   
   622    629   /*
   623    630   ** Return the size in bytes of a PCache object.
   624    631   */
   625    632   int sqlite3PcacheSize(void){ return sizeof(PCache); }
   626    633   
................................................................................
   633    640     int szExtra,                 /* Extra space associated with each page */
   634    641     int bPurgeable,              /* True if pages are on backing store */
   635    642     void (*xDestroy)(PgHdr*),    /* Called to destroy a page */
   636    643     int (*xStress)(void*,PgHdr*),/* Call to try to make pages clean */
   637    644     void *pStress,               /* Argument to xStress */
   638    645     PCache *p                    /* Preallocated space for the PCache */
   639    646   ){
   640         -  assert( pcache.isInit );
          647  +  assert( pcache_g.isInit );
   641    648     memset(p, 0, sizeof(PCache));
   642    649     p->szPage = szPage;
   643    650     p->szExtra = szExtra;
   644    651     p->bPurgeable = bPurgeable;
   645    652     p->xDestroy = xDestroy;
   646    653     p->xStress = xStress;
   647    654     p->pStress = pStress;
   648    655     p->nMax = 100;
   649    656     p->nMin = 10;
   650    657   
   651    658     pcacheEnterMutex();
   652    659     if( bPurgeable ){
   653         -    pcache.nMaxPage += p->nMax;
   654         -    pcache.nMinPage += p->nMin;
          660  +    pcache_g.nMaxPage += p->nMax;
          661  +    pcache_g.nMinPage += p->nMin;
   655    662     }
   656    663   
   657    664     pcacheExitMutex();
   658    665   }
   659    666   
   660    667   /*
   661    668   ** Change the page size for PCache object.  This can only happen
................................................................................
   674    681     Pgno pgno,            /* Page number to obtain */
   675    682     int createFlag,       /* If true, create page if it does not exist already */
   676    683     PgHdr **ppPage        /* Write the page here */
   677    684   ){
   678    685     int rc = SQLITE_OK;
   679    686     PgHdr *pPage = 0;
   680    687   
   681         -  assert( pcache.isInit );
          688  +  assert( pcache_g.isInit );
   682    689     assert( pCache!=0 );
   683    690     assert( pgno>0 );
   684    691     expensive_assert( pCache->nPinned==pcachePinnedCount(pCache) );
   685    692   
   686    693     pcacheEnterMutex();
   687    694   
   688    695     /* Search the hash table for the requested page. Exit early if it is found. */
................................................................................
   744    751       if( p->pCache->xDestroy ){
   745    752         p->pCache->xDestroy(p);
   746    753       }
   747    754       pCache->nRef--;
   748    755       if( (p->flags&PGHDR_DIRTY)==0 ){
   749    756         pCache->nPinned--;
   750    757         pcacheEnterMutex();
   751         -      if( pcache.nCurrentPage>pcache.nMaxPage ){
          758  +      if( pcache_g.nCurrentPage>pcache_g.nMaxPage ){
   752    759           pcacheRemoveFromList(&pCache->pClean, p);
   753    760           pcacheRemoveFromHash(p);
   754    761           pcachePageFree(p);
   755    762         }else{
   756    763           pcacheAddToLruList(p);
   757    764         }
   758    765         pcacheExitMutex();
................................................................................
   878    885   }
   879    886   
   880    887   /*
   881    888   ** Remove all content from a page cache
   882    889   */
   883    890   void pcacheClear(PCache *pCache){
   884    891     PgHdr *p, *pNext;
   885         -  assert( sqlite3_mutex_held(pcache.mutex) );
          892  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
   886    893     for(p=pCache->pClean; p; p=pNext){
   887    894       pNext = p->pNext;
   888    895       pcacheRemoveFromLruList(p);
   889    896       pcachePageFree(p);
   890    897     }
   891    898     for(p=pCache->pDirty; p; p=pNext){
   892    899       pNext = p->pNext;
................................................................................
   938    945   
   939    946   /*
   940    947   ** If there are currently more than pcache.nMaxPage pages allocated, try
   941    948   ** to recycle pages to reduce the number allocated to pcache.nMaxPage.
   942    949   */
   943    950   static void pcacheEnforceMaxPage(){
   944    951     PgHdr *p;
   945         -  assert( sqlite3_mutex_held(pcache.mutex) );
   946         -  while( pcache.nCurrentPage>pcache.nMaxPage && (p = pcacheRecyclePage()) ){
          952  +  assert( sqlite3_mutex_held(pcache_g.mutex) );
          953  +  while( pcache_g.nCurrentPage>pcache_g.nMaxPage && (p = pcacheRecyclePage()) ){
   947    954       pcachePageFree(p);
   948    955     }
   949    956   }
   950    957   
   951    958   /*
   952    959   ** Close a cache.
   953    960   */
   954    961   void sqlite3PcacheClose(PCache *pCache){
   955    962     pcacheEnterMutex();
   956    963   
   957    964     /* Free all the pages used by this pager and remove them from the LRU list. */
   958    965     pcacheClear(pCache);
   959    966     if( pCache->bPurgeable ){
   960         -    pcache.nMaxPage -= pCache->nMax;
   961         -    pcache.nMinPage -= pCache->nMin;
          967  +    pcache_g.nMaxPage -= pCache->nMax;
          968  +    pcache_g.nMinPage -= pCache->nMin;
   962    969       pcacheEnforceMaxPage();
   963    970     }
   964    971     sqlite3_free(pCache->apHash);
   965    972     pcacheExitMutex();
   966    973   }
   967    974   
   968    975   /*
................................................................................
  1204   1211   */
  1205   1212   void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
  1206   1213     if( mxPage<10 ){
  1207   1214       mxPage = 10;
  1208   1215     }
  1209   1216     if( pCache->bPurgeable ){
  1210   1217       pcacheEnterMutex();
  1211         -    pcache.nMaxPage -= pCache->nMax;
  1212         -    pcache.nMaxPage += mxPage;
         1218  +    pcache_g.nMaxPage -= pCache->nMax;
         1219  +    pcache_g.nMaxPage += mxPage;
  1213   1220       pcacheEnforceMaxPage();
  1214   1221       pcacheExitMutex();
  1215   1222     }
  1216   1223     pCache->nMax = mxPage;
  1217   1224   }
  1218   1225   
  1219   1226   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
................................................................................
  1224   1231   **
  1225   1232   ** nReq is the number of bytes of memory required. Once this much has
  1226   1233   ** been released, the function returns. The return value is the total number 
  1227   1234   ** of bytes of memory released.
  1228   1235   */
  1229   1236   int sqlite3PcacheReleaseMemory(int nReq){
  1230   1237     int nFree = 0;
  1231         -  if( pcache.pStart==0 ){
         1238  +  if( pcache_g.pStart==0 ){
  1232   1239       PgHdr *p;
  1233   1240       pcacheEnterMutex();
  1234   1241       while( (nReq<0 || nFree<nReq) && (p=pcacheRecyclePage()) ){
  1235   1242         nFree += pcachePageSize(p);
  1236   1243         pcachePageFree(p);
  1237   1244       }
  1238   1245       pcacheExitMutex();
................................................................................
  1246   1253     int *pnCurrent,
  1247   1254     int *pnMax,
  1248   1255     int *pnMin,
  1249   1256     int *pnRecyclable
  1250   1257   ){
  1251   1258     PgHdr *p;
  1252   1259     int nRecyclable = 0;
  1253         -  for(p=pcache.pLruHead; p; p=p->pNextLru){
         1260  +  for(p=pcache_g.pLruHead; p; p=p->pNextLru){
  1254   1261       nRecyclable++;
  1255   1262     }
  1256   1263   
  1257         -  *pnCurrent = pcache.nCurrentPage;
  1258         -  *pnMax = pcache.nMaxPage;
  1259         -  *pnMin = pcache.nMinPage;
         1264  +  *pnCurrent = pcache_g.nCurrentPage;
         1265  +  *pnMax = pcache_g.nMaxPage;
         1266  +  *pnMin = pcache_g.nMinPage;
  1260   1267     *pnRecyclable = nRecyclable;
  1261   1268   }
  1262   1269   #endif
  1263   1270