Skip to content

Commit e3419f9

Browse files
committed
rt: Memory regions are never synchronized now
1 parent 0a1baef commit e3419f9

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

src/libstd/rt/local_heap.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ impl LocalHeap {
4040
#[fixed_stack_segment] #[inline(never)]
4141
pub fn new() -> LocalHeap {
4242
unsafe {
43-
// Don't need synchronization for the single-threaded local heap
44-
let synchronized = false as uintptr_t;
4543
// XXX: These usually come from the environment
4644
let detailed_leaks = false as uintptr_t;
4745
let poison_on_free = false as uintptr_t;
48-
let region = rust_new_memory_region(synchronized, detailed_leaks, poison_on_free);
46+
let region = rust_new_memory_region(detailed_leaks, poison_on_free);
4947
assert!(region.is_not_null());
5048
let boxed = rust_new_boxed_region(region, poison_on_free);
5149
assert!(boxed.is_not_null());
@@ -109,8 +107,7 @@ pub fn live_allocs() -> *raw::Box<()> {
109107

110108
extern {
111109
#[fast_ffi]
112-
fn rust_new_memory_region(synchronized: uintptr_t,
113-
detailed_leaks: uintptr_t,
110+
fn rust_new_memory_region(detailed_leaks: uintptr_t,
114111
poison_on_free: uintptr_t) -> *MemoryRegion;
115112
#[fast_ffi]
116113
fn rust_delete_memory_region(region: *MemoryRegion);

src/rt/memory_region.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,25 @@ inline void memory_region::maybe_print_backtrace(const alloc_header *header) con
4242
# endif
4343
}
4444

45-
memory_region::memory_region(bool synchronized,
46-
bool detailed_leaks,
45+
memory_region::memory_region(bool detailed_leaks,
4746
bool poison_on_free) :
4847
_parent(NULL), _live_allocations(0),
4948
_detailed_leaks(detailed_leaks),
50-
_poison_on_free(poison_on_free),
51-
_synchronized(synchronized) {
49+
_poison_on_free(poison_on_free) {
5250
}
5351

5452
memory_region::memory_region(memory_region *parent) :
5553
_parent(parent), _live_allocations(0),
5654
_detailed_leaks(parent->_detailed_leaks),
57-
_poison_on_free(parent->_poison_on_free),
58-
_synchronized(parent->_synchronized) {
55+
_poison_on_free(parent->_poison_on_free) {
5956
}
6057

6158
void memory_region::add_alloc() {
62-
//_live_allocations++;
63-
sync::increment(_live_allocations);
59+
_live_allocations++;
6460
}
6561

6662
void memory_region::dec_alloc() {
67-
//_live_allocations--;
68-
sync::decrement(_live_allocations);
63+
_live_allocations--;
6964
}
7065

7166
void memory_region::free(void *mem) {
@@ -112,7 +107,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
112107
# endif
113108

114109
# if RUSTRT_TRACK_ALLOCATIONS >= 2
115-
if (_synchronized) { _lock.lock(); }
116110
if (_allocation_list[newMem->index] != alloc) {
117111
printf("at index %d, found %p, expected %p\n",
118112
alloc->index, _allocation_list[alloc->index], alloc);
@@ -125,7 +119,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
125119
// printf("realloc: stored %p at index %d, replacing %p\n",
126120
// newMem, index, mem);
127121
}
128-
if (_synchronized) { _lock.unlock(); }
129122
# endif
130123

131124
return get_data(newMem);
@@ -160,9 +153,7 @@ memory_region::malloc(size_t size, const char *tag) {
160153
}
161154

162155
memory_region::~memory_region() {
163-
if (_synchronized) { _lock.lock(); }
164156
if (_live_allocations == 0 && !_detailed_leaks) {
165-
if (_synchronized) { _lock.unlock(); }
166157
return;
167158
}
168159
char msg[128];
@@ -193,7 +184,6 @@ memory_region::~memory_region() {
193184
fprintf(stderr, "%s\n", msg);
194185
assert(false);
195186
}
196-
if (_synchronized) { _lock.unlock(); }
197187
}
198188

199189
void
@@ -204,7 +194,6 @@ memory_region::release_alloc(void *mem) {
204194
# endif
205195

206196
# if RUSTRT_TRACK_ALLOCATIONS >= 2
207-
if (_synchronized) { _lock.lock(); }
208197
if (((size_t) alloc->index) >= _allocation_list.size()) {
209198
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
210199
(uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size());
@@ -222,7 +211,6 @@ memory_region::release_alloc(void *mem) {
222211
_allocation_list[alloc->index] = NULL;
223212
alloc->index = -1;
224213
}
225-
if (_synchronized) { _lock.unlock(); }
226214
# endif
227215

228216
dec_alloc();
@@ -236,9 +224,7 @@ memory_region::claim_alloc(void *mem) {
236224
# endif
237225

238226
# if RUSTRT_TRACK_ALLOCATIONS >= 2
239-
if (_synchronized) { _lock.lock(); }
240227
alloc->index = _allocation_list.append(alloc);
241-
if (_synchronized) { _lock.unlock(); }
242228
# endif
243229

244230
# if RUSTRT_TRACK_ALLOCATIONS >= 3

src/rt/memory_region.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class memory_region {
5959
array_list<alloc_header *> _allocation_list;
6060
const bool _detailed_leaks;
6161
const bool _poison_on_free;
62-
const bool _synchronized;
6362
lock_and_signal _lock;
6463

6564
void add_alloc();
@@ -77,8 +76,7 @@ class memory_region {
7776
memory_region& operator=(const memory_region& rhs);
7877

7978
public:
80-
memory_region(bool synchronized,
81-
bool detailed_leaks, bool poison_on_free);
79+
memory_region(bool detailed_leaks, bool poison_on_free);
8280
memory_region(memory_region *parent);
8381
void *malloc(size_t size, const char *tag);
8482
void *realloc(void *mem, size_t size);

src/rt/rust_builtin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,9 @@ rust_initialize_rt_tls_key() {
528528
}
529529

530530
extern "C" CDECL memory_region*
531-
rust_new_memory_region(uintptr_t synchronized,
532-
uintptr_t detailed_leaks,
531+
rust_new_memory_region(uintptr_t detailed_leaks,
533532
uintptr_t poison_on_free) {
534-
return new memory_region((bool)synchronized,
535-
(bool)detailed_leaks,
533+
return new memory_region((bool)detailed_leaks,
536534
(bool)poison_on_free);
537535
}
538536

0 commit comments

Comments
 (0)