| File lib/felix/rtl/flx_gc.cpp |
GODI Package
apps-felix |
#line 311 "lpsrc/flx_gc.ipk"
#include "flx_gc.hpp"
#include <cstdio>
#include <cassert>
namespace flx {
namespace gc {
namespace generic {
// create a shape object given an array of offsets
gc_shape_t::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
)
:
cname(cn),
count(count_a),
amt(amt_a),
finaliser(finaliser_a),
n_offsets(n_offsets_a),
offsets(offsets_a)
{}
void destroy(void *p)
{
if(p)
{
frame_t *fp = CLIENT_TO_FRAME(p);
if(!fp->finalised)
fp->collector->deallocate(fp);
}
}
// b may be 0
void _init_ptr(void **a, void *b)
{
*a = b;
}
// *a or b may be 0
void _set_ptr(void **a, void *b)
{
*a = b;
}
// *a may be 0
void _release_ptr(void **a)
{
*a = 0;
}
void _destroy_ptr(void **a)
{
void *b = *a; // save the pointer value
*a=0; // null out the variable
destroy(b);
}
void reset_shape(void *memory, gc_shape_t &shape)
{
assert(memory);
CLIENT_TO_FRAME(memory)->shape = &shape;
}
void reset_count(void *memory, unsigned long n)
{
assert(memory);
CLIENT_TO_FRAME(memory)->n_objects = n;
}
collector_t::collector_t() : debug(false) {}
}}} // end namespaces
// in global namespace now ..
void *operator new(
std::size_t amt,
flx::gc::generic::collector_t &collector,
flx::gc::generic::gc_shape_t &shape
)
{
if (amt != shape.amt)
{
fprintf(stderr,"Shape size error: allocator size = %ld\n",amt);
fprintf(stderr,"Shape %s size = %ld\n",shape.cname,shape.amt);
abort();
}
return collector.allocate(&shape,1);
}
void *operator new(
std::size_t amt,
flx::gc::generic::collector_t &collector,
flx::gc::generic::gc_shape_t &shape,
unsigned long count
)
{
assert (amt == shape.amt * count);
return collector.allocate(&shape,count);
}