[glib: 1/2] gthreadpool: Include prgname in thread name



commit c50bdf07e804e2e08f4c7d5e240ba30ddd3d05d6
Author: Vincent Whitchurch <rabinv axis com>
Date:   Thu Oct 4 16:39:52 2018 +0200

    gthreadpool: Include prgname in thread name
    
    All pool threads are named "pool" and this a bit annoying when looking
    at system-wide traces or statistics for a system where several
    applications use thread pools.  Include the prgname in the thread names
    to get a better default name.  The total length including the "pool-"
    prefix is limited to 16 bytes in order for it to work on all systems.
    
    Change-Id: I473a9f534c4630f3e81da72ff96d8f593c60efac

 glib/gthreadpool.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c
index dd7289370..a1fbda671 100644
--- a/glib/gthreadpool.c
+++ b/glib/gthreadpool.c
@@ -31,6 +31,7 @@
 #include "gmain.h"
 #include "gtestutils.h"
 #include "gtimer.h"
+#include "gutils.h"
 
 /**
  * SECTION:thread_pools
@@ -401,10 +402,15 @@ g_thread_pool_start_thread (GRealThreadPool  *pool,
 
   if (!success)
     {
+      const gchar *prgname = g_get_prgname ();
+      gchar name[16] = "pool";
       GThread *thread;
 
+      if (prgname)
+        g_snprintf (name, sizeof (name), "pool-%s", prgname);
+
       /* No thread was found, we have to start a new one */
-      thread = g_thread_try_new ("pool", g_thread_pool_thread_proxy, pool, error);
+      thread = g_thread_try_new (name, g_thread_pool_thread_proxy, pool, error);
 
       if (thread == NULL)
         return FALSE;


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