Exemplo n.º 1
0
        private static PgHdr pcache1Alloc(int nByte)
        {
            PgHdr p = null;

            Debug.Assert(MutexEx.NotHeld(pcache1.grp.mutex));
            StatusEx.sqlite3StatusSet(StatusEx.STATUS.PAGECACHE_SIZE, nByte);
            if (nByte <= pcache1.szSlot)
            {
                MutexEx.Enter(pcache1.mutex);
                p = pcache1.pFree._PgHdr;
                if (p != null)
                {
                    pcache1.pFree = pcache1.pFree.pNext;
                    pcache1.nFreeSlot--;
                    pcache1.bUnderPressure = pcache1.nFreeSlot < pcache1.nReserve;
                    Debug.Assert(pcache1.nFreeSlot >= 0);
                    StatusEx.sqlite3StatusAdd(StatusEx.STATUS.PAGECACHE_USED, 1);
                }
                MutexEx.Leave(pcache1.mutex);
            }
            if (p == null)
            {
                // Memory is not available in the SQLITE_CONFIG_PAGECACHE pool.  Get it from sqlite3Malloc instead.
                p = new PgHdr();
                {
                    var sz = nByte;
                    MutexEx.Enter(pcache1.mutex);
                    StatusEx.sqlite3StatusAdd(StatusEx.STATUS.PAGECACHE_OVERFLOW, sz);
                    MutexEx.Leave(pcache1.mutex);
                }
                SysEx.sqlite3MemdebugSetType(p, SysEx.MEMTYPE.PCACHE);
            }
            return(p);
        }
Exemplo n.º 2
0
 private static void pcache1Free(ref PgHdr p)
 {
     if (p == null)
     {
         return;
     }
     if (p.CacheAllocated)
     {
         var pSlot = new PgFreeslot();
         MutexEx.Enter(pcache1.mutex);
         StatusEx.sqlite3StatusAdd(StatusEx.STATUS.PAGECACHE_USED, -1);
         pSlot._PgHdr  = p;
         pSlot.pNext   = pcache1.pFree;
         pcache1.pFree = pSlot;
         pcache1.nFreeSlot++;
         pcache1.bUnderPressure = pcache1.nFreeSlot < pcache1.nReserve;
         Debug.Assert(pcache1.nFreeSlot <= pcache1.nSlot);
         MutexEx.Leave(pcache1.mutex);
     }
     else
     {
         Debug.Assert(SysEx.sqlite3MemdebugHasType(p, SysEx.MEMTYPE.PCACHE));
         SysEx.sqlite3MemdebugSetType(p, SysEx.MEMTYPE.HEAP);
         var iSize = MallocEx.sqlite3MallocSize(p.Data);
         MutexEx.Enter(pcache1.mutex);
         StatusEx.sqlite3StatusAdd(StatusEx.STATUS.PAGECACHE_OVERFLOW, -iSize);
         MutexEx.Leave(pcache1.mutex);
         MallocEx.sqlite3_free(ref p.Data);
     }
 }
Exemplo n.º 3
0
 private static int pcache1MemSize(object p)
 {
     if (p >= pcache1.pStart && p < pcache1.pEnd)
     {
         return(pcache1.szSlot);
     }
     else
     {
         Debug.Assert(SysEx.sqlite3MemdebugHasType(p, SysEx.MEMTYPE.PCACHE));
         SysEx.sqlite3MemdebugSetType(p, SysEx.MEMTYPE.HEAP);
         var iSize = SysEx.sqlite3MallocSize(p);
         SysEx.sqlite3MemdebugSetType(p, SysEx.MEMTYPE.PCACHE);
         return(iSize);
     }
 }