[glib: 1/3] gthread: Count how many threads have been started



commit 6271b5eb93c30fd6a81cdea6cdac1f978c8a7ae3
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Jul 25 15:08:29 2019 +0100

    gthread: Count how many threads have been started
    
    This will be used in a following commit to warn if setenv() is used
    after another thread has been created.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #715

 glib/gthread.c        | 10 ++++++++++
 glib/gthreadprivate.h |  2 ++
 2 files changed, 12 insertions(+)
---
diff --git a/glib/gthread.c b/glib/gthread.c
index 73138cb34..6531f70d7 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -512,6 +512,8 @@ static GMutex    g_once_mutex;
 static GCond     g_once_cond;
 static GSList   *g_once_init_list = NULL;
 
+static volatile guint g_thread_n_created_counter = 0;
+
 static void g_thread_cleanup (gpointer data);
 static GPrivate     g_thread_specific_private = G_PRIVATE_INIT (g_thread_cleanup);
 
@@ -807,6 +809,12 @@ g_thread_proxy (gpointer data)
   return NULL;
 }
 
+guint
+g_thread_n_created (void)
+{
+  return g_atomic_int_get (&g_thread_n_created_counter);
+}
+
 /**
  * g_thread_new:
  * @name: (nullable): an (optional) name for the new thread
@@ -898,6 +906,8 @@ g_thread_new_internal (const gchar *name,
 {
   g_return_val_if_fail (func != NULL, NULL);
 
+  g_atomic_int_inc (&g_thread_n_created_counter);
+
   return (GThread *) g_system_thread_new (proxy, stack_size, scheduler_settings,
                                           name, func, data, error);
 }
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 888b3766d..34ba6126b 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -81,6 +81,8 @@ gboolean g_thread_get_scheduler_settings (GThreadSchedulerSettings *scheduler_se
 
 gpointer        g_thread_proxy                  (gpointer      thread);
 
+guint           g_thread_n_created              (void);
+
 gpointer        g_private_set_alloc0            (GPrivate       *key,
                                                  gsize           size);
 


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