[glib] thread: use GSList for g_thread_foreach list
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] thread: use GSList for g_thread_foreach list
- Date: Wed, 12 Oct 2011 21:16:30 +0000 (UTC)
commit 96904b679061d78da65bf0dd0b331f4a3c754b3d
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Oct 12 17:01:33 2011 -0400
thread: use GSList for g_thread_foreach list
...instead of having a 'next' pointer in the GThread struct.
Now GThread contains no fields used only by deprecated code (except for
the rather generic setup function field).
glib/deprecated/gthread-deprecated.c | 28 ++++++++--------------------
glib/gthreadprivate.h | 1 -
2 files changed, 8 insertions(+), 21 deletions(-)
---
diff --git a/glib/deprecated/gthread-deprecated.c b/glib/deprecated/gthread-deprecated.c
index 3dcc2b0..89e004f 100644
--- a/glib/deprecated/gthread-deprecated.c
+++ b/glib/deprecated/gthread-deprecated.c
@@ -197,7 +197,7 @@ void g_thread_init_glib (void) { }
/* Internal variables {{{1 */
-static GRealThread *g_thread_all_threads = NULL;
+static GSList *g_thread_all_threads = NULL;
static GSList *g_thread_free_indices = NULL;
/* Protects g_thread_all_threads and g_thread_free_indices */
@@ -252,8 +252,7 @@ g_thread_foreach (GFunc thread_func,
g_return_if_fail (thread_func != NULL);
/* snapshot the list of threads for iteration */
G_LOCK (g_thread);
- for (thread = g_thread_all_threads; thread; thread = thread->next)
- slist = g_slist_prepend (slist, thread);
+ slist = g_slist_copy (g_thread_all_threads);
G_UNLOCK (g_thread);
/* walk the list, skipping non-existent threads */
while (slist)
@@ -262,9 +261,10 @@ g_thread_foreach (GFunc thread_func,
slist = node->next;
/* check whether the current thread still exists */
G_LOCK (g_thread);
- for (thread = g_thread_all_threads; thread; thread = thread->next)
- if (thread == node->data)
- break;
+ if (g_slist_find (g_thread_all_threads, node->data))
+ thread = node->data;
+ else
+ thread = NULL;
G_UNLOCK (g_thread);
if (thread)
thread_func (thread, user_data);
@@ -276,20 +276,9 @@ static void
g_enumerable_thread_remove (gpointer data)
{
GRealThread *thread = data;
- GRealThread *t, *p;
G_LOCK (g_thread);
- for (t = g_thread_all_threads, p = NULL; t; p = t, t = t->next)
- {
- if (t == thread)
- {
- if (p)
- p->next = t->next;
- else
- g_thread_all_threads = t->next;
- break;
- }
- }
+ g_thread_all_threads = g_slist_remove (g_thread_all_threads, thread);
G_UNLOCK (g_thread);
}
@@ -299,8 +288,7 @@ static void
g_enumerable_thread_add (GRealThread *thread)
{
G_LOCK (g_thread);
- thread->next = g_thread_all_threads;
- g_thread_all_threads = thread;
+ g_thread_all_threads = g_slist_prepend (g_thread_all_threads, thread);
G_UNLOCK (g_thread);
g_private_set (&enumerable_thread_private, thread);
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index b467d7b..2b42620 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -66,7 +66,6 @@ G_GNUC_INTERNAL GThread *g_thread_new_internal (const gchar *name,
struct _GRealThread
{
GThread thread;
- GRealThread *next;
const gchar *name;
GThreadSetup setup_func;
gpointer retval;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]