[util] rgn_bootstrap_new
This commit is contained in:
parent
3936c26feb
commit
a31e039e09
|
@ -15,19 +15,17 @@
|
||||||
struct ax_ctxt* ax_new(void)
|
struct ax_ctxt* ax_new(void)
|
||||||
{
|
{
|
||||||
// "bootstrap" a new region
|
// "bootstrap" a new region
|
||||||
struct rgn rgn0;
|
struct rgn* rgn = rgn_bootstrap_new(MEDIUM);
|
||||||
rgn_init(&rgn0, SMALL);
|
|
||||||
struct rgn* rgn = rmemdup_typed(&rgn0, struct rgn, &rgn0, 1);
|
|
||||||
// use it to make a new context
|
// use it to make a new context
|
||||||
struct ax_ctxt* ax = ralloc_typed(rgn, struct ax_ctxt, 1);
|
struct ax_ctxt* ax = ralloc_typed(rgn, struct ax_ctxt, 1);
|
||||||
ax__ctxt_init(ax, rgn);
|
ax__ctxt_init(ax, rgn);
|
||||||
|
rgn_pin(rgn, ax, (void*) ax__ctxt_cleanup);
|
||||||
return ax;
|
return ax;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax_free(struct ax_ctxt* ax)
|
void ax_free(struct ax_ctxt* ax)
|
||||||
{
|
{
|
||||||
if (ax != NULL) {
|
if (ax != NULL) {
|
||||||
ax__ctxt_cleanup(ax);
|
|
||||||
rgn_cleanup(ax->init_rgn);
|
rgn_cleanup(ax->init_rgn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,15 @@ void rgn_pin(struct rgn* rgn, void* obj, void (*dtor)(void*))
|
||||||
rgn->pinned = pin;
|
rgn->pinned = pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct rgn* rgn_bootstrap_new(size_t pgsize)
|
||||||
|
{
|
||||||
|
struct rgn tmp;
|
||||||
|
rgn_init(&tmp, pgsize);
|
||||||
|
struct rgn* ptr = ralloc_typed(&tmp, struct rgn, 1);
|
||||||
|
*ptr = tmp;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void rgn_print_stats(struct rgn* rgn, FILE* out)
|
void rgn_print_stats(struct rgn* rgn, FILE* out)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,10 @@ void rgn_pin(struct rgn* rgn, void* obj, void (*dtor)(void*));
|
||||||
* Derived utilities
|
* Derived utilities
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// new "self-bootstrapped" region -- the return region pointer belongs to
|
||||||
|
// itself, and will be invalidated when this region is cleared/cleaned up.
|
||||||
|
struct rgn* rgn_bootstrap_new(size_t pgsize);
|
||||||
|
|
||||||
#define ralloc_typed(_rgn, T, _n) \
|
#define ralloc_typed(_rgn, T, _n) \
|
||||||
((T*) ralloc(_rgn, sizeof(T) * (_n)))
|
((T*) ralloc(_rgn, sizeof(T) * (_n)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue