Mercurial > projects > ldc
comparison tango/lib/gc/basic/gc.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children | 7816aafeea3c |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /** | |
2 * This module contains the garbage collector front-end. | |
3 * | |
4 * Copyright: Copyright (C) 2005-2006 Digital Mars, www.digitalmars.com. | |
5 * All rights reserved. | |
6 * License: | |
7 * This software is provided 'as-is', without any express or implied | |
8 * warranty. In no event will the authors be held liable for any damages | |
9 * arising from the use of this software. | |
10 * | |
11 * Permission is granted to anyone to use this software for any purpose, | |
12 * including commercial applications, and to alter it and redistribute it | |
13 * freely, in both source and binary form, subject to the following | |
14 * restrictions: | |
15 * | |
16 * o The origin of this software must not be misrepresented; you must not | |
17 * claim that you wrote the original software. If you use this software | |
18 * in a product, an acknowledgment in the product documentation would be | |
19 * appreciated but is not required. | |
20 * o Altered source versions must be plainly marked as such, and must not | |
21 * be misrepresented as being the original software. | |
22 * o This notice may not be removed or altered from any source | |
23 * distribution. | |
24 * Authors: Walter Bright, Sean Kelly | |
25 */ | |
26 | |
27 private import gcx; | |
28 private import tango.stdc.stdlib; | |
29 | |
30 version=GCCLASS; | |
31 | |
32 version (GCCLASS) | |
33 alias GC gc_t; | |
34 else | |
35 alias GC* gc_t; | |
36 | |
37 gc_t _gc; | |
38 | |
39 extern (C) void thread_init(); | |
40 | |
41 extern (C) void gc_init() | |
42 { | |
43 version (GCCLASS) | |
44 { void* p; | |
45 ClassInfo ci = GC.classinfo; | |
46 | |
47 p = tango.stdc.stdlib.malloc(ci.init.length); | |
48 (cast(byte*)p)[0 .. ci.init.length] = ci.init[]; | |
49 _gc = cast(GC)p; | |
50 } | |
51 else | |
52 { | |
53 _gc = cast(GC*) tango.stdc.stdlib.calloc(1, GC.sizeof); | |
54 } | |
55 _gc.initialize(); | |
56 // NOTE: The GC must initialize the thread library | |
57 // before its first collection. | |
58 thread_init(); | |
59 } | |
60 | |
61 extern (C) void gc_term() | |
62 { | |
63 // NOTE: There may be daemons threads still running when this routine is | |
64 // called. If so, cleaning memory out from under then is a good | |
65 // way to make them crash horribly. This probably doesn't matter | |
66 // much since the app is supposed to be shutting down anyway, but | |
67 // I'm disabling cleanup for now until I can think about it some | |
68 // more. | |
69 // | |
70 // NOTE: Due to popular demand, this has been re-enabled. It still has | |
71 // the problems mentioned above though, so I guess we'll see. | |
72 _gc.fullCollectNoStack(); // not really a 'collect all' -- still scans | |
73 // static data area, roots, and ranges. | |
74 _gc.Dtor(); | |
75 } | |
76 | |
77 extern (C) void gc_enable() | |
78 { | |
79 _gc.enable(); | |
80 } | |
81 | |
82 extern (C) void gc_disable() | |
83 { | |
84 _gc.disable(); | |
85 } | |
86 | |
87 extern (C) void gc_collect() | |
88 { | |
89 _gc.fullCollect(); | |
90 } | |
91 | |
92 extern (C) uint gc_getAttr( void* p ) | |
93 { | |
94 return _gc.getAttr( p ); | |
95 } | |
96 | |
97 extern (C) uint gc_setAttr( void* p, uint a ) | |
98 { | |
99 return _gc.setAttr( p, a ); | |
100 } | |
101 | |
102 extern (C) uint gc_clrAttr( void* p, uint a ) | |
103 { | |
104 return _gc.clrAttr( p, a ); | |
105 } | |
106 | |
107 extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) | |
108 { | |
109 return _gc.malloc( sz, ba ); | |
110 } | |
111 | |
112 extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) | |
113 { | |
114 return _gc.calloc( sz, ba ); | |
115 } | |
116 | |
117 extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 ) | |
118 { | |
119 return _gc.realloc( p, sz, ba ); | |
120 } | |
121 | |
122 extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ) | |
123 { | |
124 return _gc.extend( p, mx, sz ); | |
125 } | |
126 | |
127 extern (C) void gc_free( void* p ) | |
128 { | |
129 _gc.free( p ); | |
130 } | |
131 | |
132 extern (C) void* gc_addrOf( void* p ) | |
133 { | |
134 return _gc.addrOf( p ); | |
135 } | |
136 | |
137 extern (C) size_t gc_sizeOf( void* p ) | |
138 { | |
139 return _gc.sizeOf( p ); | |
140 } | |
141 | |
142 extern (C) BlkInfo gc_query( void* p ) | |
143 { | |
144 return _gc.query( p ); | |
145 } | |
146 | |
147 extern (C) void gc_addRoot( void* p ) | |
148 { | |
149 _gc.addRoot( p ); | |
150 } | |
151 | |
152 extern (C) void gc_addRange( void* p, size_t sz ) | |
153 { | |
154 _gc.addRange( p, sz ); | |
155 } | |
156 | |
157 extern (C) void gc_removeRoot( void *p ) | |
158 { | |
159 _gc.removeRoot( p ); | |
160 } | |
161 | |
162 extern (C) void gc_removeRange( void *p ) | |
163 { | |
164 _gc.removeRange( p ); | |
165 } |