diff options
author | 2017-02-09 08:01:03 -0800 | |
---|---|---|
committer | 2017-02-09 08:01:03 -0800 | |
commit | 560371d8472b91cfe0423ad05252b86f868e5d9a (patch) | |
tree | b98d76f25372502acc0798cc2286e76b778252f5 | |
parent | 2a11ad1529833d0faaa0d2b03f19fd0c06286991 (diff) | |
parent | 44cc814bcafb470049f26de8e0a45ccc2c1a8c78 (diff) |
Merge branch 'atomic_counters' into call_mutex
-rw-r--r-- | test/core/util/memory_counters.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/test/core/util/memory_counters.c b/test/core/util/memory_counters.c index 0a782b3470..fd6770bd49 100644 --- a/test/core/util/memory_counters.c +++ b/test/core/util/memory_counters.c @@ -49,10 +49,14 @@ static void guard_free(void *vptr); static void *guard_malloc(size_t size) { size_t *ptr; if (!size) return NULL; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, 1); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, 1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, + (gpr_atm)1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, + (gpr_atm)1); ptr = g_old_allocs.malloc_fn(size + sizeof(size)); *ptr++ = size; return ptr; @@ -68,10 +72,14 @@ static void *guard_realloc(void *vptr, size_t size) { return NULL; } --ptr; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, -*ptr); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, 1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + -(gpr_atm)*ptr); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, + (gpr_atm)1); ptr = g_old_allocs.realloc_fn(ptr, size + sizeof(size)); *ptr++ = size; return ptr; @@ -81,8 +89,10 @@ static void guard_free(void *vptr) { size_t *ptr = vptr; if (!vptr) return; --ptr; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, -*ptr); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, -1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + -(gpr_atm)*ptr); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, + -(gpr_atm)1); g_old_allocs.free_fn(ptr); } |