dbus-memory: use atomic accesses to block count, even for assertions
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 14 Jul 2011 16:26:52 +0000 (17:26 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 26 Jul 2011 16:41:38 +0000 (17:41 +0100)
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38005

dbus/dbus-memory.c

index a37759c0f10144a9b8e76ea612b480b6a3e76084..ee40e82b149097f2b2307930eb55ac4622d860bf 100644 (file)
@@ -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);