예제 #1
0
 /*
 ** Free an allocated buffer obtained from pcache1Alloc().
 */
 static void pcache1Free(ref PgHdr p)
 {
     if (p == null)
     {
         return;
     }
     if (p.CacheAllocated)//if ( p >= pcache1.pStart && p < pcache1.pEnd )
     {
         PgFreeslot pSlot = new PgFreeslot();
         sqlite3_mutex_enter(pcache1.mutex);
         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
         pSlot._PgHdr  = p;// pSlot = (PgFreeslot)p;
         pSlot.pNext   = pcache1.pFree;
         pcache1.pFree = pSlot;
         pcache1.nFreeSlot++;
         pcache1.bUnderPressure = pcache1.nFreeSlot < pcache1.nReserve;
         Debug.Assert(pcache1.nFreeSlot <= pcache1.nSlot);
         sqlite3_mutex_leave(pcache1.mutex);
     }
     else
     {
         int iSize;
         Debug.Assert(sqlite3MemdebugHasType(p, MEMTYPE_PCACHE));
         sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
         iSize = sqlite3MallocSize(p.pData);
         sqlite3_mutex_enter(pcache1.mutex);
         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
         sqlite3_mutex_leave(pcache1.mutex);
         sqlite3_free(ref p.pData);
     }
 }
예제 #2
0
파일: pcache1_c.cs 프로젝트: ycaihua/rhodes
        /******************************************************************************/
        /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/

        /*
        ** This function is called during initialization if a static buffer is
        ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
        ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
        ** enough to contain 'n' buffers of 'sz' bytes each.
        */
        static void sqlite3PCacheBufferSetup(object pBuf, int sz, int n)
        {
            if (pcache1.isInit != 0)
            {
                PgFreeslot p;
                sz             = ROUNDDOWN8(sz);
                pcache1.szSlot = sz;
                pcache1.pStart = pBuf;
                pcache1.pFree  = null;
                while (n-- != 0)
                {
                    p             = new PgFreeslot();// (PgFreeslot)pBuf;
                    p._PgHdr      = new PgHdr();
                    p.pNext       = pcache1.pFree;
                    pcache1.pFree = p;
                    //pBuf = (void*)&((char*)pBuf)[sz];
                }
                pcache1.pEnd = pBuf;
            }
        }
예제 #3
0
 /*
 ** Free an allocated buffer obtained from pcache1Alloc().
 */
 static void pcache1Free(ref PgHdr p)
 {
     Debug.Assert(sqlite3_mutex_held(pcache1.mutex));
     if (p == null)
     {
         return;
     }
     if (p.CacheAllocated) //if ( p >= pcache1.pStart && p < pcache1.pEnd )
     {
         PgFreeslot pSlot = new PgFreeslot();
         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
         pSlot._PgHdr  = p;// (PgFreeslot)p;
         pSlot.pNext   = pcache1.pFree;
         pcache1.pFree = pSlot;
     }
     else
     {
         int iSize = p.pData.Length; //sqlite3MallocSize( p );
         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
         p = null;                   //sqlite3_free( ref p );
     }
 }
예제 #4
0
        /******************************************************************************/
        /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/

        /*
        ** This function is called during initialization if a static buffer is
        ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
        ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
        ** enough to contain 'n' buffers of 'sz' bytes each.
        **
        ** This routine is called from sqlite3_initialize() and so it is guaranteed
        ** to be serialized already.  There is no need for further mutexing.
        */
        static void sqlite3PCacheBufferSetup(object pBuf, int sz, int n)
        {
            if (pcache1.isInit)
            {
                PgFreeslot p;
                sz                     = ROUNDDOWN8(sz);
                pcache1.szSlot         = sz;
                pcache1.nSlot          = pcache1.nFreeSlot = n;
                pcache1.nReserve       = n > 90 ? 10 : (n / 10 + 1);
                pcache1.pStart         = null;
                pcache1.pEnd           = null;
                pcache1.pFree          = null;
                pcache1.bUnderPressure = false;
                while (n-- > 0)
                {
                    p             = new PgFreeslot();// (PgFreeslot)pBuf;
                    p._PgHdr      = new PgHdr();
                    p.pNext       = pcache1.pFree;
                    pcache1.pFree = p;
                    //pBuf = (void)&((char)pBuf)[sz];
                }
                pcache1.pEnd = pBuf;
            }
        }
예제 #5
0
 /*
 ** Free an allocated buffer obtained from pcache1Alloc().
 */
 static void pcache1Free( ref PgHdr p )
 {
   Debug.Assert( sqlite3_mutex_held( pcache1.mutex ) );
   if ( p == null ) return;
   if ( p.CacheAllocated ) //if ( p >= pcache1.pStart && p < pcache1.pEnd )
   {
     PgFreeslot pSlot = new PgFreeslot();
     sqlite3StatusAdd( SQLITE_STATUS_PAGECACHE_USED, -1 );
     pSlot._PgHdr = p;// (PgFreeslot)p;
     pSlot.pNext = pcache1.pFree;
     pcache1.pFree = pSlot;
   }
   else
   {
     int iSize = sqlite3MallocSize(p.pData);
     sqlite3StatusAdd( SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize );
     sqlite3_free(ref p.pData); 
     p = null;
   }
 }
예제 #6
0
    /******************************************************************************/
    /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/

    /*
    ** This function is called during initialization if a static buffer is
    ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
    ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
    ** enough to contain 'n' buffers of 'sz' bytes each.
    */
    static void sqlite3PCacheBufferSetup( object pBuf, int sz, int n )
    {
      if ( pcache1.isInit != 0 )
      {
        PgFreeslot p;
        sz = ROUNDDOWN8( sz );
        pcache1.szSlot = sz;
        pcache1.pStart = pBuf;
        pcache1.pFree = null;
        while ( n-- != 0 )
        {
          p = new PgFreeslot();// (PgFreeslot)pBuf;
          p._PgHdr = new PgHdr();
          p.pNext = pcache1.pFree;
          pcache1.pFree = p;
          //pBuf = (void*)&((char*)pBuf)[sz];
        }
        pcache1.pEnd = pBuf;
      }
    }