Home | History | Annotate | Download | only in dist

Lines Matching defs:mem3

21446 /************** Begin file mem3.c ********************************************/
21511 ** We often identify a chunk by its index in mem3.aPool[]. When
21519 ** Pointers to the head of the list are stored in mem3.aiSmall[]
21520 ** for smaller chunks and mem3.aiHash[] for larger chunks.
21534 u32 next; /* Index in mem3.aPool[] of next free chunk */
21535 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
21542 ** into a single structure named "mem3". This is to keep the
21585 } mem3 = { 97535575 };
21587 #define mem3 GLOBAL(struct Mem3Global, mem3)
21590 ** Unlink the chunk at mem3.aPool[i] from list it is currently
21594 u32 next = mem3.aPool[i].u.list.next;
21595 u32 prev = mem3.aPool[i].u.list.prev;
21596 assert( sqlite3_mutex_held(mem3.mutex) );
21600 mem3.aPool[prev].u.list.next = next;
21603 mem3.aPool[next].u.list.prev = prev;
21605 mem3.aPool[i].u.list.next = 0;
21606 mem3.aPool[i].u.list.prev = 0;
21615 assert( sqlite3_mutex_held(mem3.mutex) );
21616 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
21618 size = mem3.aPool[i-1].u.hdr.size4x/4;
21619 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
21622 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
21625 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
21630 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
21634 assert( sqlite3_mutex_held(mem3.mutex) );
21635 mem3.aPool[i].u.list.next = *pRoot;
21636 mem3.aPool[i].u.list.prev = 0;
21638 mem3.aPool[*pRoot].u.list.prev = i;
21649 assert( sqlite3_mutex_held(mem3.mutex) );
21651 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
21652 size = mem3.aPool[i-1].u.hdr.size4x/4;
21653 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
21656 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
21659 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
21669 mem3.mutex==0 ){
21670 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
21672 sqlite3_mutex_enter(mem3.mutex);
21675 sqlite3_mutex_leave(mem3.mutex);
21682 if( !mem3.alarmBusy ){
21683 mem3.alarmBusy = 1;
21684 assert( sqlite3_mutex_held(mem3.mutex) );
21685 sqlite3_mutex_leave(mem3.mutex);
21687 sqlite3_mutex_enter(mem3.mutex);
21688 mem3.alarmBusy = 0;
21700 assert( sqlite3_mutex_held(mem3.mutex) );
21702 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
21703 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
21704 x = mem3.aPool[i-1].u.hdr.size4x;
21705 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
21706 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
21707 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
21708 return &mem3.aPool[i];
21712 ** Carve a piece off of the end of the mem3.iMaster free chunk.
21717 assert( sqlite3_mutex_held(mem3.mutex) );
21718 assert( mem3.szMaster>=nBlock );
21719 if( nBlock>=mem3.szMaster-1 ){
21721 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
21722 mem3.iMaster = 0;
21723 mem3.szMaster = 0;
21724 mem3.mnMaster = 0;
21729 newi = mem3.iMaster + mem3.szMaster - nBlock;
21730 assert( newi > mem3.iMaster+1 );
21731 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
21732 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
21733 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
21734 mem3.szMaster -= nBlock;
21735 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
21736 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21737 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
21738 if( mem3.szMaster < mem3.mnMaster ){
21739 mem3.mnMaster = mem3.szMaster;
21741 return (void*)&mem3.aPool[newi];
21748 ** mem3.aiSmall[] or mem3.aiHash[].
21753 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
21754 ** the current mem3.iMaster with the new larger chunk. In order for
21755 ** this mem3.iMaster replacement to work, the master chunk must be
21764 assert( sqlite3_mutex_held(mem3.mutex) );
21766 iNext = mem3.aPool[i].u.list.next;
21767 size = mem3.aPool[i-1].u.hdr.size4x;
21771 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
21772 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
21774 iNext = mem3.aPool[prev].u.list.next;
21778 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
21779 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
21780 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
21786 if( size>mem3.szMaster ){
21787 mem3.iMaster = i;
21788 mem3.szMaster = size;
21805 assert( sqlite3_mutex_held(mem3.mutex) );
21820 i = mem3.aiSmall[nBlock-2];
21822 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
21827 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
21828 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
21829 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
21839 if( mem3.szMaster>=nBlock ){
21851 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
21853 if( mem3.iMaster ){
21854 memsys3Link(mem3.iMaster);
21855 mem3.iMaster = 0;
21856 mem3.szMaster = 0;
21859 memsys3Merge(&mem3.aiHash[i]);
21862 memsys3Merge(&mem3.aiSmall[i]);
21864 if( mem3.szMaster ){
21865 memsys3Unlink(mem3.iMaster);
21866 if( mem3.szMaster>=nBlock ){
21886 assert( sqlite3_mutex_held(mem3.mutex) );
21887 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
21888 i = p - mem3.aPool;
21889 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
21890 size = mem3.aPool[i-1].u.hdr.size4x/4;
21891 assert( i+size<=mem3.nPool+1 );
21892 mem3.aPool[i-1].u.hdr.size4x &= ~1;
21893 mem3.aPool[i+size-1].u.hdr.prevSize = size;
21894 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
21898 if( mem3.iMaster ){
21899 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
21900 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
21901 mem3.iMaster -= size;
21902 mem3.szMaster += size;
21903 memsys3Unlink(mem3.iMaster);
21904 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21905 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
21906 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
21908 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21909 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
21910 memsys3Unlink(mem3.iMaster+mem3.szMaster);
21911 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
21912 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
21913 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
22004 /* Store a pointer to the memory block in global structure mem3. */
22006 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
22007 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
22010 mem3.szMaster = mem3.nPool;
22011 mem3.mnMaster = mem3.szMaster;
22012 mem3.iMaster = 1;
22013 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
22014 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
22015 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
22025 mem3.mutex = 0;
22052 for(i=1; i<=mem3.nPool; i+=size/4){
22053 size = mem3.aPool[i-1].u.hdr.size4x;
22055 fprintf(out, "%p size error\n", &mem3.aPool[i]);
22059 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
22060 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
22064 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
22065 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
22070 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
22072 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
22073 i==mem3.iMaster ? " **master**" : "");
22077 if( mem3.aiSmall[i]==0 ) continue;
22079 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
22080 fprintf(out, " %p(%d)", &mem3.aPool[j],
22081 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
22086 if( mem3.aiHash[i]==0 ) continue;
22088 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
22089 fprintf(out, " %p(%d)", &mem3.aPool[j],
22090 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
22094 fprintf(out, "master=%d\n", mem3.iMaster);
22095 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
22096 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
22097 sqlite3_mutex_leave(mem3.mutex);
22135 /************** End of mem3.c ************************************************/