[glib] thread: use GPrivate for enumerable threads
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] thread: use GPrivate for enumerable threads
- Date: Wed, 12 Oct 2011 21:16:20 +0000 (UTC)
commit f788a2e5e1f7c9898675d3876367e2cf7d55f386
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Oct 12 16:26:39 2011 -0400
thread: use GPrivate for enumerable threads
Use a GPrivate to track the destruction of enumerable threads and remove
them from the list.
glib/deprecated/gthread-deprecated.c | 27 ++++++++++++++++-----------
glib/gthread.c | 11 +++--------
glib/gthreadprivate.h | 1 -
3 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/glib/deprecated/gthread-deprecated.c b/glib/deprecated/gthread-deprecated.c
index ab8dd90..218c5b8 100644
--- a/glib/deprecated/gthread-deprecated.c
+++ b/glib/deprecated/gthread-deprecated.c
@@ -332,18 +332,10 @@ g_thread_foreach (GFunc thread_func,
}
}
-void
-g_enumerable_thread_add (GRealThread *thread)
-{
- G_LOCK (g_thread);
- thread->next = g_thread_all_threads;
- g_thread_all_threads = thread;
- G_UNLOCK (g_thread);
-}
-
-void
-g_enumerable_thread_remove (GRealThread *thread)
+static void
+g_enumerable_thread_remove (gpointer data)
{
+ GRealThread *thread = data;
GRealThread *t, *p;
G_LOCK (g_thread);
@@ -361,6 +353,19 @@ g_enumerable_thread_remove (GRealThread *thread)
G_UNLOCK (g_thread);
}
+GPrivate enumerable_thread_private = G_PRIVATE_INIT (g_enumerable_thread_remove);
+
+void
+g_enumerable_thread_add (GRealThread *thread)
+{
+ G_LOCK (g_thread);
+ thread->next = g_thread_all_threads;
+ g_thread_all_threads = thread;
+ G_UNLOCK (g_thread);
+
+ g_private_set (&enumerable_thread_private, thread);
+}
+
/* GOnce {{{1 ------------------------------------------------------------- */
gboolean
g_once_init_enter_impl (volatile gsize *location)
diff --git a/glib/gthread.c b/glib/gthread.c
index 57c1f02..e6e1901 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -678,9 +678,6 @@ g_thread_cleanup (gpointer data)
*/
if (!thread->thread.joinable)
{
- if (thread->enumerable)
- g_enumerable_thread_remove (thread);
-
/* Just to make sure, this isn't used any more */
g_system_thread_assign (thread->system_thread, zero_thread);
g_free (thread);
@@ -701,6 +698,9 @@ g_thread_create_proxy (gpointer data)
/* This has to happen before G_LOCK, as that might call g_thread_self */
g_private_set (&g_thread_specific_private, data);
+ if (thread->enumerable)
+ g_enumerable_thread_add (thread);
+
/* The lock makes sure that thread->system_thread is written,
* before thread->thread.func is called. See g_thread_new_internal().
*/
@@ -822,8 +822,6 @@ g_thread_new_internal (const gchar *name,
g_system_thread_create (g_thread_create_proxy, result,
stack_size, joinable,
&result->system_thread, &local_error);
- if (enumerable && !local_error)
- g_enumerable_thread_add (result);
G_UNLOCK (g_thread_new);
if (local_error)
@@ -899,9 +897,6 @@ g_thread_join (GThread *thread)
retval = real->retval;
- if (real->enumerable)
- g_enumerable_thread_remove (real);
-
/* Just to make sure, this isn't used any more */
thread->joinable = 0;
g_system_thread_assign (real->system_thread, zero_thread);
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 1dafdac..479d3e0 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -75,7 +75,6 @@ G_GNUC_INTERNAL extern GSystemThread zero_thread;
G_GNUC_INTERNAL extern GMutex g_once_mutex;
G_GNUC_INTERNAL void g_enumerable_thread_add (GRealThread *thread);
-G_GNUC_INTERNAL void g_enumerable_thread_remove (GRealThread *thread);
/* initializers that may also use g_private_new() */
G_GNUC_INTERNAL void _g_messages_thread_init_nomessage (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]