[gjs: 1/5] toggle: Add debug logging



commit 743858a93807df7853e10bd66cd7a2eb325daab9
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Feb 9 19:12:08 2018 -0800

    toggle: Add debug logging
    
    The ToggleQueue is used a lot, so this should be disabled by default
    unless compiled with GJS_VERBOSE_ENABLE_LIFECYCLE.

 gi/toggle.cpp | 7 ++++++-
 gi/toggle.h   | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/gi/toggle.cpp b/gi/toggle.cpp
index 0c3aa26..5010716 100644
--- a/gi/toggle.cpp
+++ b/gi/toggle.cpp
@@ -82,6 +82,7 @@ ToggleQueue::is_queued(GObject *gobj)
 std::pair<bool, bool>
 ToggleQueue::cancel(GObject *gobj)
 {
+    debug("cancel", gobj);
     std::lock_guard<std::mutex> hold(lock);
     bool had_toggle_down = find_and_erase_operation_locked(gobj, DOWN);
     bool had_toggle_up = find_and_erase_operation_locked(gobj, UP);
@@ -101,7 +102,8 @@ ToggleQueue::handle_toggle(Handler handler)
         handler(item.gobj, item.direction);
         q.pop_front();
     }
-    
+
+    debug("handle", item.gobj);
     if (item.needs_unref)
         g_object_unref(item.gobj);
     
@@ -120,8 +122,11 @@ ToggleQueue::enqueue(GObject               *gobj,
      * (either only up, or down-up)
      */
     if (direction == UP) {
+        debug("enqueue UP", gobj);
         g_object_ref(gobj);
         item.needs_unref = true;
+    } else {
+        debug("enqueue DOWN", gobj);
     }
     /* If we're toggling down, we don't need to take a reference since
      * the associated JSObject already has one, and that JSObject won't
diff --git a/gi/toggle.h b/gi/toggle.h
index d1f9fbf..b32714c 100644
--- a/gi/toggle.h
+++ b/gi/toggle.h
@@ -30,6 +30,8 @@
 #include <mutex>
 #include <glib-object.h>
 
+#include "util/log.h"
+
 /* Thread-safe queue for enqueueing toggle-up or toggle-down events on GObjects
  * from any thread. For more information, see object.cpp, comments near
  * wrapped_gobj_toggle_notify(). */
@@ -54,6 +56,11 @@ private:
     unsigned m_idle_id;
     Handler m_toggle_handler;
 
+    /* No-op unless GJS_VERBOSE_ENABLE_LIFECYCLE is defined to 1. */
+    inline void debug(const char *did, void *what) {
+        gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "ToggleQueue %s %p", did, what);
+    }
+
     std::deque<Item>::iterator find_operation_locked(GObject  *gobj,
                                                      Direction direction);
     bool find_and_erase_operation_locked(GObject *gobj, Direction direction);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]