Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 513

Show
Ignore:
Timestamp:
01/16/11 07:14:56 (14 years ago)
Author:
walter
Message:

add gc_isCollecting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/gcstub/gc.d

    r441 r513  
    2121/*          Copyright Sean Kelly 2005 - 2009. 
    2222 * Distributed under the Boost Software License, Version 1.0. 
    2323 *    (See accompanying file LICENSE_1_0.txt or copy at 
    2424 *          http://www.boost.org/LICENSE_1_0.txt) 
    2525 */ 
    2626module gc.gc; 
    2727 
    2828private 
    2929{ 
    3030   import core.stdc.stdlib; 
     31   import core.stdc.stdio; 
    3132 
    3233   enum BlkAttr : uint 
    3334    { 
    3435        FINALIZE    = 0b0000_0001, 
    3536        NO_SCAN     = 0b0000_0010, 
    3637        NO_MOVE     = 0b0000_0100, 
    3738        APPENDABLE  = 0b0000_1000, 
    3839        ALL_BITS    = 0b1111_1111 
    3940    } 
    4041 
     
    4849    extern (C) void thread_init(); 
    4950    extern (C) void onOutOfMemoryError(); 
    5051 
    5152    struct Proxy 
    5253    { 
    5354        extern (C) void function() gc_enable; 
    5455        extern (C) void function() gc_disable; 
    5556        extern (C) void function() gc_collect; 
    5657        extern (C) void function() gc_minimize; 
    5758 
     59        extern (C) bool function(void*) gc_isCollecting; 
    5860        extern (C) uint function(void*) gc_getAttr; 
    5961        extern (C) uint function(void*, uint) gc_setAttr; 
    6062        extern (C) uint function(void*, uint) gc_clrAttr; 
    6163 
    6264        extern (C) void*   function(size_t, uint) gc_malloc; 
    6365        extern (C) BlkInfo function(size_t, uint) gc_qalloc; 
    6466        extern (C) void*   function(size_t, uint) gc_calloc; 
    6567        extern (C) void*   function(void*, size_t, uint ba) gc_realloc; 
    6668        extern (C) size_t  function(void*, size_t, size_t) gc_extend; 
    6769        extern (C) size_t  function(size_t) gc_reserve; 
     
    8284    __gshared Proxy  pthis; 
    8385    __gshared Proxy* proxy; 
    8486 
    8587    void initProxy() 
    8688    { 
    8789        pthis.gc_enable = &gc_enable; 
    8890        pthis.gc_disable = &gc_disable; 
    8991        pthis.gc_collect = &gc_collect; 
    9092        pthis.gc_minimize = &gc_minimize; 
    9193 
     94        pthis.gc_isCollecting = &gc_isCollecting; 
    9295        pthis.gc_getAttr = &gc_getAttr; 
    9396        pthis.gc_setAttr = &gc_setAttr; 
    9497        pthis.gc_clrAttr = &gc_clrAttr; 
    9598 
    9699        pthis.gc_malloc = &gc_malloc; 
    97100        pthis.gc_qalloc = &gc_qalloc; 
    98101        pthis.gc_calloc = &gc_calloc; 
    99102        pthis.gc_realloc = &gc_realloc; 
    100103        pthis.gc_extend = &gc_extend; 
    101104        pthis.gc_reserve = &gc_reserve; 
     
    161164    return proxy.gc_collect(); 
    162165} 
    163166 
    164167extern (C) void gc_minimize() 
    165168{ 
    166169    if( proxy is null ) 
    167170        return; 
    168171    return proxy.gc_minimize(); 
    169172} 
    170173 
     174extern (C) bool gc_isCollecting( void* p ) 
     175{ 
     176    if( proxy is null ) 
     177        return false; 
     178    return proxy.gc_isCollecting( p ); 
     179} 
     180 
    171181extern (C) uint gc_getAttr( void* p ) 
    172182{ 
    173183    if( proxy is null ) 
    174184        return 0; 
    175185    return proxy.gc_getAttr( p ); 
    176186} 
    177187 
    178188extern (C) uint gc_setAttr( void* p, uint a ) 
    179189{ 
    180190    if( proxy is null ) 
     
    286296extern (C) void gc_addRoot( void* p ) 
    287297{ 
    288298    if( proxy is null ) 
    289299    { 
    290300        void** r = cast(void**) realloc( roots, 
    291301                                         (nroots+1) * roots[0].sizeof ); 
    292302        if( r is null ) 
    293303            onOutOfMemoryError(); 
    294304        r[nroots++] = p; 
    295305        roots = r; 
    296  
     306    assert(0);  // fix 
    297307    } 
    298308    return proxy.gc_addRoot( p ); 
    299309} 
    300310 
    301311extern (C) void gc_addRange( void* p, size_t sz ) 
    302312{ 
     313    //printf("gcstub::gc_addRange() proxy = %p\n", proxy); 
    303314    if( proxy is null ) 
    304315    { 
    305316        Range* r = cast(Range*) realloc( ranges, 
    306317                                         (nranges+1) * ranges[0].sizeof ); 
    307318        if( r is null ) 
    308319            onOutOfMemoryError(); 
    309320        r[nranges].pos = p; 
    310321        r[nranges].len = sz; 
    311322        ranges = r; 
    312323        ++nranges; 
     324    assert(0);  // fix 
    313325    } 
    314326    return proxy.gc_addRange( p, sz ); 
    315327} 
    316328 
    317329extern (C) void gc_removeRoot( void *p ) 
    318330{ 
    319331    if( proxy is null ) 
    320332    { 
    321333        for( size_t i = 0; i < nroots; ++i ) 
    322334        {