mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 14:57:14 +00:00
rt: Memory regions are never synchronized now
This commit is contained in:
parent
0a1baef4f5
commit
e3419f9c45
@ -40,12 +40,10 @@ impl LocalHeap {
|
|||||||
#[fixed_stack_segment] #[inline(never)]
|
#[fixed_stack_segment] #[inline(never)]
|
||||||
pub fn new() -> LocalHeap {
|
pub fn new() -> LocalHeap {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Don't need synchronization for the single-threaded local heap
|
|
||||||
let synchronized = false as uintptr_t;
|
|
||||||
// XXX: These usually come from the environment
|
// XXX: These usually come from the environment
|
||||||
let detailed_leaks = false as uintptr_t;
|
let detailed_leaks = false as uintptr_t;
|
||||||
let poison_on_free = 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());
|
assert!(region.is_not_null());
|
||||||
let boxed = rust_new_boxed_region(region, poison_on_free);
|
let boxed = rust_new_boxed_region(region, poison_on_free);
|
||||||
assert!(boxed.is_not_null());
|
assert!(boxed.is_not_null());
|
||||||
@ -109,8 +107,7 @@ pub fn live_allocs() -> *raw::Box<()> {
|
|||||||
|
|
||||||
extern {
|
extern {
|
||||||
#[fast_ffi]
|
#[fast_ffi]
|
||||||
fn rust_new_memory_region(synchronized: uintptr_t,
|
fn rust_new_memory_region(detailed_leaks: uintptr_t,
|
||||||
detailed_leaks: uintptr_t,
|
|
||||||
poison_on_free: uintptr_t) -> *MemoryRegion;
|
poison_on_free: uintptr_t) -> *MemoryRegion;
|
||||||
#[fast_ffi]
|
#[fast_ffi]
|
||||||
fn rust_delete_memory_region(region: *MemoryRegion);
|
fn rust_delete_memory_region(region: *MemoryRegion);
|
||||||
|
@ -42,30 +42,25 @@ inline void memory_region::maybe_print_backtrace(const alloc_header *header) con
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_region::memory_region(bool synchronized,
|
memory_region::memory_region(bool detailed_leaks,
|
||||||
bool detailed_leaks,
|
|
||||||
bool poison_on_free) :
|
bool poison_on_free) :
|
||||||
_parent(NULL), _live_allocations(0),
|
_parent(NULL), _live_allocations(0),
|
||||||
_detailed_leaks(detailed_leaks),
|
_detailed_leaks(detailed_leaks),
|
||||||
_poison_on_free(poison_on_free),
|
_poison_on_free(poison_on_free) {
|
||||||
_synchronized(synchronized) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_region::memory_region(memory_region *parent) :
|
memory_region::memory_region(memory_region *parent) :
|
||||||
_parent(parent), _live_allocations(0),
|
_parent(parent), _live_allocations(0),
|
||||||
_detailed_leaks(parent->_detailed_leaks),
|
_detailed_leaks(parent->_detailed_leaks),
|
||||||
_poison_on_free(parent->_poison_on_free),
|
_poison_on_free(parent->_poison_on_free) {
|
||||||
_synchronized(parent->_synchronized) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_region::add_alloc() {
|
void memory_region::add_alloc() {
|
||||||
//_live_allocations++;
|
_live_allocations++;
|
||||||
sync::increment(_live_allocations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_region::dec_alloc() {
|
void memory_region::dec_alloc() {
|
||||||
//_live_allocations--;
|
_live_allocations--;
|
||||||
sync::decrement(_live_allocations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_region::free(void *mem) {
|
void memory_region::free(void *mem) {
|
||||||
@ -112,7 +107,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
||||||
if (_synchronized) { _lock.lock(); }
|
|
||||||
if (_allocation_list[newMem->index] != alloc) {
|
if (_allocation_list[newMem->index] != alloc) {
|
||||||
printf("at index %d, found %p, expected %p\n",
|
printf("at index %d, found %p, expected %p\n",
|
||||||
alloc->index, _allocation_list[alloc->index], alloc);
|
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",
|
// printf("realloc: stored %p at index %d, replacing %p\n",
|
||||||
// newMem, index, mem);
|
// newMem, index, mem);
|
||||||
}
|
}
|
||||||
if (_synchronized) { _lock.unlock(); }
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
return get_data(newMem);
|
return get_data(newMem);
|
||||||
@ -160,9 +153,7 @@ memory_region::malloc(size_t size, const char *tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memory_region::~memory_region() {
|
memory_region::~memory_region() {
|
||||||
if (_synchronized) { _lock.lock(); }
|
|
||||||
if (_live_allocations == 0 && !_detailed_leaks) {
|
if (_live_allocations == 0 && !_detailed_leaks) {
|
||||||
if (_synchronized) { _lock.unlock(); }
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char msg[128];
|
char msg[128];
|
||||||
@ -193,7 +184,6 @@ memory_region::~memory_region() {
|
|||||||
fprintf(stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
if (_synchronized) { _lock.unlock(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -204,7 +194,6 @@ memory_region::release_alloc(void *mem) {
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
||||||
if (_synchronized) { _lock.lock(); }
|
|
||||||
if (((size_t) alloc->index) >= _allocation_list.size()) {
|
if (((size_t) alloc->index) >= _allocation_list.size()) {
|
||||||
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
|
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());
|
(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;
|
_allocation_list[alloc->index] = NULL;
|
||||||
alloc->index = -1;
|
alloc->index = -1;
|
||||||
}
|
}
|
||||||
if (_synchronized) { _lock.unlock(); }
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
dec_alloc();
|
dec_alloc();
|
||||||
@ -236,9 +224,7 @@ memory_region::claim_alloc(void *mem) {
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
# if RUSTRT_TRACK_ALLOCATIONS >= 2
|
||||||
if (_synchronized) { _lock.lock(); }
|
|
||||||
alloc->index = _allocation_list.append(alloc);
|
alloc->index = _allocation_list.append(alloc);
|
||||||
if (_synchronized) { _lock.unlock(); }
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if RUSTRT_TRACK_ALLOCATIONS >= 3
|
# if RUSTRT_TRACK_ALLOCATIONS >= 3
|
||||||
|
@ -59,7 +59,6 @@ private:
|
|||||||
array_list<alloc_header *> _allocation_list;
|
array_list<alloc_header *> _allocation_list;
|
||||||
const bool _detailed_leaks;
|
const bool _detailed_leaks;
|
||||||
const bool _poison_on_free;
|
const bool _poison_on_free;
|
||||||
const bool _synchronized;
|
|
||||||
lock_and_signal _lock;
|
lock_and_signal _lock;
|
||||||
|
|
||||||
void add_alloc();
|
void add_alloc();
|
||||||
@ -77,8 +76,7 @@ private:
|
|||||||
memory_region& operator=(const memory_region& rhs);
|
memory_region& operator=(const memory_region& rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
memory_region(bool synchronized,
|
memory_region(bool detailed_leaks, bool poison_on_free);
|
||||||
bool detailed_leaks, bool poison_on_free);
|
|
||||||
memory_region(memory_region *parent);
|
memory_region(memory_region *parent);
|
||||||
void *malloc(size_t size, const char *tag);
|
void *malloc(size_t size, const char *tag);
|
||||||
void *realloc(void *mem, size_t size);
|
void *realloc(void *mem, size_t size);
|
||||||
|
@ -528,11 +528,9 @@ rust_initialize_rt_tls_key() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL memory_region*
|
extern "C" CDECL memory_region*
|
||||||
rust_new_memory_region(uintptr_t synchronized,
|
rust_new_memory_region(uintptr_t detailed_leaks,
|
||||||
uintptr_t detailed_leaks,
|
|
||||||
uintptr_t poison_on_free) {
|
uintptr_t poison_on_free) {
|
||||||
return new memory_region((bool)synchronized,
|
return new memory_region((bool)detailed_leaks,
|
||||||
(bool)detailed_leaks,
|
|
||||||
(bool)poison_on_free);
|
(bool)poison_on_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user