rt: Don't make memory_region depend on rust_env

I am going to use memory_region and boxed_region as the local heap
in the new scheduler, for now at least, and I don't have a rust_env
available.
This commit is contained in:
Brian Anderson 2013-04-21 17:42:45 -07:00
parent f9069baa70
commit 2fe118b26f
6 changed files with 18 additions and 14 deletions

View file

@ -82,7 +82,7 @@ void boxed_region::free(rust_opaque_box *box) {
if (box->next) box->next->prev = box->prev;
if (live_allocs == box) live_allocs = box->next;
if (env->poison_on_free) {
if (poison_on_free) {
memset(box_body(box), 0xab, box->td->size);
}

View file

@ -24,7 +24,7 @@ struct rust_env;
* a type descr which describes the payload (what follows the header). */
class boxed_region {
private:
rust_env *env;
bool poison_on_free;
memory_region *backing_region;
rust_opaque_box *live_allocs;
@ -41,8 +41,8 @@ private:
boxed_region& operator=(const boxed_region& rhs);
public:
boxed_region(rust_env *e, memory_region *br)
: env(e)
boxed_region(memory_region *br, bool poison_on_free)
: poison_on_free(poison_on_free)
, backing_region(br)
, live_allocs(NULL)
{}

View file

@ -11,7 +11,6 @@
#include "sync/sync.h"
#include "memory_region.h"
#include "rust_env.h"
#if RUSTRT_TRACK_ALLOCATIONS >= 3
#include <execinfo.h>
@ -35,15 +34,19 @@ void *memory_region::get_data(alloc_header *ptr) {
return (void*)((char *)ptr + HEADER_SIZE);
}
memory_region::memory_region(rust_env *env, bool synchronized) :
_env(env), _parent(NULL), _live_allocations(0),
_detailed_leaks(env->detailed_leaks),
memory_region::memory_region(bool synchronized,
bool detailed_leaks,
bool poison_on_free) :
_parent(NULL), _live_allocations(0),
_detailed_leaks(detailed_leaks),
_poison_on_free(poison_on_free),
_synchronized(synchronized) {
}
memory_region::memory_region(memory_region *parent) :
_env(parent->_env), _parent(parent), _live_allocations(0),
_parent(parent), _live_allocations(0),
_detailed_leaks(parent->_detailed_leaks),
_poison_on_free(parent->_poison_on_free),
_synchronized(parent->_synchronized) {
}
@ -241,7 +244,7 @@ memory_region::claim_alloc(void *mem) {
void
memory_region::maybe_poison(void *mem) {
if (!_env->poison_on_free)
if (!_poison_on_free)
return;
# if RUSTRT_TRACK_ALLOCATIONS >= 1

View file

@ -54,11 +54,11 @@ private:
inline alloc_header *get_header(void *mem);
inline void *get_data(alloc_header *);
rust_env *_env;
memory_region *_parent;
int _live_allocations;
array_list<alloc_header *> _allocation_list;
const bool _detailed_leaks;
const bool _poison_on_free;
const bool _synchronized;
lock_and_signal _lock;
@ -75,7 +75,8 @@ private:
memory_region& operator=(const memory_region& rhs);
public:
memory_region(rust_env *env, bool synchronized);
memory_region(bool synchronized,
bool detailed_leaks, bool poison_on_free);
memory_region(memory_region *parent);
void *malloc(size_t size, const char *tag);
void *realloc(void *mem, size_t size);

View file

@ -36,7 +36,7 @@ rust_sched_loop::rust_sched_loop(rust_scheduler *sched, int id, bool killed) :
sched(sched),
log_lvl(log_debug),
min_stack_size(kernel->env->min_stack_size),
local_region(kernel->env, false),
local_region(false, kernel->env->detailed_leaks, kernel->env->poison_on_free),
// FIXME #2891: calculate a per-scheduler name.
name("main")
{

View file

@ -36,7 +36,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
kernel(sched_loop->kernel),
name(name),
list_index(-1),
boxed(sched_loop->kernel->env, &local_region),
boxed(&local_region, sched_loop->kernel->env->poison_on_free),
local_region(&sched_loop->local_region),
unwinding(false),
total_stack_sz(0),