aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c9
-rw-r--r--src/malloc.c15
-rw-r--r--src/mutex.c34
-rw-r--r--src/pcache.c28
-rw-r--r--src/pcache1.c11
-rw-r--r--src/test2.c5
6 files changed, 45 insertions, 57 deletions
diff --git a/src/btree.c b/src/btree.c
index c2d4e50b9..e363e91f2 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.690 2009/07/15 18:15:23 drh Exp $
+** $Id: btree.c,v 1.691 2009/07/16 18:21:18 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -2618,6 +2618,11 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
/*
** Move the open database page pDbPage to location iFreePage in the
** database. The pDbPage reference remains valid.
+**
+** The isCommit flag indicates that there is no need to remember that
+** the journal needs to be sync()ed before database page pDbPage->pgno
+** can be written to. The caller has already promised not to write to that
+** page.
*/
static int relocatePage(
BtShared *pBt, /* Btree */
@@ -2625,7 +2630,7 @@ static int relocatePage(
u8 eType, /* Pointer map 'type' entry for pDbPage */
Pgno iPtrPage, /* Pointer map 'page-no' entry for pDbPage */
Pgno iFreePage, /* The location to move pDbPage to */
- int isCommit
+ int isCommit /* isCommit flag passed to sqlite3PagerMovepage */
){
MemPage *pPtrPage; /* The page that contains a pointer to pDbPage */
Pgno iDbPage = pDbPage->pgno;
diff --git a/src/malloc.c b/src/malloc.c
index e89f5ab14..9986f377d 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -12,7 +12,7 @@
**
** Memory allocation functions used throughout sqlite.
**
-** $Id: malloc.c,v 1.64 2009/06/27 00:48:33 drh Exp $
+** $Id: malloc.c,v 1.65 2009/07/16 18:21:18 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -88,13 +88,11 @@ static SQLITE_WSD struct Mem0Global {
** The alarm callback and its arguments. The mem0.mutex lock will
** be held while the callback is running. Recursive calls into
** the memory subsystem are allowed, but no new callbacks will be
- ** issued. The alarmBusy variable is set to prevent recursive
- ** callbacks.
+ ** issued.
*/
sqlite3_int64 alarmThreshold;
void (*alarmCallback)(void*, sqlite3_int64,int);
void *alarmArg;
- int alarmBusy;
/*
** Pointers to the end of sqlite3GlobalConfig.pScratch and
@@ -103,7 +101,7 @@ static SQLITE_WSD struct Mem0Global {
*/
u32 *aScratchFree;
u32 *aPageFree;
-} mem0 = { 62560955, 0, 0, 0, 0, 0, 0, 0, 0 };
+} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
#define mem0 GLOBAL(struct Mem0Global, mem0)
@@ -220,15 +218,16 @@ static void sqlite3MallocAlarm(int nByte){
void (*xCallback)(void*,sqlite3_int64,int);
sqlite3_int64 nowUsed;
void *pArg;
- if( mem0.alarmCallback==0 || mem0.alarmBusy ) return;
- mem0.alarmBusy = 1;
+ if( mem0.alarmCallback==0 ) return;
xCallback = mem0.alarmCallback;
nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
pArg = mem0.alarmArg;
+ mem0.alarmCallback = 0;
sqlite3_mutex_leave(mem0.mutex);
xCallback(pArg, nowUsed, nByte);
sqlite3_mutex_enter(mem0.mutex);
- mem0.alarmBusy = 0;
+ mem0.alarmCallback = xCallback;
+ mem0.alarmArg = pArg;
}
/*
diff --git a/src/mutex.c b/src/mutex.c
index d7b769d73..9c7cdd4ab 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -14,7 +14,7 @@
** This file contains code that is common across all mutex implementations.
**
-** $Id: mutex.c,v 1.30 2009/02/17 16:29:11 danielk1977 Exp $
+** $Id: mutex.c,v 1.31 2009/07/16 18:21:18 drh Exp $
*/
#include "sqliteInt.h"
@@ -30,32 +30,16 @@ int sqlite3MutexInit(void){
** install a mutex implementation via sqlite3_config() prior to
** sqlite3_initialize() being called. This block copies pointers to
** the default implementation into the sqlite3GlobalConfig structure.
- **
- ** The danger is that although sqlite3_config() is not a threadsafe
- ** API, sqlite3_initialize() is, and so multiple threads may be
- ** attempting to run this function simultaneously. To guard write
- ** access to the sqlite3GlobalConfig structure, the 'MASTER' static mutex
- ** is obtained before modifying it.
*/
- sqlite3_mutex_methods *p = sqlite3DefaultMutex();
- sqlite3_mutex *pMaster = 0;
-
- rc = p->xMutexInit();
- if( rc==SQLITE_OK ){
- pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
- assert(pMaster);
- p->xMutexEnter(pMaster);
- assert( sqlite3GlobalConfig.mutex.xMutexAlloc==0
- || sqlite3GlobalConfig.mutex.xMutexAlloc==p->xMutexAlloc
- );
- if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
- sqlite3GlobalConfig.mutex = *p;
- }
- p->xMutexLeave(pMaster);
- }
- }else{
- rc = sqlite3GlobalConfig.mutex.xMutexInit();
+ sqlite3_mutex_methods *pFrom = sqlite3DefaultMutex();
+ sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
+
+ memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
+ memcpy(&pTo->xMutexFree, &pFrom->xMutexFree,
+ sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
+ pTo->xMutexAlloc = pFrom->xMutexAlloc;
}
+ rc = sqlite3GlobalConfig.mutex.xMutexInit();
}
return rc;
diff --git a/src/pcache.c b/src/pcache.c
index 571581980..dd166f857 100644
--- a/src/pcache.c
+++ b/src/pcache.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file implements that page cache.
**
-** @(#) $Id: pcache.c,v 1.44 2009/03/31 01:32:18 drh Exp $
+** @(#) $Id: pcache.c,v 1.45 2009/07/16 18:21:18 drh Exp $
*/
#include "sqliteInt.h"
@@ -470,24 +470,22 @@ static PgHdr *pcacheMergeDirtyList(PgHdr *pA, PgHdr *pB){
** Sort the list of pages in accending order by pgno. Pages are
** connected by pDirty pointers. The pDirtyPrev pointers are
** corrupted by this sort.
+**
+** Since there cannot be more than 2^31 distinct pages in a database,
+** there cannot be more than 31 buckets required by the merge sorter.
+** One extra bucket is added to catch overflow in case something
+** ever changes to make the previous sentence incorrect.
*/
-#define N_SORT_BUCKET_ALLOC 25
-#define N_SORT_BUCKET 25
-#ifdef SQLITE_TEST
- int sqlite3_pager_n_sort_bucket = 0;
- #undef N_SORT_BUCKET
- #define N_SORT_BUCKET \
- (sqlite3_pager_n_sort_bucket?sqlite3_pager_n_sort_bucket:N_SORT_BUCKET_ALLOC)
-#endif
+#define N_SORT_BUCKET 32
static PgHdr *pcacheSortDirtyList(PgHdr *pIn){
- PgHdr *a[N_SORT_BUCKET_ALLOC], *p;
+ PgHdr *a[N_SORT_BUCKET], *p;
int i;
memset(a, 0, sizeof(a));
while( pIn ){
p = pIn;
pIn = p->pDirty;
p->pDirty = 0;
- for(i=0; i<N_SORT_BUCKET-1; i++){
+ for(i=0; ALWAYS(i<N_SORT_BUCKET-1); i++){
if( a[i]==0 ){
a[i] = p;
break;
@@ -496,11 +494,9 @@ static PgHdr *pcacheSortDirtyList(PgHdr *pIn){
a[i] = 0;
}
}
- if( i==N_SORT_BUCKET-1 ){
- /* Coverage: To get here, there need to be 2^(N_SORT_BUCKET)
- ** elements in the input list. This is possible, but impractical.
- ** Testing this line is the point of global variable
- ** sqlite3_pager_n_sort_bucket.
+ if( NEVER(i==N_SORT_BUCKET-1) ){
+ /* To get here, there need to be 2^(N_SORT_BUCKET) elements in
+ ** the input list. But that is impossible.
*/
a[i] = pcacheMergeDirtyList(a[i], p);
}
diff --git a/src/pcache1.c b/src/pcache1.c
index 1bff0e532..c02e16633 100644
--- a/src/pcache1.c
+++ b/src/pcache1.c
@@ -16,7 +16,7 @@
** If the default page cache implementation is overriden, then neither of
** these two features are available.
**
-** @(#) $Id: pcache1.c,v 1.17 2009/06/09 18:58:53 shane Exp $
+** @(#) $Id: pcache1.c,v 1.18 2009/07/16 18:21:18 drh Exp $
*/
#include "sqliteInt.h"
@@ -655,7 +655,14 @@ static void pcache1Rekey(
pPage->pNext = pCache->apHash[h];
pCache->apHash[h] = pPage;
- if( iNew>pCache->iMaxKey ){
+ /* The xRekey() interface is only used to move pages earlier in the
+ ** database file (in order to move all free pages to the end of the
+ ** file where they can be truncated off.) Hence, it is not possible
+ ** for the new page number to be greater than the largest previously
+ ** fetched page. But we retain the following test in case xRekey()
+ ** begins to be used in different ways in the future.
+ */
+ if( NEVER(iNew>pCache->iMaxKey) ){
pCache->iMaxKey = iNew;
}
diff --git a/src/test2.c b/src/test2.c
index 0ea382830..43859c6d6 100644
--- a/src/test2.c
+++ b/src/test2.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test2.c,v 1.71 2009/06/18 17:22:39 drh Exp $
+** $Id: test2.c,v 1.72 2009/07/16 18:21:18 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -623,7 +623,6 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
extern int sqlite3_io_error_hardhit;
extern int sqlite3_diskfull_pending;
extern int sqlite3_diskfull;
- extern int sqlite3_pager_n_sort_bucket;
static struct {
char *zName;
Tcl_CmdProc *xProc;
@@ -668,7 +667,5 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
(char*)&sqlite3_diskfull, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_pending_byte",
(char*)&sqlite3PendingByte, TCL_LINK_INT | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "sqlite_pager_n_sort_bucket",
- (char*)&sqlite3_pager_n_sort_bucket, TCL_LINK_INT);
return TCL_OK;
}