Skip to content

Commit

Permalink
rt: Don't make memory_region depend on rust_env
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brson committed Apr 22, 2013
1 parent f9069ba commit 2fe118b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/rt/boxed_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/rt/boxed_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,8 +41,8 @@ class boxed_region {
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)
{}
Expand Down
15 changes: 9 additions & 6 deletions src/rt/memory_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "sync/sync.h"
#include "memory_region.h"
#include "rust_env.h"

#if RUSTRT_TRACK_ALLOCATIONS >= 3
#include <execinfo.h>
Expand All @@ -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) {
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/rt/memory_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class memory_region {
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;

Expand All @@ -75,7 +75,8 @@ class memory_region {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/rt/rust_sched_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
2 changes: 1 addition & 1 deletion src/rt/rust_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2fe118b

Please sign in to comment.