Changeset 513
- Timestamp:
- 01/16/11 07:14:56 (14 years ago)
- Files:
-
- trunk/src/gcstub/gc.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/gcstub/gc.d
r441 r513 21 21 /* Copyright Sean Kelly 2005 - 2009. 22 22 * Distributed under the Boost Software License, Version 1.0. 23 23 * (See accompanying file LICENSE_1_0.txt or copy at 24 24 * http://www.boost.org/LICENSE_1_0.txt) 25 25 */ 26 26 module gc.gc; 27 27 28 28 private 29 29 { 30 30 import core.stdc.stdlib; 31 import core.stdc.stdio; 31 32 32 33 enum BlkAttr : uint 33 34 { 34 35 FINALIZE = 0b0000_0001, 35 36 NO_SCAN = 0b0000_0010, 36 37 NO_MOVE = 0b0000_0100, 37 38 APPENDABLE = 0b0000_1000, 38 39 ALL_BITS = 0b1111_1111 39 40 } 40 41 … … 48 49 extern (C) void thread_init(); 49 50 extern (C) void onOutOfMemoryError(); 50 51 51 52 struct Proxy 52 53 { 53 54 extern (C) void function() gc_enable; 54 55 extern (C) void function() gc_disable; 55 56 extern (C) void function() gc_collect; 56 57 extern (C) void function() gc_minimize; 57 58 59 extern (C) bool function(void*) gc_isCollecting; 58 60 extern (C) uint function(void*) gc_getAttr; 59 61 extern (C) uint function(void*, uint) gc_setAttr; 60 62 extern (C) uint function(void*, uint) gc_clrAttr; 61 63 62 64 extern (C) void* function(size_t, uint) gc_malloc; 63 65 extern (C) BlkInfo function(size_t, uint) gc_qalloc; 64 66 extern (C) void* function(size_t, uint) gc_calloc; 65 67 extern (C) void* function(void*, size_t, uint ba) gc_realloc; 66 68 extern (C) size_t function(void*, size_t, size_t) gc_extend; 67 69 extern (C) size_t function(size_t) gc_reserve; … … 82 84 __gshared Proxy pthis; 83 85 __gshared Proxy* proxy; 84 86 85 87 void initProxy() 86 88 { 87 89 pthis.gc_enable = &gc_enable; 88 90 pthis.gc_disable = &gc_disable; 89 91 pthis.gc_collect = &gc_collect; 90 92 pthis.gc_minimize = &gc_minimize; 91 93 94 pthis.gc_isCollecting = &gc_isCollecting; 92 95 pthis.gc_getAttr = &gc_getAttr; 93 96 pthis.gc_setAttr = &gc_setAttr; 94 97 pthis.gc_clrAttr = &gc_clrAttr; 95 98 96 99 pthis.gc_malloc = &gc_malloc; 97 100 pthis.gc_qalloc = &gc_qalloc; 98 101 pthis.gc_calloc = &gc_calloc; 99 102 pthis.gc_realloc = &gc_realloc; 100 103 pthis.gc_extend = &gc_extend; 101 104 pthis.gc_reserve = &gc_reserve; … … 161 164 return proxy.gc_collect(); 162 165 } 163 166 164 167 extern (C) void gc_minimize() 165 168 { 166 169 if( proxy is null ) 167 170 return; 168 171 return proxy.gc_minimize(); 169 172 } 170 173 174 extern (C) bool gc_isCollecting( void* p ) 175 { 176 if( proxy is null ) 177 return false; 178 return proxy.gc_isCollecting( p ); 179 } 180 171 181 extern (C) uint gc_getAttr( void* p ) 172 182 { 173 183 if( proxy is null ) 174 184 return 0; 175 185 return proxy.gc_getAttr( p ); 176 186 } 177 187 178 188 extern (C) uint gc_setAttr( void* p, uint a ) 179 189 { 180 190 if( proxy is null ) … … 286 296 extern (C) void gc_addRoot( void* p ) 287 297 { 288 298 if( proxy is null ) 289 299 { 290 300 void** r = cast(void**) realloc( roots, 291 301 (nroots+1) * roots[0].sizeof ); 292 302 if( r is null ) 293 303 onOutOfMemoryError(); 294 304 r[nroots++] = p; 295 305 roots = r; 296 306 assert(0); // fix 297 307 } 298 308 return proxy.gc_addRoot( p ); 299 309 } 300 310 301 311 extern (C) void gc_addRange( void* p, size_t sz ) 302 312 { 313 //printf("gcstub::gc_addRange() proxy = %p\n", proxy); 303 314 if( proxy is null ) 304 315 { 305 316 Range* r = cast(Range*) realloc( ranges, 306 317 (nranges+1) * ranges[0].sizeof ); 307 318 if( r is null ) 308 319 onOutOfMemoryError(); 309 320 r[nranges].pos = p; 310 321 r[nranges].len = sz; 311 322 ranges = r; 312 323 ++nranges; 324 assert(0); // fix 313 325 } 314 326 return proxy.gc_addRange( p, sz ); 315 327 } 316 328 317 329 extern (C) void gc_removeRoot( void *p ) 318 330 { 319 331 if( proxy is null ) 320 332 { 321 333 for( size_t i = 0; i < nroots; ++i ) 322 334 {
