From 7dc7af3d22854733f5007f97fa33f47fb6124a17 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 14 Jul 2011 17:26:52 +0100 Subject: [PATCH 8/9] dbus-memory: use atomic accesses to block count, even for assertions --- dbus/dbus-memory.c | 24 +++++++++++++++++------- 1 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index a37759c..ee40e82 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -295,7 +295,7 @@ _dbus_decrement_fail_alloc_counter (void) int _dbus_get_malloc_blocks_outstanding (void) { - return n_blocks_outstanding.value; + return _dbus_atomic_get (&n_blocks_outstanding); } /** @@ -634,10 +634,15 @@ dbus_free (void *memory) check_guards (memory, TRUE); if (memory) { - _dbus_atomic_dec (&n_blocks_outstanding); - - _dbus_assert (n_blocks_outstanding.value >= 0); - +#ifdef DBUS_DISABLE_ASSERT + _dbus_atomic_dec (&n_blocks_outstanding); +#else + dbus_int32_t old_value; + + old_value = _dbus_atomic_dec (&n_blocks_outstanding); + _dbus_assert (old_value >= 1); +#endif + free (((unsigned char*)memory) - GUARD_START_OFFSET); } @@ -648,9 +653,14 @@ dbus_free (void *memory) if (memory) /* we guarantee it's safe to free (NULL) */ { #ifdef DBUS_BUILD_TESTS +#ifdef DBUS_DISABLE_ASSERT _dbus_atomic_dec (&n_blocks_outstanding); - - _dbus_assert (n_blocks_outstanding.value >= 0); +#else + dbus_int32_t old_value; + + old_value = _dbus_atomic_dec (&n_blocks_outstanding); + _dbus_assert (old_value >= 1); +#endif #endif free (memory); -- 1.7.5.4