[glib/wip/mount-watcher: 1/24] GThread: add internal "debug name" helper



commit 94599349284bda5e8d1b96dadcc69d0d3d562fe2
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jan 5 12:36:43 2015 -0500

    GThread: add internal "debug name" helper
    
    Add an internal function to get the name of a thread for display in
    debugging messages.  We support reporting "the main thread" for the
    thread that our ctor got run in (which is almost definitely what most
    people would consider to be 'the main thread').
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742599

 glib/gthread.c        |   21 +++++++++++++++++++++
 glib/gthreadprivate.h |    2 ++
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/glib/gthread.c b/glib/gthread.c
index ea8e5f9..6cb1a04 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -972,6 +972,27 @@ g_thread_self (void)
   return (GThread*) thread;
 }
 
+/*< internal >
+ * g_thread_get_debug_name:
+ * @thread: a #GThread
+ *
+ * Gets the name of @thread, suitable for debugging output.
+ *
+ * If @thread is not named then this will return something like "unnamed
+ * thread".
+ */
+const gchar *
+g_thread_get_debug_name (GThread *thread)
+{
+  GRealThread *real = (GRealThread*) thread;
+
+  if (real->name)
+    return real->name;
+
+  else
+    return "unnamed thread";
+}
+
 /**
  * g_get_num_processors:
  *
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 198b29a..a9b63b0 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -57,4 +57,6 @@ GThread *       g_thread_new_internal           (const gchar  *name,
 
 gpointer        g_thread_proxy                  (gpointer      thread);
 
+const gchar *   g_thread_get_debug_name         (GThread      *thread);
+
 #endif /* __G_THREADPRIVATE_H__ */


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