fix(util/memory): remove get_thread_allocated_memory, it used thread_local
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
60a1ac3192
commit
d827b56777
3 changed files with 0 additions and 29 deletions
|
@ -20,7 +20,6 @@ static void tst1() {
|
||||||
a = static_cast<int*>(lean::realloc(a, N * 2 * sizeof(N)));
|
a = static_cast<int*>(lean::realloc(a, N * 2 * sizeof(N)));
|
||||||
lean_assert(lean::get_allocated_memory() >= old_mem + N * 2 * sizeof(N));
|
lean_assert(lean::get_allocated_memory() >= old_mem + N * 2 * sizeof(N));
|
||||||
std::cout << "Total: " << static_cast<size_t>(lean::get_allocated_memory()) << "\n";
|
std::cout << "Total: " << static_cast<size_t>(lean::get_allocated_memory()) << "\n";
|
||||||
std::cout << "Thread: " << static_cast<size_t>(lean::get_thread_allocated_memory()) << "\n";
|
|
||||||
#if !defined(HAS_TCMALLOC) && !defined(LEAN_USE_BOOST)
|
#if !defined(HAS_TCMALLOC) && !defined(LEAN_USE_BOOST)
|
||||||
// When TCMALLOC is used, there is a problem during initialization, and the value of get_thread_allocated_memory is off.
|
// When TCMALLOC is used, there is a problem during initialization, and the value of get_thread_allocated_memory is off.
|
||||||
lean_assert_eq(lean::get_allocated_memory(), static_cast<size_t>(lean::get_thread_allocated_memory()));
|
lean_assert_eq(lean::get_allocated_memory(), static_cast<size_t>(lean::get_thread_allocated_memory()));
|
||||||
|
|
|
@ -14,10 +14,6 @@ size_t get_allocated_memory() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long get_thread_allocated_memory() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * malloc(size_t sz) {
|
void * malloc(size_t sz) {
|
||||||
void * r = ::malloc(sz);
|
void * r = ::malloc(sz);
|
||||||
if (r || sz == 0)
|
if (r || sz == 0)
|
||||||
|
@ -105,31 +101,15 @@ public:
|
||||||
size_t size() const { return m_size; }
|
size_t size() const { return m_size; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class thread_alloc_info {
|
|
||||||
size_t m_size; // It can be negative
|
|
||||||
public:
|
|
||||||
thread_alloc_info():m_size(0) {}
|
|
||||||
void inc(size_t sz) { m_size += sz; }
|
|
||||||
void dec(size_t sz) { m_size -= sz; }
|
|
||||||
long long size() const { return static_cast<long long>(m_size); }
|
|
||||||
};
|
|
||||||
|
|
||||||
static alloc_info g_global_memory;
|
static alloc_info g_global_memory;
|
||||||
static thread_alloc_info & get_thread_memory() {
|
|
||||||
// we cannot use MK_THREAD_LOCAL_GET here because it depends on new/delete, and the Lean new/delete invokes this procedure
|
|
||||||
static thread_alloc_info LEAN_THREAD_LOCAL g_info;
|
|
||||||
return g_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t get_allocated_memory() { return g_global_memory.size(); }
|
size_t get_allocated_memory() { return g_global_memory.size(); }
|
||||||
long long get_thread_allocated_memory() { return get_thread_memory().size(); }
|
|
||||||
|
|
||||||
void * malloc(size_t sz) {
|
void * malloc(size_t sz) {
|
||||||
void * r = malloc_core(sz);
|
void * r = malloc_core(sz);
|
||||||
if (r || sz == 0) {
|
if (r || sz == 0) {
|
||||||
size_t rsz = malloc_size(r);
|
size_t rsz = malloc_size(r);
|
||||||
g_global_memory.inc(rsz);
|
g_global_memory.inc(rsz);
|
||||||
get_thread_memory().inc(rsz);
|
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
|
@ -145,11 +125,9 @@ void * realloc(void * ptr, size_t sz) {
|
||||||
}
|
}
|
||||||
size_t old_sz = malloc_size(ptr);
|
size_t old_sz = malloc_size(ptr);
|
||||||
g_global_memory.dec(old_sz);
|
g_global_memory.dec(old_sz);
|
||||||
get_thread_memory().dec(old_sz);
|
|
||||||
void * r = realloc_core(ptr, sz);
|
void * r = realloc_core(ptr, sz);
|
||||||
size_t new_sz = malloc_size(r);
|
size_t new_sz = malloc_size(r);
|
||||||
g_global_memory.inc(new_sz);
|
g_global_memory.inc(new_sz);
|
||||||
get_thread_memory().inc(new_sz);
|
|
||||||
if (r || sz == 0)
|
if (r || sz == 0)
|
||||||
return r;
|
return r;
|
||||||
else
|
else
|
||||||
|
@ -160,7 +138,6 @@ void free(void * ptr) {
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
size_t sz = malloc_size(ptr);
|
size_t sz = malloc_size(ptr);
|
||||||
g_global_memory.dec(sz);
|
g_global_memory.dec(sz);
|
||||||
get_thread_memory().dec(sz);
|
|
||||||
}
|
}
|
||||||
free_core(ptr);
|
free_core(ptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,7 @@ Author: Leonardo de Moura
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
size_t get_allocated_memory();
|
size_t get_allocated_memory();
|
||||||
long long get_thread_allocated_memory();
|
|
||||||
void * malloc(size_t sz);
|
void * malloc(size_t sz);
|
||||||
void * realloc(void * ptr, size_t sz);
|
void * realloc(void * ptr, size_t sz);
|
||||||
void free(void * ptr);
|
void free(void * ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue