提交 e3419f9c 编写于 作者: B Brian Anderson

rt: Memory regions are never synchronized now

上级 0a1baef4
......@@ -40,12 +40,10 @@ impl LocalHeap {
#[fixed_stack_segment] #[inline(never)]
pub fn new() -> LocalHeap {
unsafe {
// Don't need synchronization for the single-threaded local heap
let synchronized = false as uintptr_t;
// XXX: These usually come from the environment
let detailed_leaks = false as uintptr_t;
let poison_on_free = false as uintptr_t;
let region = rust_new_memory_region(synchronized, detailed_leaks, poison_on_free);
let region = rust_new_memory_region(detailed_leaks, poison_on_free);
assert!(region.is_not_null());
let boxed = rust_new_boxed_region(region, poison_on_free);
assert!(boxed.is_not_null());
......@@ -109,8 +107,7 @@ pub fn live_allocs() -> *raw::Box<()> {
extern {
#[fast_ffi]
fn rust_new_memory_region(synchronized: uintptr_t,
detailed_leaks: uintptr_t,
fn rust_new_memory_region(detailed_leaks: uintptr_t,
poison_on_free: uintptr_t) -> *MemoryRegion;
#[fast_ffi]
fn rust_delete_memory_region(region: *MemoryRegion);
......
......@@ -42,30 +42,25 @@ inline void memory_region::maybe_print_backtrace(const alloc_header *header) con
# endif
}
memory_region::memory_region(bool synchronized,
bool detailed_leaks,
memory_region::memory_region(bool detailed_leaks,
bool poison_on_free) :
_parent(NULL), _live_allocations(0),
_detailed_leaks(detailed_leaks),
_poison_on_free(poison_on_free),
_synchronized(synchronized) {
_poison_on_free(poison_on_free) {
}
memory_region::memory_region(memory_region *parent) :
_parent(parent), _live_allocations(0),
_detailed_leaks(parent->_detailed_leaks),
_poison_on_free(parent->_poison_on_free),
_synchronized(parent->_synchronized) {
_poison_on_free(parent->_poison_on_free) {
}
void memory_region::add_alloc() {
//_live_allocations++;
sync::increment(_live_allocations);
_live_allocations++;
}
void memory_region::dec_alloc() {
//_live_allocations--;
sync::decrement(_live_allocations);
_live_allocations--;
}
void memory_region::free(void *mem) {
......@@ -112,7 +107,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
# endif
# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
if (_allocation_list[newMem->index] != alloc) {
printf("at index %d, found %p, expected %p\n",
alloc->index, _allocation_list[alloc->index], alloc);
......@@ -125,7 +119,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
// printf("realloc: stored %p at index %d, replacing %p\n",
// newMem, index, mem);
}
if (_synchronized) { _lock.unlock(); }
# endif
return get_data(newMem);
......@@ -160,9 +153,7 @@ memory_region::malloc(size_t size, const char *tag) {
}
memory_region::~memory_region() {
if (_synchronized) { _lock.lock(); }
if (_live_allocations == 0 && !_detailed_leaks) {
if (_synchronized) { _lock.unlock(); }
return;
}
char msg[128];
......@@ -193,7 +184,6 @@ memory_region::~memory_region() {
fprintf(stderr, "%s\n", msg);
assert(false);
}
if (_synchronized) { _lock.unlock(); }
}
void
......@@ -204,7 +194,6 @@ memory_region::release_alloc(void *mem) {
# endif
# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
if (((size_t) alloc->index) >= _allocation_list.size()) {
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
(uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size());
......@@ -222,7 +211,6 @@ memory_region::release_alloc(void *mem) {
_allocation_list[alloc->index] = NULL;
alloc->index = -1;
}
if (_synchronized) { _lock.unlock(); }
# endif
dec_alloc();
......@@ -236,9 +224,7 @@ memory_region::claim_alloc(void *mem) {
# endif
# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
alloc->index = _allocation_list.append(alloc);
if (_synchronized) { _lock.unlock(); }
# endif
# if RUSTRT_TRACK_ALLOCATIONS >= 3
......
......@@ -59,7 +59,6 @@ private:
array_list<alloc_header *> _allocation_list;
const bool _detailed_leaks;
const bool _poison_on_free;
const bool _synchronized;
lock_and_signal _lock;
void add_alloc();
......@@ -77,8 +76,7 @@ private:
memory_region& operator=(const memory_region& rhs);
public:
memory_region(bool synchronized,
bool detailed_leaks, bool poison_on_free);
memory_region(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);
......
......@@ -528,11 +528,9 @@ rust_initialize_rt_tls_key() {
}
extern "C" CDECL memory_region*
rust_new_memory_region(uintptr_t synchronized,
uintptr_t detailed_leaks,
rust_new_memory_region(uintptr_t detailed_leaks,
uintptr_t poison_on_free) {
return new memory_region((bool)synchronized,
(bool)detailed_leaks,
return new memory_region((bool)detailed_leaks,
(bool)poison_on_free);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册