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
This commit is contained in:
Philip Withnall 2019-07-25 15:08:29 +01:00
parent 5d32b99d0c
commit 6271b5eb93
2 changed files with 12 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);