aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pager.c6
-rw-r--r--src/pcache.c47
2 files changed, 33 insertions, 20 deletions
diff --git a/src/pager.c b/src/pager.c
index c47ab4465..1903fb1e7 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.477 2008/08/23 18:53:08 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.478 2008/08/25 07:12:29 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -2442,6 +2442,10 @@ static int pagerStress(void *p, PgHdr *pPg){
Pager *pPager = (Pager *)p;
int rc = SQLITE_OK;
+ if( pPager->doNotSync ){
+ return SQLITE_OK;
+ }
+
assert( pPg->flags&PGHDR_DIRTY );
if( pPager->errCode==SQLITE_OK ){
if( pPg->flags&PGHDR_NEED_SYNC ){
diff --git a/src/pcache.c b/src/pcache.c
index 4c4d2538f..b26bc58b1 100644
--- a/src/pcache.c
+++ b/src/pcache.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file implements that page cache.
**
-** @(#) $Id: pcache.c,v 1.11 2008/08/23 18:53:08 danielk1977 Exp $
+** @(#) $Id: pcache.c,v 1.12 2008/08/25 07:12:29 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -455,6 +455,23 @@ static int pcachePageSize(PgHdr *p){
}
#endif
+static int pcacheRecyclePage(PgHdr *p, PCache *pCache){
+ assert( sqlite3_mutex_held(pcache.mutex_lru) );
+ assert( sqlite3_mutex_held(pcache.mutex_mem2) );
+
+ PCache *pC = p->pCache;
+ assert( pC->iInUseMM==0 );
+ pC->iInUseMM = 1;
+ if( pC->xStress && (pC->iInUseDB==0 || pC==pCache) ){
+ pcacheExitGlobal();
+ pC->xStress(pC->pStress, p);
+ pcacheEnterGlobal();
+ }
+ pC->iInUseMM = 0;
+
+ return (p->flags&PGHDR_DIRTY);
+}
+
/*
** Recycle a page from the global LRU list. If no page can be recycled,
** return NULL. Otherwise, the pointer returned points to a PgHdr
@@ -469,26 +486,18 @@ static PgHdr *pcacheRecycle(PCache *pCache){
assert( pcache.isInit );
assert( sqlite3_mutex_held(pcache.mutex_lru) );
- p = pcache.pLruSynced;
- if( !p ){
- p = pcache.pLruTail;
- }
- if( p && (p->flags&PGHDR_DIRTY) ){
- if( SQLITE_OK==sqlite3_mutex_try(pcache.mutex_mem2) ){
- PCache *pC = p->pCache;
- assert( pC->iInUseMM==0 );
- pC->iInUseMM = 1;
- if( pC->xStress && (pC->iInUseDB==0 || pC==pCache) ){
- pcacheExitGlobal();
- pC->xStress(pC->pStress, p);
- pcacheEnterGlobal();
+ if( SQLITE_OK==sqlite3_mutex_try(pcache.mutex_mem2) ){
+ p = pcache.pLruSynced;
+ while( p && (p->flags&PGHDR_DIRTY) && pcacheRecyclePage(p, pCache) ){
+ do { p = p->pPrevLru; } while( p && (p->flags&PGHDR_NEED_SYNC) );
+ }
+ if( !p ){
+ p = pcache.pLruTail;
+ while( p && (p->flags&PGHDR_DIRTY) && pcacheRecyclePage(p, pCache) ){
+ do { p = p->pPrevLru; } while( p && 0==(p->flags&PGHDR_NEED_SYNC) );
}
- pC->iInUseMM = 0;
- sqlite3_mutex_leave(pcache.mutex_mem2);
}
- }
- if( p && (p->flags&PGHDR_DIRTY) ){
- p = 0;
+ sqlite3_mutex_leave(pcache.mutex_mem2);
}
if( p ){