mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
Revert whitespace fixes to third_party (#501)
This commit is contained in:
parent
d4000bb8f7
commit
9de3d8f1e6
365 changed files with 39190 additions and 39211 deletions
94
third_party/sqlite3/pcache1.c
vendored
94
third_party/sqlite3/pcache1.c
vendored
|
@ -89,16 +89,16 @@ typedef struct PgFreeslot PgFreeslot;
|
|||
typedef struct PGroup PGroup;
|
||||
|
||||
/*
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
|
||||
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
|
||||
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
|
||||
** in memory.
|
||||
**
|
||||
** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
|
||||
** but causes a 2-byte gap in the structure for most architectures (since
|
||||
** but causes a 2-byte gap in the structure for most architectures (since
|
||||
** pointers must be either 4 or 8-byte aligned). As this structure is located
|
||||
** in memory directly after the associated page data, if the database is
|
||||
** corrupt, code at the b-tree layer may overread the page buffer and
|
||||
** corrupt, code at the b-tree layer may overread the page buffer and
|
||||
** read part of this structure before the corruption is detected. This
|
||||
** can cause a valgrind error if the unitialized gap is accessed. Using u16
|
||||
** ensures there is no such gap, and therefore no bytes of unitialized memory
|
||||
|
@ -123,7 +123,7 @@ struct PgHdr1 {
|
|||
#define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
|
||||
#define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
|
||||
|
||||
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
|
||||
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
|
||||
** of one or more PCaches that are able to recycle each other's unpinned
|
||||
** pages when they are under memory pressure. A PGroup is an instance of
|
||||
** the following object.
|
||||
|
@ -159,13 +159,13 @@ struct PGroup {
|
|||
** temporary or transient database) has a single page cache which
|
||||
** is an instance of this object.
|
||||
**
|
||||
** Pointers to structures of this type are cast and returned as
|
||||
** Pointers to structures of this type are cast and returned as
|
||||
** opaque sqlite3_pcache* handles.
|
||||
*/
|
||||
struct PCache1 {
|
||||
/* Cache configuration parameters. Page size (szPage) and the purgeable
|
||||
** flag (bPurgeable) and the pnPurgeable pointer are all set when the
|
||||
** cache is created and are never changed thereafter. nMax may be
|
||||
** cache is created and are never changed thereafter. nMax may be
|
||||
** modified at any time by a call to the pcache1Cachesize() method.
|
||||
** The PGroup mutex must be held when accessing nMax.
|
||||
*/
|
||||
|
@ -213,7 +213,7 @@ static SQLITE_WSD struct PCacheGlobal {
|
|||
*/
|
||||
int isInit; /* True if initialized */
|
||||
int separateCache; /* Use a new PGroup for each PCache */
|
||||
int nInitPage; /* Initial bulk allocation size */
|
||||
int nInitPage; /* Initial bulk allocation size */
|
||||
int szSlot; /* Size of each free slot */
|
||||
int nSlot; /* The number of pcache slots */
|
||||
int nReserve; /* Try to keep nFreeSlot above this */
|
||||
|
@ -254,7 +254,7 @@ static SQLITE_WSD struct PCacheGlobal {
|
|||
|
||||
|
||||
/*
|
||||
** This function is called during initialization if a static buffer is
|
||||
** This function is called during initialization if a static buffer is
|
||||
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
|
||||
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
|
||||
** enough to contain 'n' buffers of 'sz' bytes each.
|
||||
|
@ -324,8 +324,8 @@ static int pcache1InitBulk(PCache1 *pCache){
|
|||
|
||||
/*
|
||||
** Malloc function used within this file to allocate space from the buffer
|
||||
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
|
||||
** such buffer exists or there is no space left in it, this function falls
|
||||
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
|
||||
** such buffer exists or there is no space left in it, this function falls
|
||||
** back to sqlite3Malloc().
|
||||
**
|
||||
** Multiple threads can run this routine at the same time. Global variables
|
||||
|
@ -432,7 +432,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
|
|||
}else{
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
/* The group mutex must be released before pcache1Alloc() is called. This
|
||||
** is because it might call sqlite3_release_memory(), which assumes that
|
||||
** is because it might call sqlite3_release_memory(), which assumes that
|
||||
** this mutex is not held. */
|
||||
assert( pcache1.separateCache==0 );
|
||||
assert( pCache->pGroup==&pcache1.grp );
|
||||
|
@ -574,7 +574,7 @@ static void pcache1ResizeHash(PCache1 *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** This function is used internally to remove the page pPage from the
|
||||
** This function is used internally to remove the page pPage from the
|
||||
** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
|
||||
** LRU list, then this function is a no-op.
|
||||
**
|
||||
|
@ -599,7 +599,7 @@ static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
|
|||
|
||||
|
||||
/*
|
||||
** Remove the page supplied as an argument from the hash table
|
||||
** Remove the page supplied as an argument from the hash table
|
||||
** (PCache1.apHash structure) that it is currently stored in.
|
||||
** Also free the page if freePage is true.
|
||||
**
|
||||
|
@ -642,8 +642,8 @@ static void pcache1EnforceMaxPage(PCache1 *pCache){
|
|||
}
|
||||
|
||||
/*
|
||||
** Discard all pages from cache pCache with a page number (key value)
|
||||
** greater than or equal to iLimit. Any pinned pages that meet this
|
||||
** Discard all pages from cache pCache with a page number (key value)
|
||||
** greater than or equal to iLimit. Any pinned pages that meet this
|
||||
** criteria are unpinned before they are discarded.
|
||||
**
|
||||
** The PCache mutex must be held when this function is called.
|
||||
|
@ -675,7 +675,7 @@ static void pcache1TruncateUnsafe(
|
|||
PgHdr1 **pp;
|
||||
PgHdr1 *pPage;
|
||||
assert( h<pCache->nHash );
|
||||
pp = &pCache->apHash[h];
|
||||
pp = &pCache->apHash[h];
|
||||
while( (pPage = *pp)!=0 ){
|
||||
if( pPage->iKey>=iLimit ){
|
||||
pCache->nPage--;
|
||||
|
@ -714,7 +714,7 @@ static int pcache1Init(void *NotUsed){
|
|||
**
|
||||
** * Use a unified cache in single-threaded applications that have
|
||||
** configured a start-time buffer for use as page-cache memory using
|
||||
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
|
||||
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
|
||||
** pBuf argument.
|
||||
**
|
||||
** * Otherwise use separate caches (mode-1)
|
||||
|
@ -749,7 +749,7 @@ static int pcache1Init(void *NotUsed){
|
|||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xShutdown method.
|
||||
** Note that the static mutex allocated in xInit does
|
||||
** Note that the static mutex allocated in xInit does
|
||||
** not need to be freed.
|
||||
*/
|
||||
static void pcache1Shutdown(void *NotUsed){
|
||||
|
@ -812,7 +812,7 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xCachesize method.
|
||||
** Implementation of the sqlite3_pcache.xCachesize method.
|
||||
**
|
||||
** Configure the cache_size limit for a cache.
|
||||
*/
|
||||
|
@ -831,7 +831,7 @@ static void pcache1Cachesize(sqlite3_pcache *p, int nMax){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xShrink method.
|
||||
** Implementation of the sqlite3_pcache.xShrink method.
|
||||
**
|
||||
** Free up as much memory as possible.
|
||||
*/
|
||||
|
@ -850,7 +850,7 @@ static void pcache1Shrink(sqlite3_pcache *p){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xPagecount method.
|
||||
** Implementation of the sqlite3_pcache.xPagecount method.
|
||||
*/
|
||||
static int pcache1Pagecount(sqlite3_pcache *p){
|
||||
int n;
|
||||
|
@ -871,8 +871,8 @@ static int pcache1Pagecount(sqlite3_pcache *p){
|
|||
** for these steps, the main pcache1Fetch() procedure can run faster.
|
||||
*/
|
||||
static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
||||
PCache1 *pCache,
|
||||
unsigned int iKey,
|
||||
PCache1 *pCache,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
unsigned int nPinned;
|
||||
|
@ -914,8 +914,8 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
}
|
||||
}
|
||||
|
||||
/* Step 5. If a usable page buffer has still not been found,
|
||||
** attempt to allocate a new one.
|
||||
/* Step 5. If a usable page buffer has still not been found,
|
||||
** attempt to allocate a new one.
|
||||
*/
|
||||
if( !pPage ){
|
||||
pPage = pcache1AllocPage(pCache, createFlag==1);
|
||||
|
@ -940,13 +940,13 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xFetch method.
|
||||
** Implementation of the sqlite3_pcache.xFetch method.
|
||||
**
|
||||
** Fetch a page by key value.
|
||||
**
|
||||
** Whether or not a new page may be allocated by this function depends on
|
||||
** the value of the createFlag argument. 0 means do not allocate a new
|
||||
** page. 1 means allocate a new page if space is easily available. 2
|
||||
** page. 1 means allocate a new page if space is easily available. 2
|
||||
** means to try really hard to allocate a new page.
|
||||
**
|
||||
** For a non-purgeable cache (a cache used as the storage for an in-memory
|
||||
|
@ -957,7 +957,7 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** There are three different approaches to obtaining space for a page,
|
||||
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
|
||||
**
|
||||
** 1. Regardless of the value of createFlag, the cache is searched for a
|
||||
** 1. Regardless of the value of createFlag, the cache is searched for a
|
||||
** copy of the requested page. If one is found, it is returned.
|
||||
**
|
||||
** 2. If createFlag==0 and the page is not already in the cache, NULL is
|
||||
|
@ -971,13 +971,13 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** PCache1.nMax, or
|
||||
**
|
||||
** (b) the number of pages pinned by the cache is greater than
|
||||
** the sum of nMax for all purgeable caches, less the sum of
|
||||
** the sum of nMax for all purgeable caches, less the sum of
|
||||
** nMin for all other purgeable caches, or
|
||||
**
|
||||
** 4. If none of the first three conditions apply and the cache is marked
|
||||
** as purgeable, and if one of the following is true:
|
||||
**
|
||||
** (a) The number of pages allocated for the cache is already
|
||||
** (a) The number of pages allocated for the cache is already
|
||||
** PCache1.nMax, or
|
||||
**
|
||||
** (b) The number of pages allocated for all purgeable caches is
|
||||
|
@ -989,7 +989,7 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
**
|
||||
** then attempt to recycle a page from the LRU list. If it is the right
|
||||
** size, return the recycled buffer. Otherwise, free the buffer and
|
||||
** proceed to step 5.
|
||||
** proceed to step 5.
|
||||
**
|
||||
** 5. Otherwise, allocate and return a new page buffer.
|
||||
**
|
||||
|
@ -999,8 +999,8 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
|
|||
** invokes the appropriate routine.
|
||||
*/
|
||||
static PgHdr1 *pcache1FetchNoMutex(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
|
@ -1029,8 +1029,8 @@ static PgHdr1 *pcache1FetchNoMutex(
|
|||
}
|
||||
#if PCACHE1_MIGHT_USE_GROUP_MUTEX
|
||||
static PgHdr1 *pcache1FetchWithMutex(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
|
@ -1044,8 +1044,8 @@ static PgHdr1 *pcache1FetchWithMutex(
|
|||
}
|
||||
#endif
|
||||
static sqlite3_pcache_page *pcache1Fetch(
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
sqlite3_pcache *p,
|
||||
unsigned int iKey,
|
||||
int createFlag
|
||||
){
|
||||
#if PCACHE1_MIGHT_USE_GROUP_MUTEX || defined(SQLITE_DEBUG)
|
||||
|
@ -1075,18 +1075,18 @@ static sqlite3_pcache_page *pcache1Fetch(
|
|||
** Mark a page as unpinned (eligible for asynchronous recycling).
|
||||
*/
|
||||
static void pcache1Unpin(
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
int reuseUnlikely
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = (PgHdr1 *)pPg;
|
||||
PGroup *pGroup = pCache->pGroup;
|
||||
|
||||
|
||||
assert( pPage->pCache==pCache );
|
||||
pcache1EnterMutex(pGroup);
|
||||
|
||||
/* It is an error to call this function if the page is already
|
||||
/* It is an error to call this function if the page is already
|
||||
** part of the PGroup LRU list.
|
||||
*/
|
||||
assert( pPage->pLruNext==0 );
|
||||
|
@ -1107,7 +1107,7 @@ static void pcache1Unpin(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xRekey method.
|
||||
** Implementation of the sqlite3_pcache.xRekey method.
|
||||
*/
|
||||
static void pcache1Rekey(
|
||||
sqlite3_pcache *p,
|
||||
|
@ -1118,7 +1118,7 @@ static void pcache1Rekey(
|
|||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = (PgHdr1 *)pPg;
|
||||
PgHdr1 **pp;
|
||||
unsigned int h;
|
||||
unsigned int h;
|
||||
assert( pPage->iKey==iOld );
|
||||
assert( pPage->pCache==pCache );
|
||||
|
||||
|
@ -1143,7 +1143,7 @@ static void pcache1Rekey(
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xTruncate method.
|
||||
** Implementation of the sqlite3_pcache.xTruncate method.
|
||||
**
|
||||
** Discard all unpinned pages in the cache with a page number equal to
|
||||
** or greater than parameter iLimit. Any pinned pages with a page number
|
||||
|
@ -1160,7 +1160,7 @@ static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
|
|||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xDestroy method.
|
||||
** Implementation of the sqlite3_pcache.xDestroy method.
|
||||
**
|
||||
** Destroy a cache allocated using pcache1Create().
|
||||
*/
|
||||
|
@ -1226,7 +1226,7 @@ sqlite3_mutex *sqlite3Pcache1Mutex(void){
|
|||
** by the current thread may be sqlite3_free()ed.
|
||||
**
|
||||
** nReq is the number of bytes of memory required. Once this much has
|
||||
** been released, the function returns. The return value is the total number
|
||||
** been released, the function returns. The return value is the total number
|
||||
** of bytes of memory released.
|
||||
*/
|
||||
int sqlite3PcacheReleaseMemory(int nReq){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue