/ Check-in [4b0e67d3]
Login

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

Overview
Comment:Comment and function naming tweaks to pcache. No functionality changes. (CVS 5572)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4b0e67d397236c740bea88ad3a5912abe896322a
User & Date: drh 2008-08-20 21:47:46
Context
2008-08-20
22:06
Modify the sqlite3VdbeUnpackRecord() interface to force the temporary space to be 8-byte aligned. This might be important for Sparc. Ticket #3318. (CVS 5573) check-in: 00b17798 user: drh tags: trunk
21:47
Comment and function naming tweaks to pcache. No functionality changes. (CVS 5572) check-in: 4b0e67d3 user: drh tags: trunk
17:48
Modify the lemon parser template to avoid using zero-initialized constants when compiled with C++. Ticket #3288. (CVS 5571) check-in: 71992f4a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.470 2008/08/20 14:49:24 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.471 2008/08/20 21:47:46 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
   486    486         || (pPg->flags&PGHDR_DIRTY) || pPg->pageHash==pager_pagehash(pPg) );
   487    487   }
   488    488   
   489    489   #else
   490    490   #define pager_datahash(X,Y)  0
   491    491   #define pager_pagehash(X)  0
   492    492   #define CHECK_PAGE(x)
   493         -#endif
          493  +#endif  /* SQLITE_CHECK_PAGES */
   494    494   
   495    495   /*
   496    496   ** When this is called the journal file for pager pPager must be open.
   497    497   ** The master journal file name is read from the end of the file and 
   498    498   ** written into memory supplied by the caller. 
   499    499   **
   500    500   ** zMaster must point to a buffer of at least nMaster bytes allocated by
................................................................................
  1864   1864     */
  1865   1865     if( !pPager || !pPager->pTmpSpace ){
  1866   1866       sqlite3OsClose(pPager->fd);
  1867   1867       sqlite3_free(pPager);
  1868   1868       return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc);
  1869   1869     }
  1870   1870     nExtra = FORCE_ALIGNMENT(nExtra);
  1871         -  sqlite3PcacheOpen(szPageDflt, nExtra, !memDb, xDesc, !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
         1871  +  sqlite3PcacheOpen(szPageDflt, nExtra, !memDb, xDesc, 
         1872  +                    !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
  1872   1873   
  1873   1874     PAGERTRACE3("OPEN %d %s\n", FILEHANDLEID(pPager->fd), pPager->zFilename);
  1874   1875     IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))
  1875   1876   
  1876   1877     /* Fill in Pager.zDirectory[] */
  1877   1878     memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
  1878   1879     for(i=strlen(pPager->zDirectory); i>0 && pPager->zDirectory[i-1]!='/'; i--){}

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.1 2008/08/20 14:49:25 danielk1977 Exp $
           14  +** @(#) $Id: pcache.c,v 1.2 2008/08/20 21:47:46 drh 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   struct PCache {
................................................................................
    61     61   static struct PCacheGlobal {
    62     62     int isInit;                         /* True when initialized */
    63     63     sqlite3_mutex *mutex_mem2;          /* static mutex MUTEX_STATIC_MEM2 */
    64     64     sqlite3_mutex *mutex_lru;           /* static mutex MUTEX_STATIC_LRU */
    65     65     PCache *pAll;                       /* list of all page caches */
    66     66     int nPage;                          /* Number of pages */
    67     67     int nPurgeable;                     /* Number of pages in purgable caches */
    68         -  int mxPage;                   /* Globally configured page maximum */
           68  +  int mxPage;                         /* Globally configured page maximum */
    69     69     int mxPagePurgeable;                /* Purgeable page maximum */
    70     70     PgHdr *pLruHead, *pLruTail;         /* Global LRU list of unused pages */
    71     71     int szSlot;                         /* Size of each free slot */
    72     72     void *pStart, *pEnd;                /* Bounds of pagecache malloc range */
    73     73     PgFreeslot *pFree;                  /* Free page blocks */
    74     74   } pcache = {0};
    75     75   
................................................................................
    95     95   ** underway.
    96     96   **
    97     97   ** Before the xStress callback of a pager-cache (PCache) is invoked, the
    98     98   ** SQLITE_MUTEX_STATIC_MEM2 mutex is obtained and the SQLITE_MUTEX_STATIC_LRU 
    99     99   ** mutex released (in that order) before making the call.
   100    100   */
   101    101   
   102         -#define enterPcacheGlobal() sqlite3_mutex_enter(pcache.mutex_lru)
   103         -#define exitPcacheGlobal()  sqlite3_mutex_leave(pcache.mutex_lru)
          102  +#define pcacheEnterGlobal() sqlite3_mutex_enter(pcache.mutex_lru)
          103  +#define pcacheExitGlobal()  sqlite3_mutex_leave(pcache.mutex_lru)
   104    104   
   105    105   /*
   106    106   ** Increment the reference count on both page p and its cache by n.
   107    107   */
   108         -static void page_ref(PgHdr *p, int n){
          108  +static void pcacheRef(PgHdr *p, int n){
   109    109     /* This next block assert()s that the number of references to the 
   110    110     ** PCache is the sum of the number of references to all pages in
   111    111     ** the PCache. This is a bit expensive to leave turned on all the 
   112    112     ** time, even in debugging builds.
   113    113     */
   114    114   #if 0
   115    115     PgHdr *pHdr;
................................................................................
   120    120   #endif
   121    121     p->nRef += n;
   122    122     p->pCache->nRef += n;
   123    123   }
   124    124   
   125    125   /********************************** Linked List Management ********************/
   126    126   
   127         -static int check_hash_count(PCache *pCache){
          127  +#ifndef NDEBUG
          128  +/*
          129  +** This routine verifies that the number of entries in the hash table
          130  +** is pCache->nPage.  This routine is used within assert() statements
          131  +** only and is therefore disabled during production builds.
          132  +*/
          133  +static int pcacheCheckHashCount(PCache *pCache){
   128    134     int i;
   129    135     int nPage = 0;
   130    136     for(i=0; i<pCache->nHash; i++){
   131    137       PgHdr *p;
   132    138       for(p=pCache->apHash[i]; p; p=p->pNextHash){
   133    139         nPage++;
   134    140       }
   135    141     }
   136    142     assert( nPage==pCache->nPage );
   137    143     return 1;
   138    144   }
          145  +#endif
   139    146   
   140    147   /*
   141    148   ** Remove a page from its hash table (PCache.apHash[]).
   142    149   */
   143    150   static void pcacheRemoveFromHash(PgHdr *pPage){
   144    151     if( pPage->pPrevHash ){
   145    152       pPage->pPrevHash->pNextHash = pPage->pNextHash;
................................................................................
   149    156       assert( pCache->apHash[h]==pPage );
   150    157       pCache->apHash[h] = pPage->pNextHash;
   151    158     }
   152    159     if( pPage->pNextHash ){
   153    160       pPage->pNextHash->pPrevHash = pPage->pPrevHash;
   154    161     }
   155    162     pPage->pCache->nPage--;
   156         -  assert( check_hash_count(pPage->pCache) );
          163  +  assert( pcacheCheckHashCount(pPage->pCache) );
   157    164   }
   158    165   
   159    166   /*
   160    167   ** Insert a page into the hash table
   161    168   */
   162    169   static void pcacheAddToHash(PgHdr *pPage){
   163    170     PCache *pCache = pPage->pCache;
................................................................................
   165    172     pPage->pNextHash = pCache->apHash[h];
   166    173     pPage->pPrevHash = 0;
   167    174     if( pCache->apHash[h] ){
   168    175       pCache->apHash[h]->pPrevHash = pPage;
   169    176     }
   170    177     pCache->apHash[h] = pPage;
   171    178     pCache->nPage++;
   172         -  assert( check_hash_count(pCache) );
          179  +  assert( pcacheCheckHashCount(pCache) );
   173    180   }
   174    181   
   175    182   /*
   176         -** Resize the hash table to nHash buckets.
          183  +** Attempt to increase the size the hash table to contain
          184  +** at least nHash buckets.
   177    185   */
   178    186   static int pcacheResizeHash(PCache *pCache, int nHash){
   179    187   #ifdef SQLITE_MALLOC_SOFT_LIMIT
   180         -  if( nHash*sizeof(PgHdr *)>SQLITE_MALLOC_SOFT_LIMIT ){
          188  +  if( nHash*sizeof(PgHdr*)>SQLITE_MALLOC_SOFT_LIMIT ){
   181    189       nHash = SQLITE_MALLOC_SOFT_LIMIT/sizeof(PgHdr *);
   182    190     }
   183    191   #endif
   184    192     if( nHash>pCache->nHash ){
   185    193       PgHdr *p;
   186         -    PgHdr **pNew = (PgHdr **)sqlite3_malloc(sizeof(PgHdr *)*nHash);
          194  +    PgHdr **pNew = (PgHdr **)sqlite3_malloc(sizeof(PgHdr*)*nHash);
   187    195       if( !pNew ){
   188    196         return SQLITE_NOMEM;
   189    197       }
   190    198       memset(pNew, 0, sizeof(PgHdr *)*nHash);
   191    199       sqlite3_free(pCache->apHash);
   192    200       pCache->apHash = pNew;
   193    201       pCache->nHash = nHash;
................................................................................
   329    337         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
   330    338       }
   331    339       return p;
   332    340     }
   333    341   }
   334    342   void *sqlite3PageMalloc(sz){
   335    343     void *p;
   336         -  enterPcacheGlobal();
          344  +  pcacheEnterGlobal();
   337    345     p = pcacheMalloc(sz);
   338         -  exitPcacheGlobal();
          346  +  pcacheExitGlobal();
   339    347     return p;
   340    348   }
   341    349   
   342    350   /*
   343    351   ** Release a pager memory allocation
   344    352   */
   345    353   void pcacheFree(void *p){
................................................................................
   354    362     }else{
   355    363       int iSize = sqlite3MallocSize(p);
   356    364       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
   357    365       sqlite3_free(p);
   358    366     }
   359    367   }
   360    368   void sqlite3PageFree(void *p){
   361         -  enterPcacheGlobal();
          369  +  pcacheEnterGlobal();
   362    370     pcacheFree(p);
   363         -  exitPcacheGlobal();
          371  +  pcacheExitGlobal();
   364    372   }
   365    373   
   366    374   /*
   367    375   ** Allocate a new page.
   368    376   */
   369    377   static PgHdr *pcachePageAlloc(int szPage, int szExtra, int bPurgeable){
   370    378     PgHdr *p;
................................................................................
   411    419     int szPage = pCache->szPage;
   412    420     int szExtra = pCache->szExtra;
   413    421     int bPurg = pCache->bPurgeable;
   414    422   
   415    423     assert( pcache.isInit );
   416    424     assert( sqlite3_mutex_notheld(pcache.mutex_lru) );
   417    425   
   418         -  enterPcacheGlobal();
          426  +  pcacheEnterGlobal();
   419    427   
   420    428     if( (pcache.mxPage && pcache.nPage>=pcache.mxPage) 
   421    429      || (!pcache.mxPage && bPurg && pcache.nPurgeable>=pcache.mxPagePurgeable)
   422    430     ){
   423    431       PCache *pCsr;
   424    432   
   425    433       /* If the above test succeeds, then a page will be obtained by recycling
................................................................................
   431    439         ** page that can be reused or until the xStress() callback of all
   432    440         ** caches has been invoked.
   433    441         */
   434    442         for(pCsr=pcache.pAll; pCsr&&!pcache.pLruTail; pCsr=pCsr->pNextAll){
   435    443           assert( pCsr->iInUseMM==0 );
   436    444           pCsr->iInUseMM = 1;
   437    445           if( pCsr->xStress && (pCsr->iInUseDB==0 || pCache==pCsr) ){
   438         -          exitPcacheGlobal();
          446  +          pcacheExitGlobal();
   439    447             pCsr->xStress(pCsr->pStress);
   440         -          enterPcacheGlobal();
          448  +          pcacheEnterGlobal();
   441    449           }
   442    450           pCsr->iInUseMM = 0;
   443    451         }
   444    452   
   445    453         sqlite3_mutex_leave(pcache.mutex_mem2);
   446    454       }
   447    455   
................................................................................
   468    476     }
   469    477   
   470    478     if( !p ){
   471    479       /* Allocate a new page object. */
   472    480       p = pcachePageAlloc(szPage, szExtra, bPurg);
   473    481     }
   474    482   
   475         -  exitPcacheGlobal();
          483  +  pcacheExitGlobal();
   476    484     return p;
   477    485   }
   478    486   
   479    487   /*************************************************** General Interfaces ******
   480    488   **
   481    489   ** Initialize and shutdown the page cache subsystem. Neither of these 
   482    490   ** functions are threadsafe.
................................................................................
   523    531     p->bPurgeable = bPurgeable;
   524    532     p->xDestroy = xDestroy;
   525    533     p->xStress = xStress;
   526    534     p->pStress = pStress;
   527    535     p->nMax = 100;
   528    536   
   529    537     if( bPurgeable ){
   530         -    enterPcacheGlobal();
          538  +    pcacheEnterGlobal();
   531    539       pcache.mxPagePurgeable += p->nMax;
   532         -    exitPcacheGlobal();
          540  +    pcacheExitGlobal();
   533    541     }
   534    542   
   535    543     /* Add the new pager-cache to the list of caches starting at pcache.pAll */
   536    544     sqlite3_mutex_enter(pcache.mutex_mem2);
   537    545     p->pNextAll = pcache.pAll;
   538    546     if( pcache.pAll ){
   539    547       pcache.pAll->pPrevAll = p;
   540    548     }
   541    549     p->pPrevAll = 0;
   542    550     pcache.pAll = p;
   543    551     sqlite3_mutex_leave(pcache.mutex_mem2);
   544    552   }
   545    553   
          554  +/*
          555  +** Change the page size for PCache object.  This can only happen
          556  +** when the cache is empty.
          557  +*/
   546    558   void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
   547    559     assert(pCache->nPage==0);
   548    560     pCache->szPage = szPage;
   549    561   }
   550    562   
   551    563   /*
   552    564   ** Try to obtain a page from the cache.
................................................................................
   565    577   
   566    578     /* Search the hash table for the requested page. Exit early if it is found. */
   567    579     if( pCache->apHash ){
   568    580       u32 h = pgno % pCache->nHash;
   569    581       for(pPage=pCache->apHash[h]; pPage; pPage=pPage->pNextHash){
   570    582         if( pPage->pgno==pgno ){
   571    583           if( pPage->nRef==0 && (pPage->flags & PGHDR_DIRTY)==0 ){
   572         -          enterPcacheGlobal();
          584  +          pcacheEnterGlobal();
   573    585             pcacheRemoveFromLruList(pPage);
   574         -          exitPcacheGlobal();
          586  +          pcacheExitGlobal();
   575    587           }
   576         -        page_ref(pPage, 1);
          588  +        pcacheRef(pPage, 1);
   577    589           *ppPage = pPage;
   578    590           return SQLITE_OK;
   579    591         }
   580    592       }
   581    593     }
   582    594   
   583    595     if( createFlag ){
................................................................................
   596    608   
   597    609       pPage->pPager = 0;
   598    610       pPage->flags = 0;
   599    611       pPage->pDirty = 0;
   600    612       pPage->nRef = 0;
   601    613       pPage->pgno = pgno;
   602    614       pPage->pCache = pCache;
   603         -    page_ref(pPage, 1);
          615  +    pcacheRef(pPage, 1);
   604    616       pcacheAddToList(&pCache->pClean, pPage);
   605    617       pcacheAddToHash(pPage);
   606    618     }else{
   607    619       *ppPage = 0;
   608    620     }
   609    621   
   610    622     return SQLITE_OK;
................................................................................
   613    625   /*
   614    626   ** Dereference a page.  When the reference count reaches zero,
   615    627   ** move the page to the LRU list if it is clean.
   616    628   */
   617    629   void sqlite3PcacheRelease(PgHdr *p){
   618    630     assert( p->nRef>0 );
   619    631     assert( p->pCache->iInUseDB || p->pCache->iInUseMM );
   620         -  page_ref(p, -1);
          632  +  pcacheRef(p, -1);
   621    633     if( p->nRef!=0 ) return;
   622    634     if( p->pCache->xDestroy ){
   623    635       p->pCache->xDestroy(p);
   624    636     }
   625    637     if( (p->flags & PGHDR_DIRTY)!=0 ) return;
   626         -  enterPcacheGlobal();
          638  +  pcacheEnterGlobal();
   627    639     pcacheAddToLruList(p);
   628         -  exitPcacheGlobal();
          640  +  pcacheExitGlobal();
   629    641   }
   630    642   
   631    643   void sqlite3PcacheRef(PgHdr *p){
   632    644     assert(p->nRef>=0);
   633         -  page_ref(p, 1);
          645  +  pcacheRef(p, 1);
   634    646   }
   635    647   
   636    648   /*
   637    649   ** Drop a page from the cache.  This should be the only reference to
   638    650   ** the page.
   639    651   */
   640    652   void sqlite3PcacheDrop(PgHdr *p){
................................................................................
   645    657     pCache->nRef--;
   646    658     if( p->flags & PGHDR_DIRTY ){
   647    659       pcacheRemoveFromList(&pCache->pDirty, p);
   648    660     }else{
   649    661       pcacheRemoveFromList(&pCache->pClean, p);
   650    662     }
   651    663     pcacheRemoveFromHash(p);
   652         -  enterPcacheGlobal();
          664  +  pcacheEnterGlobal();
   653    665     pcachePageFree(p);
   654         -  exitPcacheGlobal();
          666  +  pcacheExitGlobal();
   655    667   }
   656    668   
   657    669   /*
   658    670   ** Make sure the page is marked as dirty.  If it isn't dirty already,
   659    671   ** make it so.
   660    672   */
   661    673   void sqlite3PcacheMakeDirty(PgHdr *p){
................................................................................
   682    694     assert( p->flags & PGHDR_DIRTY );
   683    695     /* assert( p->nRef>0 ); */
   684    696     pCache = p->pCache;
   685    697     pcacheRemoveFromList(&pCache->pDirty, p);
   686    698     pcacheAddToList(&pCache->pClean, p);
   687    699     p->flags &= ~PGHDR_DIRTY;
   688    700     if( p->nRef==0 ){
   689         -    enterPcacheGlobal();
          701  +    pcacheEnterGlobal();
   690    702       pcacheAddToLruList(p);
   691         -    exitPcacheGlobal();
          703  +    pcacheExitGlobal();
   692    704     }
   693    705   }
   694    706   
   695    707   /*
   696    708   ** Make every page in the cache clean.
   697    709   */
   698    710   void sqlite3PcacheCleanAll(PCache *pCache){
................................................................................
   700    712     assert( pCache->iInUseDB );
   701    713     while( (p = pCache->pDirty)!=0 ){
   702    714       assert( p->apSave[0]==0 && p->apSave[1]==0 );
   703    715       pcacheRemoveFromList(&pCache->pDirty, p);
   704    716       pcacheAddToList(&pCache->pClean, p);
   705    717       p->flags &= ~PGHDR_DIRTY;
   706    718       if( p->nRef==0 ){
   707         -      enterPcacheGlobal();
          719  +      pcacheEnterGlobal();
   708    720         pcacheAddToLruList(p);
   709         -      exitPcacheGlobal();
          721  +      pcacheExitGlobal();
   710    722       }
   711    723     }
   712    724   }
   713    725   
   714    726   /*
   715    727   ** Change the page number of page p to newPgno. If newPgno is 0, then the
   716    728   ** page object is added to the clean-list and the PGHDR_REUSE_UNLIKELY 
................................................................................
   718    730   */
   719    731   void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
   720    732     assert( p->pCache->iInUseDB );
   721    733     pcacheRemoveFromHash(p);
   722    734     p->pgno = newPgno;
   723    735     if( newPgno==0 ){
   724    736       p->flags |= PGHDR_REUSE_UNLIKELY;
   725         -    enterPcacheGlobal();
          737  +    pcacheEnterGlobal();
   726    738       pcacheFree(p->apSave[0]);
   727    739       pcacheFree(p->apSave[1]);
   728         -    exitPcacheGlobal();
          740  +    pcacheExitGlobal();
   729    741       p->apSave[0] = 0;
   730    742       p->apSave[1] = 0;
   731    743       sqlite3PcacheMakeClean(p);
   732    744     }
   733    745     pcacheAddToHash(p);
   734    746   }
   735    747   
   736    748   /*
   737    749   ** Set the global maximum number of pages. Return the previous value.
   738    750   */
   739    751   void sqlite3PcacheGlobalMax(int mx){
   740         -  enterPcacheGlobal();
          752  +  pcacheEnterGlobal();
   741    753     pcache.mxPage = mx;
   742         -  exitPcacheGlobal();
          754  +  pcacheExitGlobal();
   743    755   }
   744    756   
   745    757   /*
   746    758   ** Remove all content from a page cache
   747    759   */
   748    760   void pcacheClear(PCache *pCache){
   749    761     PgHdr *p, *pNext;
................................................................................
   767    779   /*
   768    780   ** Drop every cache entry whose page number is greater than "pgno".
   769    781   */
   770    782   void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
   771    783     PgHdr *p, *pNext;
   772    784     PgHdr *pDirty = pCache->pDirty;
   773    785     assert( pCache->iInUseDB );
   774         -  enterPcacheGlobal();
          786  +  pcacheEnterGlobal();
   775    787     for(p=pCache->pClean; p||pDirty; p=pNext){
   776    788       if( !p ){
   777    789         p = pDirty;
   778    790         pDirty = 0;
   779    791       }
   780    792       pNext = p->pNext;
   781    793       if( p->pgno>pgno ){
................................................................................
   792    804           /* If there are references to the page, it cannot be freed. In this
   793    805           ** case, zero the page content instead.
   794    806           */
   795    807           memset(p->pData, 0, pCache->szPage);
   796    808         }
   797    809       }
   798    810     }
   799         -  exitPcacheGlobal();
          811  +  pcacheExitGlobal();
   800    812   }
   801    813   
   802    814   
   803    815   /*
   804    816   ** Close a cache.
   805    817   */
   806    818   void sqlite3PcacheClose(PCache *pCache){
   807    819     assert( pCache->iInUseDB==1 );
   808    820   
   809    821     /* Free all the pages used by this pager and remove them from the LRU
   810    822     ** list. This requires the protection of the MUTEX_STATIC_LRU mutex.
   811    823     */
   812         -  enterPcacheGlobal();
          824  +  pcacheEnterGlobal();
   813    825     pcacheClear(pCache);
   814    826     if( pCache->bPurgeable ){
   815    827       pcache.mxPagePurgeable -= pCache->nMax;
   816    828     }
   817    829     sqlite3_free(pCache->apHash);
   818         -  exitPcacheGlobal();
          830  +  pcacheExitGlobal();
   819    831   
   820    832     /* Now remove the pager-cache structure itself from the list of
   821    833     ** all such structures headed by pcache.pAll. This required the
   822    834     ** MUTEX_STATIC_MEM2 mutex.
   823    835     */
   824    836     sqlite3_mutex_enter(pcache.mutex_mem2);
   825    837     assert(pCache==pcache.pAll || pCache->pPrevAll);
................................................................................
   861    873   
   862    874   /*
   863    875   ** Commit a change previously preserved.
   864    876   */
   865    877   void sqlite3PcacheCommit(PCache *pCache, int idJournal){
   866    878     PgHdr *p;
   867    879     assert( pCache->iInUseDB );
   868         -  enterPcacheGlobal();     /* Mutex is required to call pcacheFree() */
          880  +  pcacheEnterGlobal();     /* Mutex is required to call pcacheFree() */
   869    881     for(p=pCache->pDirty; p; p=p->pNext){
   870    882       if( p->apSave[idJournal] ){
   871    883         pcacheFree(p->apSave[idJournal]);
   872    884         p->apSave[idJournal] = 0;
   873    885       }
   874    886     }
   875         -  exitPcacheGlobal();
          887  +  pcacheExitGlobal();
   876    888   }
   877    889   
   878    890   /*
   879    891   ** Rollback a change previously preserved.
   880    892   */
   881    893   void sqlite3PcacheRollback(PCache *pCache, int idJournal){
   882    894     PgHdr *p;
   883    895     int sz;
   884    896     assert( pCache->iInUseDB );
   885         -  enterPcacheGlobal();     /* Mutex is required to call pcacheFree() */
          897  +  pcacheEnterGlobal();     /* Mutex is required to call pcacheFree() */
   886    898     sz = pCache->szPage;
   887    899     for(p=pCache->pDirty; p; p=p->pNext){
   888    900       if( p->apSave[idJournal] ){
   889    901         memcpy(p->pData, p->apSave[idJournal], sz);
   890    902         pcacheFree(p->apSave[idJournal]);
   891    903         p->apSave[idJournal] = 0;
   892    904       }
   893    905     }
   894         -  exitPcacheGlobal();
          906  +  pcacheExitGlobal();
   895    907   }
   896    908   
   897    909   /* 
   898    910   ** Assert flags settings on all pages.  Debugging only.
   899    911   */
   900    912   void sqlite3PcacheAssertFlags(PCache *pCache, int trueMask, int falseMask){
   901    913     PgHdr *p;
................................................................................
   912    924   
   913    925   /* 
   914    926   ** Discard the contents of the cache.
   915    927   */
   916    928   int sqlite3PcacheClear(PCache *pCache){
   917    929     assert( pCache->iInUseDB );
   918    930     assert(pCache->nRef==0);
   919         -  enterPcacheGlobal();
          931  +  pcacheEnterGlobal();
   920    932     pcacheClear(pCache);
   921         -  exitPcacheGlobal();
          933  +  pcacheExitGlobal();
   922    934     return SQLITE_OK;
   923    935   }
   924    936   
   925    937   /*
   926    938   ** Merge two lists of pages connected by pDirty and in pgno order.
   927    939   ** Do not both fixing the pPrevDirty pointers.
   928    940   */
................................................................................
  1096   1108   ** Set the suggested cache-size value.
  1097   1109   */
  1098   1110   void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
  1099   1111     if( mxPage<10 ){
  1100   1112       mxPage = 10;
  1101   1113     }
  1102   1114     if( pCache->bPurgeable ){
  1103         -    enterPcacheGlobal();
         1115  +    pcacheEnterGlobal();
  1104   1116       pcache.mxPagePurgeable -= pCache->nMax;
  1105   1117       pcache.mxPagePurgeable += mxPage;
  1106         -    exitPcacheGlobal();
         1118  +    pcacheExitGlobal();
  1107   1119     }
  1108   1120     pCache->nMax = mxPage;
  1109   1121   }
  1110   1122   
  1111   1123   /*
  1112   1124   ** Lock a pager-cache.
  1113   1125   */
................................................................................
  1125   1137   /*
  1126   1138   ** Unlock a pager-cache.
  1127   1139   */
  1128   1140   void sqlite3PcacheUnlock(PCache *pCache){
  1129   1141     pCache->iInUseDB--;
  1130   1142     assert( pCache->iInUseDB>=0 );
  1131   1143   }
  1132         -