/* ** Deallocate a page */ static void pcachePageFree(PgHdr *p) { assert( sqlite3_mutex_held(pcache.mutex) ); if( p->pCache->bPurgeable ) { pcache.nCurrentPage--; } pcacheFree(p->apSave[0]); pcacheFree(p->apSave[1]); pcacheFree(p); }
/* ** Change the page number of page p to newPgno. If newPgno is 0, then the ** page object is added to the clean-list and the PGHDR_REUSE_UNLIKELY ** flag set. */ void sqlite3PcacheMove(PgHdr *p, Pgno newPgno) { assert( p->nRef>0 ); pcacheEnterMutex(); pcacheRemoveFromHash(p); p->pgno = newPgno; if( newPgno==0 ) { p->flags |= PGHDR_REUSE_UNLIKELY; pcacheFree(p->apSave[0]); pcacheFree(p->apSave[1]); p->apSave[0] = 0; p->apSave[1] = 0; if( (p->flags & PGHDR_DIRTY) ) { pcacheMakeClean(p); } } pcacheAddToHash(p); pcacheExitMutex(); }
/* ** Commit a change previously preserved. */ void sqlite3PcacheCommit(PCache *pCache, int idJournal) { PgHdr *p; pcacheEnterMutex(); /* Mutex is required to call pcacheFree() */ for(p=pCache->pDirty; p; p=p->pNext) { if( p->apSave[idJournal] ) { pcacheFree(p->apSave[idJournal]); p->apSave[idJournal] = 0; } } pcacheExitMutex(); }
/* ** Rollback a change previously preserved. */ void sqlite3PcacheRollback(PCache *pCache, int idJournal) { PgHdr *p; int sz; pcacheEnterMutex(); /* Mutex is required to call pcacheFree() */ sz = pCache->szPage; for(p=pCache->pDirty; p; p=p->pNext) { if( p->apSave[idJournal] ) { memcpy(p->pData, p->apSave[idJournal], sz); pcacheFree(p->apSave[idJournal]); p->apSave[idJournal] = 0; } } pcacheExitMutex(); }
void sqlite3PageFree(void *p){ pcacheEnterMutex(); pcacheFree(p); pcacheExitMutex(); }