add and use _dbus_server_trace_ref
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 26 Jul 2011 15:28:41 +0000 (16:28 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 13 Feb 2012 17:54:54 +0000 (17:54 +0000)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37286
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Lennart Poettering <lennart@poettering.net>
dbus/dbus-server-debug-pipe.c
dbus/dbus-server-protected.h
dbus/dbus-server-socket.c
dbus/dbus-server.c

index e18cad7..419db5c 100644 (file)
@@ -177,7 +177,8 @@ _dbus_server_debug_pipe_new (const char     *server_name,
   _dbus_string_free (&address);
 
   /* server keeps the pipe hash ref */
-  
+
+  _dbus_server_trace_ref (&debug_server->base, 0, 1, "debug_pipe_new");
   return (DBusServer *)debug_server;
 
  nomem_4:
index 31976e3..df306f7 100644 (file)
@@ -126,6 +126,20 @@ DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry
                                                               DBusServer       **server_p,
                                                               DBusError         *error);
 
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+void _dbus_server_trace_ref (DBusServer *server,
+    int old_refcount,
+    int new_refcount,
+    const char *why);
+#else
+#define _dbus_server_trace_ref(s,o,n,w) \
+  do \
+  {\
+    (void) (o); \
+    (void) (n); \
+  } while (0)
+#endif
+
 #ifdef DBUS_DISABLE_CHECKS
 #define TOOK_LOCK_CHECK(server)
 #define RELEASING_LOCK_CHECK(server)
index 8e31da9..ae4b602 100644 (file)
@@ -343,6 +343,7 @@ _dbus_server_new_for_socket (int              *fds,
 
   SERVER_UNLOCK (server);
 
+  _dbus_server_trace_ref (&socket_server->base, 0, 1, "new_for_socket");
   return (DBusServer*) socket_server;
 
  failed_2:
index 5383a66..157557c 100644 (file)
  * @{
  */
 
+#ifndef _dbus_server_trace_ref
+void
+_dbus_server_trace_ref (DBusServer *server,
+    int old_refcount,
+    int new_refcount,
+    const char *why)
+{
+  static int enabled = -1;
+
+  _dbus_trace_ref ("DBusServer", server, old_refcount, new_refcount, why,
+      "DBUS_SERVER_TRACE", &enabled);
+}
+#endif
+
 /* this is a little fragile since it assumes the address doesn't
  * already have a guid, but it shouldn't
  */
@@ -442,18 +456,15 @@ _dbus_server_toggle_timeout (DBusServer  *server,
 void
 _dbus_server_ref_unlocked (DBusServer *server)
 {
+  dbus_int32_t old_refcount;
+
   _dbus_assert (server != NULL);
   HAVE_LOCK_CHECK (server);
 
-#ifdef DBUS_DISABLE_ASSERT
-  _dbus_atomic_inc (&server->refcount);
-#else
-    {
-      dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
-
-      _dbus_assert (old_refcount > 0);
-    }
-#endif
+  old_refcount = _dbus_atomic_inc (&server->refcount);
+  _dbus_assert (old_refcount > 0);
+  _dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
+      "ref_unlocked");
 }
 
 /**
@@ -475,6 +486,9 @@ _dbus_server_unref_unlocked (DBusServer *server)
   old_refcount = _dbus_atomic_dec (&server->refcount);
   _dbus_assert (old_refcount > 0);
 
+  _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
+      "unref_unlocked");
+
   if (old_refcount == 1)
     {
       _dbus_assert (server->disconnected);
@@ -681,29 +695,27 @@ dbus_server_listen (const char     *address,
 DBusServer *
 dbus_server_ref (DBusServer *server)
 {
-  _dbus_return_val_if_fail (server != NULL, NULL);
+  dbus_int32_t old_refcount;
 
-#ifdef DBUS_DISABLE_CHECKS
-  _dbus_atomic_inc (&server->refcount);
-#else
-    {
-      dbus_int32_t old_refcount;
+  _dbus_return_val_if_fail (server != NULL, NULL);
 
-      /* can't get the refcount without a side-effect */
-      old_refcount = _dbus_atomic_inc (&server->refcount);
+  /* can't get the refcount without a side-effect */
+  old_refcount = _dbus_atomic_inc (&server->refcount);
 
-      if (_DBUS_UNLIKELY (old_refcount <= 0))
-        {
-          /* undo side-effect first */
-          _dbus_atomic_dec (&server->refcount);
-          _dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
-                                   _DBUS_FUNCTION_NAME, "old_refcount > 0",
-                                   __FILE__, __LINE__);
-          return NULL;
-        }
+#ifndef DBUS_DISABLE_CHECKS
+  if (_DBUS_UNLIKELY (old_refcount <= 0))
+    {
+      /* undo side-effect first */
+      _dbus_atomic_dec (&server->refcount);
+      _dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
+                               _DBUS_FUNCTION_NAME, "old_refcount > 0",
+                               __FILE__, __LINE__);
+      return NULL;
     }
 #endif
 
+  _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref");
+
   return server;
 }
 
@@ -739,6 +751,8 @@ dbus_server_unref (DBusServer *server)
     }
 #endif
 
+  _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref");
+
   if (old_refcount == 1)
     {
       /* lock not held! */