thread: drop thread setup function hackery
authorRyan Lortie <desrt@desrt.ca>
Thu, 13 Oct 2011 01:44:07 +0000 (21:44 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 13 Oct 2011 01:48:02 +0000 (21:48 -0400)
Use a custom proxy function for the deprecated case instead.

Now GRealThread has strictly zero members dedicated to deprecated
functionality.

glib/deprecated/gthread-deprecated.c
glib/gthread.c
glib/gthreadprivate.h

index 45cb911ad4f05e016b9ba18da8b020d7dca87303..1e99694c35736ce28ac1fa8aa39743728f871cad 100644 (file)
@@ -291,6 +291,17 @@ g_enumerable_thread_add (GRealThread *thread)
 
   g_private_set (&enumerable_thread_private, thread);
 }
+
+static gpointer
+g_deprecated_thread_proxy (gpointer data)
+{
+  GRealThread *real = data;
+
+  g_enumerable_thread_add (real);
+
+  return g_thread_proxy (data);
+}
+
 /**
  * g_thread_create:
  * @func: a function to execute in the new thread
@@ -320,7 +331,7 @@ g_thread_create (GThreadFunc   func,
                  gboolean      joinable,
                  GError      **error)
 {
-  return g_thread_new_internal (NULL, func, data, joinable, 0, g_enumerable_thread_add, error);
+  return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, 0, error);
 }
 
 /**
@@ -348,7 +359,7 @@ g_thread_create_full (GThreadFunc       func,
                       GThreadPriority   priority,
                       GError          **error)
 {
-  return g_thread_new_internal (NULL, func, data, joinable, stack_size, g_enumerable_thread_add, error);
+  return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, stack_size, error);
 }
 
 
index 23fd703db0f3cbdd8394c8a56d05163cb001e4a6..27cdc0854d55dad6057c2a4abfb0d15aef7552b1 100644 (file)
@@ -681,8 +681,8 @@ g_thread_cleanup (gpointer data)
     }
 }
 
-static gpointer
-g_thread_create_proxy (gpointer data)
+gpointer
+g_thread_proxy (gpointer data)
 {
   GRealThread* thread = data;
 
@@ -694,9 +694,6 @@ 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->setup_func)
-    thread->setup_func (thread);
-
   /* The lock makes sure that thread->system_thread is written,
    * before thread->thread.func is called. See g_thread_new_internal().
    */
@@ -743,7 +740,7 @@ g_thread_new (const gchar  *name,
               gboolean      joinable,
               GError      **error)
 {
-  return g_thread_new_internal (name, func, data, joinable, 0, FALSE, error);
+  return g_thread_new_internal (name, g_thread_proxy, func, data, joinable, 0, error);
 }
 
 /**
@@ -790,16 +787,16 @@ g_thread_new_full (const gchar  *name,
                    gsize         stack_size,
                    GError      **error)
 {
-  return g_thread_new_internal (name, func, data, joinable, stack_size, FALSE, error);
+  return g_thread_new_internal (name, g_thread_proxy, func, data, joinable, stack_size, error);
 }
 
 GThread *
 g_thread_new_internal (const gchar   *name,
+                       GThreadFunc    proxy,
                        GThreadFunc    func,
                        gpointer       data,
                        gboolean       joinable,
                        gsize          stack_size,
-                       GThreadSetup   setup_func,
                        GError       **error)
 {
   GRealThread *result;
@@ -812,11 +809,9 @@ g_thread_new_internal (const gchar   *name,
   result->thread.joinable = joinable;
   result->thread.func = func;
   result->thread.data = data;
-  result->setup_func = setup_func;
   result->name = name;
   G_LOCK (g_thread_new);
-  g_system_thread_create (g_thread_create_proxy, result,
-                          stack_size, joinable,
+  g_system_thread_create (proxy, result, stack_size, joinable,
                           &result->system_thread, &local_error);
   G_UNLOCK (g_thread_new);
 
index 3f9fa9b3ad7b4c10cc684c73743db3b6af44283f..3aebf72415ad0c88376b9447ec35877c33136bc3 100644 (file)
@@ -30,7 +30,6 @@
 G_BEGIN_DECLS
 
 typedef struct _GRealThread GRealThread;
-typedef void (*GThreadSetup) (GRealThread *thread);
 
 G_GNUC_INTERNAL void     g_system_thread_join  (gpointer thread);
 G_GNUC_INTERNAL void     g_system_thread_create (GThreadFunc       func,
@@ -44,18 +43,20 @@ G_GNUC_INTERNAL void     g_system_thread_exit  (void);
 G_GNUC_INTERNAL void     g_system_thread_set_name (const gchar *name);
 
 G_GNUC_INTERNAL GThread *g_thread_new_internal (const gchar   *name,
+                                                GThreadFunc    proxy,
                                                 GThreadFunc    func,
                                                 gpointer       data,
                                                 gboolean       joinable,
                                                 gsize          stack_size,
-                                                GThreadSetup   setup_func,
                                                 GError       **error);
 
+G_GNUC_INTERNAL
+gpointer        g_thread_proxy                  (gpointer     thread);
+
 struct  _GRealThread
 {
   GThread thread;
   const gchar *name;
-  GThreadSetup setup_func;
   gpointer retval;
   GSystemThread system_thread;
 };