Mercurial > projects > ldc
annotate tango/lib/gc/basic/gc.d @ 305:2b72433d5c8c trunk
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
Fixed problems with label collisions when using labels inside inline asm. LabelStatement is now easily reached given its
Identifier, which should be useful elsewhere too.
Enabled inline asm for building the lib/compiler/llvmdc runtime code, fixing branches out of asm makes this possible.
author | lindquist |
---|---|
date | Fri, 27 Jun 2008 22:04:35 +0200 |
parents | 88252a1af660 |
children |
rev | line source |
---|---|
132 | 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. | |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
243
diff
changeset
|
72 |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
262
diff
changeset
|
73 _gc.fullCollectNoStack(); // not really a 'collect all' -- still scans |
132 | 74 // static data area, roots, and ranges. |
75 _gc.Dtor(); | |
76 } | |
77 | |
78 extern (C) void gc_enable() | |
79 { | |
80 _gc.enable(); | |
81 } | |
82 | |
83 extern (C) void gc_disable() | |
84 { | |
85 _gc.disable(); | |
86 } | |
87 | |
88 extern (C) void gc_collect() | |
89 { | |
90 _gc.fullCollect(); | |
91 } | |
92 | |
93 extern (C) uint gc_getAttr( void* p ) | |
94 { | |
95 return _gc.getAttr( p ); | |
96 } | |
97 | |
98 extern (C) uint gc_setAttr( void* p, uint a ) | |
99 { | |
100 return _gc.setAttr( p, a ); | |
101 } | |
102 | |
103 extern (C) uint gc_clrAttr( void* p, uint a ) | |
104 { | |
105 return _gc.clrAttr( p, a ); | |
106 } | |
107 | |
108 extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) | |
109 { | |
110 return _gc.malloc( sz, ba ); | |
111 } | |
112 | |
113 extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) | |
114 { | |
115 return _gc.calloc( sz, ba ); | |
116 } | |
117 | |
118 extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 ) | |
119 { | |
120 return _gc.realloc( p, sz, ba ); | |
121 } | |
122 | |
123 extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ) | |
124 { | |
125 return _gc.extend( p, mx, sz ); | |
126 } | |
127 | |
128 extern (C) void gc_free( void* p ) | |
129 { | |
130 _gc.free( p ); | |
131 } | |
132 | |
133 extern (C) void* gc_addrOf( void* p ) | |
134 { | |
135 return _gc.addrOf( p ); | |
136 } | |
137 | |
138 extern (C) size_t gc_sizeOf( void* p ) | |
139 { | |
140 return _gc.sizeOf( p ); | |
141 } | |
142 | |
143 extern (C) BlkInfo gc_query( void* p ) | |
144 { | |
145 return _gc.query( p ); | |
146 } | |
147 | |
148 extern (C) void gc_addRoot( void* p ) | |
149 { | |
150 _gc.addRoot( p ); | |
151 } | |
152 | |
153 extern (C) void gc_addRange( void* p, size_t sz ) | |
154 { | |
155 _gc.addRange( p, sz ); | |
156 } | |
157 | |
158 extern (C) void gc_removeRoot( void *p ) | |
159 { | |
160 _gc.removeRoot( p ); | |
161 } | |
162 | |
163 extern (C) void gc_removeRange( void *p ) | |
164 { | |
165 _gc.removeRange( p ); | |
166 } |