From e3419f9c45476f27e1c89edff5ab557039cdd384 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 22 Aug 2013 22:42:36 -0700 Subject: [PATCH] rt: Memory regions are never synchronized now --- src/libstd/rt/local_heap.rs | 7 ++----- src/rt/memory_region.cpp | 24 +++++------------------- src/rt/memory_region.h | 4 +--- src/rt/rust_builtin.cpp | 6 ++---- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index bca1b4a70f4..aa8c5dd4674 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -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); diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index 0d58d4dae92..e75df3db074 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -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 diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h index b833b90d42a..ace463ede21 100644 --- a/src/rt/memory_region.h +++ b/src/rt/memory_region.h @@ -59,7 +59,6 @@ private: array_list _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); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index cb81c149770..784693755c5 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -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); }