Mercurial > projects > ldc
annotate tango/lib/gc/basic/gc.d @ 262:88252a1af660 trunk
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
author | lindquist |
---|---|
date | Sat, 14 Jun 2008 05:13:49 +0200 |
parents | 4d006f7b2ada |
children | 2b72433d5c8c |
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 |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
243
diff
changeset
|
73 // FIXME: LLVMDC crashes ... |
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
243
diff
changeset
|
74 //_gc.fullCollectNoStack(); // not really a 'collect all' -- still scans |
132 | 75 // static data area, roots, and ranges. |
76 _gc.Dtor(); | |
77 } | |
78 | |
79 extern (C) void gc_enable() | |
80 { | |
81 _gc.enable(); | |
82 } | |
83 | |
84 extern (C) void gc_disable() | |
85 { | |
86 _gc.disable(); | |
87 } | |
88 | |
89 extern (C) void gc_collect() | |
90 { | |
91 _gc.fullCollect(); | |
92 } | |
93 | |
94 extern (C) uint gc_getAttr( void* p ) | |
95 { | |
96 return _gc.getAttr( p ); | |
97 } | |
98 | |
99 extern (C) uint gc_setAttr( void* p, uint a ) | |
100 { | |
101 return _gc.setAttr( p, a ); | |
102 } | |
103 | |
104 extern (C) uint gc_clrAttr( void* p, uint a ) | |
105 { | |
106 return _gc.clrAttr( p, a ); | |
107 } | |
108 | |
109 extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) | |
110 { | |
111 return _gc.malloc( sz, ba ); | |
112 } | |
113 | |
114 extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) | |
115 { | |
116 return _gc.calloc( sz, ba ); | |
117 } | |
118 | |
119 extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 ) | |
120 { | |
121 return _gc.realloc( p, sz, ba ); | |
122 } | |
123 | |
124 extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ) | |
125 { | |
126 return _gc.extend( p, mx, sz ); | |
127 } | |
128 | |
129 extern (C) void gc_free( void* p ) | |
130 { | |
131 _gc.free( p ); | |
132 } | |
133 | |
134 extern (C) void* gc_addrOf( void* p ) | |
135 { | |
136 return _gc.addrOf( p ); | |
137 } | |
138 | |
139 extern (C) size_t gc_sizeOf( void* p ) | |
140 { | |
141 return _gc.sizeOf( p ); | |
142 } | |
143 | |
144 extern (C) BlkInfo gc_query( void* p ) | |
145 { | |
146 return _gc.query( p ); | |
147 } | |
148 | |
149 extern (C) void gc_addRoot( void* p ) | |
150 { | |
151 _gc.addRoot( p ); | |
152 } | |
153 | |
154 extern (C) void gc_addRange( void* p, size_t sz ) | |
155 { | |
156 _gc.addRange( p, sz ); | |
157 } | |
158 | |
159 extern (C) void gc_removeRoot( void *p ) | |
160 { | |
161 _gc.removeRoot( p ); | |
162 } | |
163 | |
164 extern (C) void gc_removeRange( void *p ) | |
165 { | |
166 _gc.removeRange( p ); | |
167 } |