00001 #line 79 "./lpsrc/flx_gc.pak"
00002 #ifndef __FLX_GC_H__
00003 #define __FLX_GC_H__
00004
00005 #include <cstdlib>
00006 #include "flx_gc_config.hpp"
00007
00008
00009 #include <set>
00010
00011 namespace flx {
00012 namespace gc {
00013 namespace generic {
00014
00015
00016 struct GC_EXTERN frame_t;
00017 struct GC_EXTERN gc_shape_t;
00018 struct GC_EXTERN collector_t;
00019 struct GC_EXTERN allocator_t;
00020
00021 enum gc_shape_flags_t {
00022 gc_flags_default = 0,
00023 gc_flags_immobile = 1,
00024 gc_flags_persistent = 2
00025 };
00026
00027
00028 struct GC_EXTERN gc_shape_t
00029 {
00030 gc_shape_t *next_shape;
00031 char const *cname;
00032 std::size_t count;
00033 std::size_t amt;
00034 void (*finaliser)(collector_t*, void*);
00035 std::size_t n_offsets;
00036 std::size_t *offsets;
00037 gc_shape_flags_t flags;
00038
00039 gc_shape_t(
00040 gc_shape_t *ns,
00041 char const *cn,
00042 std::size_t count_a,
00043 std::size_t amt_a,
00044 void (*finaliser_a)(collector_t*, void*),
00045 std::size_t n_offsets_a,
00046 std::size_t *offsets_a
00047 );
00048 gc_shape_t(
00049 gc_shape_t *ns,
00050 char const *cn,
00051 std::size_t count_a,
00052 std::size_t amt_a,
00053 void (*finaliser_a)(collector_t*, void*),
00054 std::size_t n_offsets_a,
00055 std::size_t *offsets_a,
00056 gc_shape_flags_t flags_a
00057 );
00058 };
00059 #line 160 "./lpsrc/flx_gc.pak"
00060 template<class T>
00061 void std_finaliser(collector_t*, void *t)
00062 {
00063 static_cast<T*>(t) -> ~T();
00064 }
00065
00066 #line 169 "./lpsrc/flx_gc.pak"
00067
00068
00069
00070 struct allocator_t {
00071 bool debug;
00072 allocator_t():debug(false){}
00073 virtual void *allocate(std::size_t)=0;
00074 virtual void deallocate(void *)=0;
00075 virtual void *reallocate(void *, std::size_t)=0;
00076 virtual ~allocator_t(){};
00077 void set_debug(bool d){debug=d;}
00078 };
00079
00080 #line 185 "./lpsrc/flx_gc.pak"
00081
00082
00083 struct GC_EXTERN collector_t
00084 {
00085 bool debug;
00086 void set_debug(bool d){debug=d;}
00087 collector_t();
00088 virtual ~collector_t(){}
00089
00090 #line 197 "./lpsrc/flx_gc.pak"
00091 unsigned long get_allocation_count()const {
00092 return v_get_allocation_count();
00093 }
00094
00095 unsigned long get_root_count()const {
00096 return v_get_root_count();
00097 }
00098
00099 unsigned long get_allocation_amt()const {
00100 return v_get_allocation_amt();
00101 }
00102
00103 #line 213 "./lpsrc/flx_gc.pak"
00104 void *allocate(gc_shape_t *shape, unsigned long x) {
00105 return v_allocate(shape,x);
00106 }
00107
00108 void deallocate(frame_t *fp) {
00109 v_deallocate(fp);
00110 }
00111
00112 #line 224 "./lpsrc/flx_gc.pak"
00113 unsigned long collect() {
00114 return v_collect();
00115 }
00116
00117 #line 231 "./lpsrc/flx_gc.pak"
00118 void add_root(void *memory) {
00119 v_add_root(memory);
00120 }
00121
00122 void remove_root(void *memory) {
00123 v_remove_root(memory);
00124 }
00125
00126 #line 253 "./lpsrc/flx_gc.pak"
00127 void compact(bool closed) {
00128 v_compact(closed);
00129 }
00130
00131 #line 260 "./lpsrc/flx_gc.pak"
00132 void check() {
00133 v_check();
00134 }
00135
00136 private:
00137 virtual unsigned long v_get_allocation_count()const=0;
00138 virtual unsigned long v_get_root_count()const=0;
00139 virtual unsigned long v_get_allocation_amt()const=0;
00140 virtual void *v_allocate(gc_shape_t *shape, unsigned long)=0;
00141 virtual void v_deallocate(frame_t *fp)=0;
00142 virtual unsigned long v_collect()=0;
00143 virtual void v_add_root(void *memory)=0;
00144 virtual void v_remove_root(void *memory)=0;
00145 virtual void v_compact(bool closed)=0;
00146 virtual void v_check()=0;
00147
00148 #line 280 "./lpsrc/flx_gc.pak"
00149 void operator=(collector_t const&);
00150 collector_t(collector_t const&);
00151 };
00152
00153
00154 #line 292 "./lpsrc/flx_gc.pak"
00155 void GC_EXTERN destroy(void *b);
00156
00157 #line 306 "./lpsrc/flx_gc.pak"
00158 void GC_EXTERN _init_ptr(void **a, void *b);
00159 void GC_EXTERN _set_ptr(void **a, void *b);
00160 void GC_EXTERN _release_ptr(void **a);
00161 void GC_EXTERN _destroy_ptr(void **a);
00162
00163 template<class T>
00164 void init_ptr(T **a, T *b)
00165 {
00166 _init_ptr
00167 (
00168 reinterpret_cast<void**>(a),
00169 reinterpret_cast<void*>(b)
00170 );
00171 }
00172
00173 template<class T>
00174 void set_ptr(T **a, T *b)
00175 {
00176 _set_ptr
00177 (
00178 reinterpret_cast<void**>(a),
00179 reinterpret_cast<void*>(b)
00180 );
00181 }
00182
00183 template<class T>
00184 void release_ptr(T **a)
00185 {
00186 _release_ptr
00187 (
00188 reinterpret_cast<void**>(a)
00189 );
00190 }
00191
00192 template<class T>
00193 void destroy_ptr(T **a)
00194 {
00195 _destroy_ptr
00196 (
00197 reinterpret_cast<void**>(a)
00198 );
00199 }
00200
00201 #line 355 "./lpsrc/flx_gc.pak"
00202 GC_EXTERN void set_used(void *memory, unsigned long);
00203 GC_EXTERN void incr_used(void *memory, unsigned long);
00204 GC_EXTERN unsigned long get_used(void *memory);
00205 GC_EXTERN unsigned long get_count(void *memory);
00206 GC_EXTERN void *create_empty_array(
00207 collector_t &collector,
00208 gc_shape_t &shape,
00209 unsigned long count
00210 );
00211
00212 }}}
00213
00214 #line 377 "./lpsrc/flx_gc.pak"
00215
00216 GC_EXTERN void *operator new
00217 (
00218 std::size_t,
00219 flx::gc::generic::collector_t &,
00220 flx::gc::generic::gc_shape_t &
00221 );
00222 #endif
00223