flx_gc.hpp

00001 #line 80 "./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 // we use an STL set to hold the collection of roots
00009 #include <set>
00010 
00011 namespace flx {
00012 namespace gc {
00013 namespace generic {
00014 // Here are the types we refer to:
00015 
00016 struct GC_EXTERN gc_shape_t;   // the shape of collectable objects
00017 struct GC_EXTERN collector_t;  // the collector itself
00018 struct GC_EXTERN allocator_t;  // the collector itself
00019 
00020 enum gc_shape_flags_t {
00021   gc_flags_default    = 0,            //< collectable and mobile
00022   gc_flags_immobile   = 1,            //< cannot be moved
00023   gc_flags_persistent = 2             //< cannot be deallocated
00024 };
00025 
00026 /// Describes runtime object shape.
00027 struct GC_EXTERN gc_shape_t
00028 {
00029   gc_shape_t *next_shape;         ///< pointer to next shape in list or NULL
00030   char const *cname;              ///< C++ typename
00031   std::size_t count;              ///< array element count
00032   std::size_t amt;                ///< bytes allocated
00033   void (*finaliser)(collector_t*, void*);  ///< finalisation function
00034   std::size_t n_offsets;          ///< number of offsets
00035   std::size_t *offsets;           ///< actual offsets
00036   gc_shape_flags_t flags;         ///< flags
00037 };
00038 #line 140 "./lpsrc/flx_gc.pak"
00039 template<class T>
00040 void std_finaliser(collector_t*, void *t)
00041 {
00042   static_cast<T*>(t) -> ~T();
00043 }
00044 
00045 #line 149 "./lpsrc/flx_gc.pak"
00046 
00047 /// Allocator abstraction.
00048 
00049 struct allocator_t {
00050   bool debug;
00051   allocator_t():debug(false){}
00052   virtual void *allocate(std::size_t)=0;
00053   virtual void deallocate(void *)=0;
00054   virtual void *reallocate(void *, std::size_t)=0;
00055   virtual ~allocator_t(){};
00056   void set_debug(bool d){debug=d;}
00057 };
00058 
00059 #line 165 "./lpsrc/flx_gc.pak"
00060 
00061 /// Collector abstraction.
00062 struct GC_EXTERN collector_t
00063 {
00064   bool debug;
00065   void set_debug(bool d){debug=d;}
00066   collector_t();
00067   virtual ~collector_t(){}
00068 
00069 #line 177 "./lpsrc/flx_gc.pak"
00070   unsigned long get_allocation_count()const {
00071     return v_get_allocation_count();
00072   }
00073 
00074   unsigned long get_root_count()const {
00075     return v_get_root_count();
00076   }
00077 
00078   unsigned long get_allocation_amt()const {
00079     return v_get_allocation_amt();
00080   }
00081 
00082 #line 193 "./lpsrc/flx_gc.pak"
00083   void *allocate(gc_shape_t *shape, unsigned long x) {
00084     return v_allocate(shape,x);
00085   }
00086 
00087 #line 200 "./lpsrc/flx_gc.pak"
00088   unsigned long collect() {
00089     return v_collect();
00090   }
00091 
00092 #line 207 "./lpsrc/flx_gc.pak"
00093   void add_root(void *memory) {
00094     v_add_root(memory);
00095   }
00096 
00097   void remove_root(void *memory) {
00098     v_remove_root(memory);
00099   }
00100 
00101   void finalise(void *frame) {
00102     v_finalise(frame);
00103   }
00104 
00105 #line 222 "./lpsrc/flx_gc.pak"
00106   //array management
00107   virtual void set_used(void *memory, unsigned long)=0;
00108   virtual void incr_used(void *memory, unsigned long)=0;
00109   virtual unsigned long get_used(void *memory)=0;
00110   virtual unsigned long get_count(void *memory)=0;
00111   virtual void *create_empty_array( gc_shape_t &shape, unsigned long count)=0;
00112 private:
00113   virtual unsigned long v_get_allocation_count()const=0;
00114   virtual unsigned long v_get_root_count()const=0;
00115   virtual unsigned long v_get_allocation_amt()const=0;
00116   virtual void *v_allocate(gc_shape_t *shape, unsigned long)=0;
00117   virtual void v_finalise(void *fp)=0;
00118   virtual unsigned long v_collect()=0;
00119   virtual void v_add_root(void *memory)=0;
00120   virtual void v_remove_root(void *memory)=0;
00121 
00122 #line 242 "./lpsrc/flx_gc.pak"
00123   void operator=(collector_t const&);
00124   collector_t(collector_t const&);
00125 };
00126 
00127 
00128 #line 248 "./lpsrc/flx_gc.pak"
00129 
00130 }}} // end namespaces
00131 
00132 #line 261 "./lpsrc/flx_gc.pak"
00133 /// Allocate collectable object
00134 GC_EXTERN void *operator new
00135 (
00136   std::size_t,
00137   flx::gc::generic::collector_t &,
00138   flx::gc::generic::gc_shape_t &
00139 );
00140 #endif
00141 

Generated on Sat Aug 25 21:22:57 2007 for Felix by  doxygen 1.5.1