Changeset 301 for trunk/thune/gc.c

Show
Ignore:
Timestamp:
10/23/06 04:19:31 (2 years ago)
Author:
krobillard
Message:

Thune - Added UBuffer & shader! datatype.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/gc.c

    r300 r301  
    145145 
    146146 
     147static void _freeBuffer( UrlanEnv* env, UGCArray* agc, UBuffer* buf ) 
     148{ 
     149    int idx = ((int) buf->dataType) - UT_BI_COUNT; 
     150    if( idx >= 0 ) 
     151        env->customDT[ idx ].gcDestroyBuffer( buf ); 
     152 
     153    // Flag as unused. 
     154    buf->dataType = UT_UNSET; 
     155 
     156    // Link to free list. 
     157    buf->link = agc->freeList; 
     158    agc->freeList = buf - ((UBuffer*) agc->arr.ptr.v); 
     159 
     160    agc->freeCount += 1; 
     161} 
     162 
     163 
     164#define FREE_BUFFER(buf) \ 
     165    btmp = buf; \ 
     166    if( btmp->dataType != UT_UNSET ) \ 
     167        _freeBuffer( env, agc, btmp ); 
     168 
     169static void _sweepBuffers( UrlanEnv* env, UArray* mark, UGCArray* agc ) 
     170{ 
     171    UBuffer* btmp; 
     172    UBuffer* ait = (UBuffer*) agc->arr.ptr.v; 
     173    uint8_t* it  = mark->ptr.b; 
     174    uint8_t* end = it + mark->used; 
     175 
     176 
     177    // Mark padding bits at end as used. 
     178    { 
     179    int padBits = agc->arr.used & 7; 
     180    if( padBits ) 
     181        end[-1] |= 0xff << padBits; 
     182    } 
     183 
     184    // Check mark bitset for unused elements. 
     185    while( it != end ) 
     186    { 
     187        if( *it != 0xff ) 
     188        { 
     189            int mask = *it; 
     190 
     191            if( (mask & 0x0f) != 0x0f ) 
     192            { 
     193                if( (mask & 0x01) == 0 ) { FREE_BUFFER( ait ) } 
     194                if( (mask & 0x02) == 0 ) { FREE_BUFFER( ait + 1 ) } 
     195                if( (mask & 0x04) == 0 ) { FREE_BUFFER( ait + 2 ) } 
     196                if( (mask & 0x08) == 0 ) { FREE_BUFFER( ait + 3 ) } 
     197            } 
     198 
     199            if( (mask & 0xf0) != 0xf0 ) 
     200            { 
     201                if( (mask & 0x10) == 0 ) { FREE_BUFFER( ait + 4 ) } 
     202                if( (mask & 0x20) == 0 ) { FREE_BUFFER( ait + 5 ) } 
     203                if( (mask & 0x40) == 0 ) { FREE_BUFFER( ait + 6 ) } 
     204                if( (mask & 0x80) == 0 ) { FREE_BUFFER( ait + 7 ) } 
     205            } 
     206        } 
     207        ++it; 
     208        ait += 8; 
     209    } 
     210} 
     211 
    147212 
    148213static UCollector _gc; 
    149  
    150 #define bsBlk       _gc.bsBlock 
    151 #define bsStr       _gc.bsBin 
    152214 
    153215 
     
    156218#define SET_BIT_BLOCK(bn) \ 
    157219    idx = bn - env->blocks.sweepStart; \ 
    158     if( idx >= 0 ) ur_setBit( bsBlk.ptr.b, idx ); 
     220    if( idx >= 0 ) ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    159221 
    160222#define SET_BIT_BIN(bn) \ 
    161223    idx = bn - env->bin.sweepStart; \ 
    162     if( idx >= 0 ) ur_setBit( bsStr.ptr.b, idx ); 
     224    if( idx >= 0 ) ur_setBit( _gc.bsBin.ptr.b, idx ); 
    163225 
    164226#define SWEEP_START_BLOCK   env->blocks.sweepStart 
     
    168230 
    169231#define SET_BIT_BLOCK(bn) \ 
    170     idx = bn; ur_setBit( bsBlk.ptr.b, idx ); 
     232    idx = bn; ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    171233 
    172234#define SET_BIT_BIN(bn) \ 
    173     idx = bn; ur_setBit( bsStr.ptr.b, idx ); 
     235    idx = bn; ur_setBit( _gc.bsBin.ptr.b, idx ); 
    174236 
    175237#define SWEEP_START_BLOCK   0 
     
    188250{ 
    189251    ur_setBit( gc->bsBlock.ptr.b, idx ); 
     252} 
     253 
     254 
     255void ur_gcMarkBuffer( UCollector* gc, UIndex idx ) 
     256{ 
     257    ur_setBit( gc->bsBuf.ptr.b, idx ); 
    190258} 
    191259 
     
    261329                    int ai   = idx >> 3; 
    262330                    int bitm = 1 << (idx & 7); 
    263                     bsBlk.ptr.b[ ai ] |= bitm; 
     331                    _gc.bsBlock.ptr.b[ ai ] |= bitm; 
    264332                    _gc.blkChecked.ptr.b[ ai ] |= bitm; 
    265333                } 
     
    273341                idx = it->func.closureN; 
    274342                if( idx ) 
    275                     ur_setBit( bsBlk.ptr.b, idx ); 
     343                    ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    276344 
    277345                idx = it->func.sigN; 
    278346                if( idx ) 
    279                     ur_setBit( bsBlk.ptr.b, idx ); 
     347                    ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    280348                break; 
    281349 
     
    293361                    int ai   = idx >> 3; 
    294362                    int bitm = 1 << (idx & 7); 
    295                     bsBlk.ptr.b[ ai ] |= bitm; 
     363                    _gc.bsBlock.ptr.b[ ai ] |= bitm; 
    296364                    if( ! (_gc.blkChecked.ptr.b[ ai ] & bitm) ) 
    297365                    { 
     
    319387                idx = it->err.messageStr; 
    320388                if( idx ) 
    321                     ur_setBit( bsStr.ptr.b, idx ); 
     389                    ur_setBit( _gc.bsBin.ptr.b, idx ); 
    322390 
    323391                idx = it->err.traceBlk; 
    324392                if( idx ) 
    325                     ur_setBit( bsBlk.ptr.b, idx ); 
     393                    ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    326394                break; 
    327395 
     
    399467                idx = it->func.sigN; 
    400468                if( idx ) 
    401                     ur_setBit( bsBlk.ptr.b, idx ); 
     469                    ur_setBit( _gc.bsBlock.ptr.b, idx ); 
    402470                it -= CC_LEN_FUNC; 
    403471                break; 
     
    548616    GC_BITSET( _gc.blkChecked, env->blocks, SWEEP_START_BLOCK ); 
    549617 
    550     GC_BITSET( bsBlk, env->blocks,      SWEEP_START_BLOCK ); 
    551     GC_BITSET( bsStr, env->bin,         SWEEP_START_BIN ); 
     618    GC_BITSET( _gc.bsBlock, env->blocks,    SWEEP_START_BLOCK ); 
     619    GC_BITSET( _gc.bsBin,   env->bin,       SWEEP_START_BIN ); 
     620    GC_BITSET( _gc.bsBuf,   env->buffers,   0 ); 
    552621 
    553622#ifdef PAIRPOOL_H 
     
    585654    ur_setBit( doneset, GLOBAL_WORD_BLKN ); 
    586655 
    587     ur_setBit( bsBlk.ptr.b, GLOBAL_VAL_BLKN ); 
    588     ur_setBit( bsBlk.ptr.b, GLOBAL_WORD_BLKN ); 
    589  
    590  
    591     ur_setBit( bsStr.ptr.b, BIN_ATOM_NAMES ); 
     656    ur_setBit( _gc.bsBlock.ptr.b, GLOBAL_VAL_BLKN ); 
     657    ur_setBit( _gc.bsBlock.ptr.b, GLOBAL_WORD_BLKN ); 
     658 
     659 
     660    ur_setBit( _gc.bsBin.ptr.b, BIN_ATOM_NAMES ); 
    592661 
    593662 
     
    627696 
    628697        i = 0; 
    629         markset = bsBlk.ptr.b; 
     698        markset = _gc.bsBlock.ptr.b; 
    630699        doneset = _gc.blkChecked.ptr.b; 
    631700 
     
    674743#endif 
    675744 
    676     _sweepArray( &bsBlk, &env->blocks ); 
    677     _sweepArray( &bsStr, &env->bin ); 
     745    _sweepBuffers( env, &_gc.bsBuf, &env->buffers ); 
     746    _sweepArray( &_gc.bsBlock, &env->blocks ); 
     747    _sweepArray( &_gc.bsBin,   &env->bin ); 
    678748 
    679749    ur_arrayFree( &_gc.blkChecked ); 
    680750 
    681     ur_arrayFree( &bsBlk ); 
    682     ur_arrayFree( &bsStr ); 
     751    ur_arrayFree( &_gc.bsBuf ); 
     752    ur_arrayFree( &_gc.bsBlock ); 
     753    ur_arrayFree( &_gc.bsBin ); 
    683754 
    684755#ifdef GC_TIME