Docs GODI Archive
Projects Blog Link DB

Search GODI:


More options
File lib/felix/rtl/flx_gc.hpp GODI Package apps-felix
 
   flx_gc.hpp  
#line 41 "lpsrc/flx_gc.ipk"
#ifndef FLX_GC
#define FLX_GC

#include <cstdlib>
#ifndef FLX_RTL_CONFIG
#include "flx_rtl_config.hpp"
#endif

// we use an STL set to hold the collection of roots
#include <set>

namespace flx {
namespace gc {
namespace generic {
// Here are the types we refer to:

struct FLX_RTL_EXTERN frame_t;      // the type of all collectable objects
struct FLX_RTL_EXTERN gc_shape_t;   // the shape of collectable objects
struct FLX_RTL_EXTERN collector_t;  // the collector itself
struct FLX_RTL_EXTERN allocator_t;  // the collector itself

struct FLX_RTL_EXTERN gc_shape_t
{
  char const *cname;              // C++ typename
  std::size_t count;              // array element count
  std::size_t amt;                // bytes allocated
  void (*finaliser)(collector_t*, void*);  // finalisation function
  std::size_t n_offsets;          // number of offsets
  std::size_t *offsets;           // actual offsets

  // convenience constructor
  gc_shape_t(
    char const *cn,
    std::size_t count_a,
    std::size_t amt_a,
    void (*finaliser_a)(collector_t*, void*),
    std::size_t n_offsets_a,
    std::size_t *offsets_a
  );
};
#line 105 "lpsrc/flx_gc.ipk"
template<class T>
void std_finaliser(collector_t*, void *t)
{
  static_cast<T*>(t) -> ~T();
}

#line 114 "lpsrc/flx_gc.ipk"
struct frame_t
{
  gc_shape_t *shape;      // the shape of each object
  unsigned long n_objects; // how many objects (for arrays)
  frame_t *next;          // the next and previous objects
  frame_t *prev;          // in the collectors list
  collector_t *collector; // the managing collector
  bool garbage;           // the garbage flag
  bool finalised;         // whether the object is finalised
};

#line 134 "lpsrc/flx_gc.ipk"
#define _MAX_ALIGN 4

// ----------------------------------------------------

#define _ROUNDUP(i,n) ((i + n - 1) / n * n)
#define _ALIGN(i) _ROUNDUP(i,_MAX_ALIGN)

#define FRAMESIZE int(_ALIGN(sizeof(frame_t)))
#define FRAME_TO_CLIENT(p) \
  ((void*)((unsigned char*)(void*)p + FRAMESIZE))
#define CLIENT_TO_FRAME(p) \
  ((frame_t*)(void*)((unsigned char*)p - FRAMESIZE))

#line 150 "lpsrc/flx_gc.ipk"
struct allocator_t {
  bool debug;
  allocator_t():debug(false){}
  virtual void *allocate(std::size_t)=0;
  virtual void deallocate(void *, std::size_t)=0;
  virtual ~allocator_t(){};
  void set_debug(bool d){debug=d;}
};

#line 162 "lpsrc/flx_gc.ipk"
struct FLX_RTL_EXTERN collector_t
{
  bool debug;
  void set_debug(bool d){debug=d;}
  collector_t();
  virtual ~collector_t(){}

#line 172 "lpsrc/flx_gc.ipk"
  virtual unsigned long get_allocation_count()const=0;
  virtual unsigned long get_root_count()const=0;
  virtual unsigned long get_allocation_amt()const=0;

#line 180 "lpsrc/flx_gc.ipk"
  virtual void *allocate(gc_shape_t *shape, unsigned long)=0;
  virtual void deallocate(frame_t *fp)=0;
#line 185 "lpsrc/flx_gc.ipk"
  virtual unsigned long collect()=0;

#line 190 "lpsrc/flx_gc.ipk"
  virtual void add_root(void *memory)=0;
  virtual void remove_root(void *memory)=0;

#line 196 "lpsrc/flx_gc.ipk"
  virtual void check()=0;

#line 202 "lpsrc/flx_gc.ipk"
private: // no assignment or copy
  void operator=(collector_t const&);
  collector_t(collector_t const&);
};


#line 215 "lpsrc/flx_gc.ipk"
void FLX_RTL_EXTERN destroy(void *b);

#line 229 "lpsrc/flx_gc.ipk"
void FLX_RTL_EXTERN _init_ptr(void **a, void *b);
void FLX_RTL_EXTERN _set_ptr(void **a, void *b);
void FLX_RTL_EXTERN _release_ptr(void **a);
void FLX_RTL_EXTERN _destroy_ptr(void **a);

template<class T>
void init_ptr(T **a, T *b)
{
  _init_ptr
  (
    reinterpret_cast<void**>(a),
    reinterpret_cast<void*>(b)
  );
}

template<class T>
void set_ptr(T **a, T *b)
{
  _set_ptr
  (
    reinterpret_cast<void**>(a),
    reinterpret_cast<void*>(b)
  );
}

template<class T>
void release_ptr(T **a)
{
  _release_ptr
  (
    reinterpret_cast<void**>(a)
  );
}

template<class T>
void destroy_ptr(T **a)
{
  _destroy_ptr
  (
    reinterpret_cast<void**>(a)
  );
}

#line 278 "lpsrc/flx_gc.ipk"
FLX_RTL_EXTERN void flx_reset_shape(void *memory, gc_shape_t &);
FLX_RTL_EXTERN void flx_reset_count(void *memory, unsigned long);

}}} // end namespaces

#line 293 "lpsrc/flx_gc.ipk"
FLX_RTL_EXTERN void *operator new
(
  std::size_t,
  flx::gc::generic::collector_t &,
  flx::gc::generic::gc_shape_t &
);

FLX_RTL_EXTERN void *operator new
(
  std::size_t,
  flx::gc::generic::collector_t &,
  flx::gc::generic::gc_shape_t &,
  unsigned long
);

#endif


This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml