diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-06-02 00:05:18 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-06-02 00:05:18 -0400 |
commit | 9cc0cdecd8ac7f504400596d0227ca9033d87af9 (patch) | |
tree | b418604ab02420bfec1fab382ec017f518514a8d /libdimension/malloc.c | |
parent | aca752532bf343a31268d96f99d431c77842eff5 (diff) | |
download | dimension-9cc0cdecd8ac7f504400596d0227ca9033d87af9.tar.xz |
Use C11 atomics.
Diffstat (limited to 'libdimension/malloc.c')
-rw-r--r-- | libdimension/malloc.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libdimension/malloc.c b/libdimension/malloc.c index d7816c3..6868802 100644 --- a/libdimension/malloc.c +++ b/libdimension/malloc.c @@ -26,9 +26,10 @@ #include "dimension-internal.h" #include <stdlib.h> #include <string.h> +#include <stdatomic.h> #ifndef NDEBUG -static size_t dmnsn_allocs = 0; +static atomic_size_t dmnsn_allocs = 0; #endif void * @@ -40,7 +41,7 @@ dmnsn_malloc(size_t size) } #ifndef NDEBUG - __sync_fetch_and_add(&dmnsn_allocs, 1); + atomic_fetch_add(&dmnsn_allocs, 1); #endif return ptr; @@ -51,7 +52,7 @@ dmnsn_realloc(void *ptr, size_t size) { #ifndef NDEBUG if (!ptr) { - __sync_fetch_and_add(&dmnsn_allocs, 1); + atomic_fetch_add(&dmnsn_allocs, 1); } #endif @@ -75,7 +76,7 @@ dmnsn_free(void *ptr) { #ifndef NDEBUG if (ptr) { - __sync_fetch_and_sub(&dmnsn_allocs, 1); + atomic_fetch_sub(&dmnsn_allocs, 1); } #endif @@ -86,7 +87,7 @@ dmnsn_free(void *ptr) DMNSN_LATE_DESTRUCTOR static void dmnsn_leak_check(void) { - if (dmnsn_allocs > 0) { + if (atomic_load_explicit(&dmnsn_allocs, memory_order_relaxed) > 0) { dmnsn_warning("Leaking memory."); } } |