diff options
| author | Michael Bebenita <mbebenita@mozilla.com> | 2010-08-17 23:40:07 -0700 |
|---|---|---|
| committer | Michael Bebenita <mbebenita@mozilla.com> | 2010-08-17 23:49:57 -0700 |
| commit | 2c1ec6771bd09266308686ab13ca32e2aa73da49 (patch) | |
| tree | acbcae9da89c0f6d37fccdf8b4091f003e798683 /src/rt/rust_srv.cpp | |
| parent | 9fa2b53d8c41cd717ed470926a746bdbff98dc35 (diff) | |
| download | rust-2c1ec6771bd09266308686ab13ca32e2aa73da49.tar.gz rust-2c1ec6771bd09266308686ab13ca32e2aa73da49.zip | |
Lots of changes around memory managment in the Runtime. Added memory regions and fixed race caused by calling rust_srv::malloc() from multiple threads when sending messages.
Diffstat (limited to 'src/rt/rust_srv.cpp')
| -rw-r--r-- | src/rt/rust_srv.cpp | 63 |
1 files changed, 11 insertions, 52 deletions
diff --git a/src/rt/rust_srv.cpp b/src/rt/rust_srv.cpp index 9239f643ebe..f2dfef63ab6 100644 --- a/src/rt/rust_srv.cpp +++ b/src/rt/rust_srv.cpp @@ -5,70 +5,29 @@ #include "rust_internal.h" #include "rust_srv.h" -#define TRACK_ALLOCATIONS - -rust_srv::rust_srv() : _live_allocations(0) { +rust_srv::rust_srv() : + local_region(this, false), + synchronized_region(this, true) { // Nop. } rust_srv::~rust_srv() { - if (_live_allocations != 0) { - char msg[128]; - snprintf(msg, sizeof(msg), - "leaked memory in rust main loop (%" PRIuPTR " objects)", - _live_allocations); -#ifdef TRACK_ALLOCATIONS - for (size_t i = 0; i < _allocation_list.size(); i++) { - if (_allocation_list[i] != NULL) { - printf("allocation 0x%" PRIxPTR " was not freed\n", - (uintptr_t) _allocation_list[i]); - } - } -#endif - fatal(msg, __FILE__, __LINE__, ""); - } + // Nop. +} + +void +rust_srv::free(void *p) { + ::free(p); } void * rust_srv::malloc(size_t bytes) { - ++_live_allocations; - void * val = ::malloc(bytes); -#ifdef TRACK_ALLOCATIONS - _allocation_list.append(val); -#endif - return val; + return ::malloc(bytes); } void * rust_srv::realloc(void *p, size_t bytes) { - if (!p) { - _live_allocations++; - } - void * val = ::realloc(p, bytes); -#ifdef TRACK_ALLOCATIONS - if (_allocation_list.replace(p, val) == false) { - printf("realloc: ptr 0x%" PRIxPTR " is not in allocation_list\n", - (uintptr_t) p); - fatal("not in allocation_list", __FILE__, __LINE__, ""); - } -#endif - return val; -} - -void -rust_srv::free(void *p) { -#ifdef TRACK_ALLOCATIONS - if (_allocation_list.replace(p, NULL) == false) { - printf("free: ptr 0x%" PRIxPTR " is not in allocation_list\n", - (uintptr_t) p); - fatal("not in allocation_list", __FILE__, __LINE__, ""); - } -#endif - if (_live_allocations < 1) { - fatal("live_allocs < 1", __FILE__, __LINE__, ""); - } - _live_allocations--; - ::free(p); + return ::realloc(p, bytes); } void |
