os/persistentdata/persistentstorage/sql/SQLite364/pcache.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/SQLite364/pcache.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,176 @@
     1.4 +/*
     1.5 +** 2008 August 05
     1.6 +**
     1.7 +** The author disclaims copyright to this source code.  In place of
     1.8 +** a legal notice, here is a blessing:
     1.9 +**
    1.10 +**    May you do good and not evil.
    1.11 +**    May you find forgiveness for yourself and forgive others.
    1.12 +**    May you share freely, never taking more than you give.
    1.13 +**
    1.14 +*************************************************************************
    1.15 +** This header file defines the interface that the sqlite page cache
    1.16 +** subsystem. 
    1.17 +**
    1.18 +** @(#) $Id: pcache.h,v 1.13 2008/10/11 17:42:29 drh Exp $
    1.19 +*/
    1.20 +
    1.21 +#ifndef _PCACHE_H_
    1.22 +
    1.23 +typedef struct PgHdr PgHdr;
    1.24 +typedef struct PCache PCache;
    1.25 +
    1.26 +/*
    1.27 +** Every page in the cache is controlled by an instance of the following
    1.28 +** structure.
    1.29 +*/
    1.30 +struct PgHdr {
    1.31 +  void *pData;                   /* Content of this page */
    1.32 +  void *pExtra;                  /* Extra content */
    1.33 +  PgHdr *pDirty;                 /* Transient list of dirty pages */
    1.34 +  Pgno pgno;                     /* Page number for this page */
    1.35 +  Pager *pPager;                 /* The pager this page is part of */
    1.36 +#ifdef SQLITE_CHECK_PAGES
    1.37 +  u32 pageHash;                  /* Hash of page content */
    1.38 +#endif
    1.39 +  u16 flags;                     /* PGHDR flags defined below */
    1.40 +  /**********************************************************************
    1.41 +  ** Elements above are public.  All that follows is private to pcache.c
    1.42 +  ** and should not be accessed by other modules.
    1.43 +  */
    1.44 +  i16 nRef;                      /* Number of users of this page */
    1.45 +  PCache *pCache;                /* Cache that owns this page */
    1.46 +  void *apSave[2];               /* Journal entries for in-memory databases */
    1.47 +  /**********************************************************************
    1.48 +  ** Elements above are accessible at any time by the owner of the cache
    1.49 +  ** without the need for a mutex.  The elements that follow can only be
    1.50 +  ** accessed while holding the SQLITE_MUTEX_STATIC_LRU mutex.
    1.51 +  */
    1.52 +  PgHdr *pNextHash, *pPrevHash;  /* Hash collision chain for PgHdr.pgno */
    1.53 +  PgHdr *pNext, *pPrev;          /* List of clean or dirty pages */
    1.54 +  PgHdr *pNextLru, *pPrevLru;    /* Part of global LRU list */
    1.55 +};
    1.56 +
    1.57 +/* Bit values for PgHdr.flags */
    1.58 +#define PGHDR_IN_JOURNAL        0x001  /* Page is in rollback journal */
    1.59 +#define PGHDR_DIRTY             0x002  /* Page has changed */
    1.60 +#define PGHDR_NEED_SYNC         0x004  /* Fsync the rollback journal before
    1.61 +                                       ** writing this page to the database */
    1.62 +#define PGHDR_NEED_READ         0x008  /* Content is unread */
    1.63 +#define PGHDR_REUSE_UNLIKELY    0x010  /* A hint that reuse is unlikely */
    1.64 +#define PGHDR_DONT_WRITE        0x020  /* Do not write content to disk */
    1.65 +
    1.66 +/* Initialize and shutdown the page cache subsystem */
    1.67 +int sqlite3PcacheInitialize(void);
    1.68 +void sqlite3PcacheShutdown(void);
    1.69 +
    1.70 +/* Page cache buffer management:
    1.71 +** These routines implement SQLITE_CONFIG_PAGECACHE.
    1.72 +*/
    1.73 +void sqlite3PCacheBufferSetup(void *, int sz, int n);
    1.74 +void *sqlite3PCacheMalloc(int sz);
    1.75 +void sqlite3PCacheFree(void*);
    1.76 +
    1.77 +/* Create a new pager cache.
    1.78 +** Under memory stress, invoke xStress to try to make pages clean.
    1.79 +** Only clean and unpinned pages can be reclaimed.
    1.80 +*/
    1.81 +void sqlite3PcacheOpen(
    1.82 +  int szPage,                    /* Size of every page */
    1.83 +  int szExtra,                   /* Extra space associated with each page */
    1.84 +  int bPurgeable,                /* True if pages are on backing store */
    1.85 +  int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */
    1.86 +  void *pStress,                 /* Argument to xStress */
    1.87 +  PCache *pToInit                /* Preallocated space for the PCache */
    1.88 +);
    1.89 +
    1.90 +/* Modify the page-size after the cache has been created. */
    1.91 +void sqlite3PcacheSetPageSize(PCache *, int);
    1.92 +
    1.93 +/* Return the size in bytes of a PCache object.  Used to preallocate
    1.94 +** storage space.
    1.95 +*/
    1.96 +int sqlite3PcacheSize(void);
    1.97 +
    1.98 +/* One release per successful fetch.  Page is pinned until released.
    1.99 +** Reference counted. 
   1.100 +*/
   1.101 +int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
   1.102 +void sqlite3PcacheRelease(PgHdr*);
   1.103 +
   1.104 +void sqlite3PcacheDrop(PgHdr*);         /* Remove page from cache */
   1.105 +void sqlite3PcacheMakeDirty(PgHdr*);    /* Make sure page is marked dirty */
   1.106 +void sqlite3PcacheMakeClean(PgHdr*);    /* Mark a single page as clean */
   1.107 +void sqlite3PcacheCleanAll(PCache*);    /* Mark all dirty list pages as clean */
   1.108 +
   1.109 +/* Change a page number.  Used by incr-vacuum. */
   1.110 +void sqlite3PcacheMove(PgHdr*, Pgno);
   1.111 +
   1.112 +/* Remove all pages with pgno>x.  Reset the cache if x==0 */
   1.113 +void sqlite3PcacheTruncate(PCache*, Pgno x);
   1.114 +
   1.115 +/* Routines used to implement transactions on memory-only databases. */
   1.116 +int sqlite3PcachePreserve(PgHdr*, int);    /* Preserve current page content */
   1.117 +void sqlite3PcacheCommit(PCache*, int);    /* Drop preserved copy */
   1.118 +void sqlite3PcacheRollback(PCache*, int, void (*xReiniter)(PgHdr*));
   1.119 +
   1.120 +/* Get a list of all dirty pages in the cache, sorted by page number */
   1.121 +PgHdr *sqlite3PcacheDirtyList(PCache*);
   1.122 +
   1.123 +/* Reset and close the cache object */
   1.124 +void sqlite3PcacheClose(PCache*);
   1.125 +
   1.126 +/* Clear flags from pages of the page cache */
   1.127 +void sqlite3PcacheClearFlags(PCache*, int mask);
   1.128 +
   1.129 +/* Assert flags settings on all pages.  Debugging only */
   1.130 +#ifndef NDEBUG
   1.131 +  void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask);
   1.132 +#else
   1.133 +# define sqlite3PcacheAssertFlags(A,B,C)
   1.134 +#endif
   1.135 +
   1.136 +/* Return true if the number of dirty pages is 0 or 1 */
   1.137 +int sqlite3PcacheZeroOrOneDirtyPages(PCache*);
   1.138 +
   1.139 +/* Discard the contents of the cache */
   1.140 +int sqlite3PcacheClear(PCache*);
   1.141 +
   1.142 +/* Return the total number of outstanding page references */
   1.143 +int sqlite3PcacheRefCount(PCache*);
   1.144 +
   1.145 +/* Increment the reference count of an existing page */
   1.146 +void sqlite3PcacheRef(PgHdr*);
   1.147 +
   1.148 +int sqlite3PcachePageRefcount(PgHdr*);
   1.149 +
   1.150 +/* Return the total number of pages stored in the cache */
   1.151 +int sqlite3PcachePagecount(PCache*);
   1.152 +
   1.153 +#ifdef SQLITE_CHECK_PAGES
   1.154 +/* Iterate through all pages currently stored in the cache. This interface
   1.155 +** is only available if SQLITE_CHECK_PAGES is defined when the library is 
   1.156 +** built.
   1.157 +*/
   1.158 +void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *));
   1.159 +#endif
   1.160 +
   1.161 +/* Set and get the suggested cache-size for the specified pager-cache.
   1.162 +**
   1.163 +** If no global maximum is configured, then the system attempts to limit
   1.164 +** the total number of pages cached by purgeable pager-caches to the sum
   1.165 +** of the suggested cache-sizes.
   1.166 +*/
   1.167 +int sqlite3PcacheGetCachesize(PCache *);
   1.168 +void sqlite3PcacheSetCachesize(PCache *, int);
   1.169 +
   1.170 +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   1.171 +/* Try to return memory used by the pcache module to the main memory heap */
   1.172 +int sqlite3PcacheReleaseMemory(int);
   1.173 +#endif
   1.174 +
   1.175 +#ifdef SQLITE_TEST
   1.176 +void sqlite3PcacheStats(int*,int*,int*,int*);
   1.177 +#endif
   1.178 +
   1.179 +#endif /* _PCACHE_H_ */