PageRenderTime 40ms CodeModel.GetById 14ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/gc.d

http://github.com/wilkie/djehuty
D | 166 lines | 114 code | 44 blank | 8 comment | 0 complexity | 351c78c5aeb08a0741a5487a2a996c03 MD5 | raw file
  1/*
  2 * gc.d
  3 *
  4 * This module implements the D runtime functions for interfacing the
  5 * garbage collector.
  6 *
  7 */
  8
  9module runtime.gc;
 10
 11import synch.atomic;
 12
 13extern(C):
 14
 15import scaffold.system;
 16
 17void gc_init() {
 18	GarbageCollector._initialize();
 19}
 20
 21void gc_term() {
 22	GarbageCollector._terminate();
 23}
 24
 25void gc_enable() {
 26	GarbageCollector.enable();
 27}
 28
 29void gc_disable() {
 30	GarbageCollector.disable();
 31}
 32
 33void gc_collect() {
 34	GarbageCollector.collect();
 35}
 36
 37uint gc_getAttr(void* p) {
 38	return 0;
 39}
 40
 41uint gc_setAttr(void* p, uint a) {
 42	return 0;
 43}
 44
 45uint gc_clrAttr(void* p, uint a) {
 46	return 0;
 47}
 48
 49void* gc_malloc(size_t sz, uint ba = 0) {
 50	return GarbageCollector.malloc(sz).ptr;
 51}
 52
 53void* gc_calloc(size_t sz, uint ba = 0) {
 54	return GarbageCollector.calloc(sz).ptr;
 55}
 56
 57void* gc_realloc(ubyte* p, size_t sz, uint ba = 0) {
 58	return GarbageCollector.realloc(p[0..sz], sz).ptr;
 59}
 60
 61size_t gc_extend(ubyte* p, size_t mx, size_t sz) {
 62	return GarbageCollector.extend(p[0..mx], mx, sz);
 63}
 64
 65void gc_free(ubyte* p) {
 66	return GarbageCollector.free(p[0..1]);
 67}
 68
 69size_t gc_sizeOf(ubyte* p) {
 70	return GarbageCollector.sizeOf(p[0..1]);
 71}
 72
 73void gc_addRoot(ubyte* p) {
 74	return GarbageCollector.addRoot(p[0..1]);
 75}
 76
 77void gc_addRange(ubyte* p, size_t sz) {
 78	return GarbageCollector.addRange(p[0..sz]);
 79}
 80
 81void gc_removeRoot(ubyte* p) {
 82	return GarbageCollector.removeRoot(p[0..1]);
 83}
 84
 85void gc_removeRange(ubyte* p) {
 86	return GarbageCollector.removeRange(p[0..1]);
 87}
 88
 89// Implementation
 90struct Pool {
 91}
 92
 93class GarbageCollector {
 94public:
 95static:
 96
 97	void enable() {
 98		Atomic.decrement(_disabled);
 99	}
100
101	void disable() {
102		Atomic.increment(_disabled);
103	}
104
105	void minimize() {
106	}
107
108	void collect() {
109	}
110
111	ubyte[] malloc(size_t length) {
112		return null;
113	}
114
115	ubyte[] realloc(ubyte[] original, size_t length) {
116		return null;
117	}
118
119	ubyte[] calloc(size_t length) {
120		return null;
121	}
122
123	size_t extend(ubyte[] original, size_t max, size_t size) {
124		return 0;
125	}
126
127	size_t reserve(size_t length) {
128		return 0;
129	}
130
131	void free(ubyte[] memory) {
132	}
133
134	void* addressOf(ubyte[] memory) {
135		return null;
136	}
137
138	size_t sizeOf(ubyte[] memory) {
139		return 0;
140	}
141
142	void addRoot(ubyte[] memory) {
143	}
144
145	void addRange(ubyte[] range) {
146	}
147
148	void removeRoot(ubyte[] memory) {
149	}
150
151	void removeRange(ubyte[] range) {
152	}
153
154private:
155
156	void _initialize() {
157		_inited = 1;
158	}
159
160	void _terminate() {
161		_inited = 0;
162	}
163
164	ulong _disabled;
165	bool _inited;
166}