Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -1270,11 +1270,19 @@ ** opened. Any outstanding pages are invalidated and subsequent attempts ** to access those pages will likely result in a coredump. */ static void pager_reset(Pager *pPager){ PgHdr *pPg, *pNext; +#ifndef SQLITE_MUTEX_NOOP + sqlite3_mutex *mutex; +#endif if( pPager->errCode ) return; +#ifndef SQLITE_MUTEX_NOOP + mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2); + sqlite3_mutex_enter(mutex); +#endif + for(pPg=pPager->pAll; pPg; pPg=pNext){ IOTRACE(("PGFREE %p %d\n", pPager, pPg->pgno)); PAGER_INCR(sqlite3_pager_pgfree_count); pNext = pPg->pNextAll; lruListRemove(pPg); @@ -1290,10 +1298,11 @@ pPager->nHash = 0; sqlite3_free(pPager->aHash); pPager->nPage = 0; pPager->aHash = 0; pPager->nRef = 0; + sqlite3_mutex_leave(mutex); } /* ** Unlock the database file. ** @@ -2634,10 +2643,15 @@ */ static void pager_truncate_cache(Pager *pPager){ PgHdr *pPg; PgHdr **ppPg; int dbSize = pPager->dbSize; +#ifndef SQLITE_MUTEX_NOOP + sqlite3_mutex *mutex; + mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2); +#endif + sqlite3_mutex_enter(mutex); ppPg = &pPager->pAll; while( (pPg = *ppPg)!=0 ){ if( pPg->pgno<=dbSize ){ ppPg = &pPg->pNextAll; @@ -2653,10 +2667,11 @@ sqlite3_free(pPg->pData); sqlite3_free(pPg); pPager->nPage--; } } + sqlite3_mutex_leave(mutex); } /* ** Try to obtain a lock on a file. Invoke the busy callback if the lock ** is currently not available. Repeat until the busy callback returns