~ubuntu-branches/ubuntu/precise/sqlite3/precise-updates

« back to all changes in this revision

Viewing changes to src/pcache1.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-12-11 14:34:09 UTC
  • mfrom: (9.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091211143409-o29fahwmcmyd0vq1
Tags: 3.6.21-2
Run autoreconf to prevent FTBFS with new libtool (closes: #560660).

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
16
16
** If the default page cache implementation is overriden, then neither of
17
17
** these two features are available.
18
 
**
19
 
** @(#) $Id: pcache1.c,v 1.17 2009/06/09 18:58:53 shane Exp $
20
18
*/
21
19
 
22
20
#include "sqliteInt.h"
218
216
 
219
217
/*
220
218
** Free a page object allocated by pcache1AllocPage().
 
219
**
 
220
** The pointer is allowed to be NULL, which is prudent.  But it turns out
 
221
** that the current implementation happens to never call this routine
 
222
** with a NULL pointer, so we mark the NULL test with ALWAYS().
221
223
*/
222
224
static void pcache1FreePage(PgHdr1 *p){
223
 
  if( p ){
 
225
  if( ALWAYS(p) ){
224
226
    if( p->pCache->bPurgeable ){
225
227
      pcache1.nCurrentPage--;
226
228
    }
408
410
 
409
411
/*
410
412
** Implementation of the sqlite3_pcache.xShutdown method.
 
413
** Note that the static mutex allocated in xInit does 
 
414
** not need to be freed.
411
415
*/
412
416
static void pcache1Shutdown(void *NotUsed){
413
417
  UNUSED_PARAMETER(NotUsed);
471
475
** Fetch a page by key value.
472
476
**
473
477
** Whether or not a new page may be allocated by this function depends on
474
 
** the value of the createFlag argument.
 
478
** the value of the createFlag argument.  0 means do not allocate a new
 
479
** page.  1 means allocate a new page if space is easily available.  2 
 
480
** means to try really hard to allocate a new page.
 
481
**
 
482
** For a non-purgeable cache (a cache used as the storage for an in-memory
 
483
** database) there is really no difference between createFlag 1 and 2.  So
 
484
** the calling function (pcache.c) will never have a createFlag of 1 on
 
485
** a non-purgable cache.
475
486
**
476
487
** There are three different approaches to obtaining space for a page,
477
488
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
482
493
**   2. If createFlag==0 and the page is not already in the cache, NULL is
483
494
**      returned.
484
495
**
485
 
**   3. If createFlag is 1, the cache is marked as purgeable and the page is 
486
 
**      not already in the cache, and if either of the following are true, 
487
 
**      return NULL:
 
496
**   3. If createFlag is 1, and the page is not already in the cache,
 
497
**      and if either of the following are true, return NULL:
488
498
**
489
499
**       (a) the number of pages pinned by the cache is greater than
490
500
**           PCache1.nMax, or
513
523
  PCache1 *pCache = (PCache1 *)p;
514
524
  PgHdr1 *pPage = 0;
515
525
 
 
526
  assert( pCache->bPurgeable || createFlag!=1 );
516
527
  pcache1EnterMutex();
517
528
  if( createFlag==1 ) sqlite3BeginBenignMalloc();
518
529
 
529
540
 
530
541
  /* Step 3 of header comment. */
531
542
  nPinned = pCache->nPage - pCache->nRecyclable;
532
 
  if( createFlag==1 && pCache->bPurgeable && (
 
543
  if( createFlag==1 && (
533
544
        nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
534
545
     || nPinned>=(pCache->nMax * 9 / 10)
535
546
  )){
654
665
  pPage->iKey = iNew;
655
666
  pPage->pNext = pCache->apHash[h];
656
667
  pCache->apHash[h] = pPage;
657
 
 
658
668
  if( iNew>pCache->iMaxKey ){
659
669
    pCache->iMaxKey = iNew;
660
670
  }