[glib] Combine g_sytem_thread_{new,create}()



commit e14a3746db8c9979b3d9840602be5f79af501605
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Oct 12 22:29:13 2011 -0400

    Combine g_sytem_thread_{new,create}()

 glib/gthread-posix.c  |   24 ++++++++++--------------
 glib/gthread-win32.c  |   25 ++++++++++---------------
 glib/gthread.c        |   11 ++++-------
 glib/gthreadprivate.h |   12 +++++-------
 4 files changed, 29 insertions(+), 43 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 4f29c7b..f640c00 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1069,29 +1069,23 @@ g_private_replace (GPrivate *key,
 
 #define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
 
-GRealThread *
-g_system_thread_new (void)
-{
-  return g_slice_new0 (GRealThread);
-}
-
 void
 g_system_thread_free (GRealThread *thread)
 {
   g_slice_free (GRealThread, thread);
 }
 
-void
-g_system_thread_create (GThreadFunc       thread_func,
-                        gulong            stack_size,
-                        gboolean          joinable,
-                        GRealThread      *thread,
-                        GError          **error)
+GRealThread *
+g_system_thread_new (GThreadFunc   thread_func,
+                     gulong        stack_size,
+                     gboolean      joinable,
+                     GError      **error)
 {
+  GRealThread *thread;
   pthread_attr_t attr;
   gint ret;
 
-  g_return_if_fail (thread_func);
+  thread = g_slice_new0 (GRealThread);
 
   posix_check_cmd (pthread_attr_init (&attr));
 
@@ -1118,10 +1112,12 @@ g_system_thread_create (GThreadFunc       thread_func,
     {
       g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN, 
 		   "Error creating thread: %s", g_strerror (ret));
-      return;
+      return thread;
     }
 
   posix_check_err (ret, "pthread_create");
+
+  return thread;
 }
 
 /**
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index 72be9a4..e380b84 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -463,12 +463,6 @@ struct _GThreadData
   gboolean joinable;
 };
 
-GRealThread *
-g_system_thread_new (void)
-{
-  return g_slice_new0 (GRealThread);
-}
-
 void
 g_system_thread_free (GRealThread *thread)
 {
@@ -497,18 +491,17 @@ g_thread_proxy (gpointer data)
   return 0;
 }
 
-void
-g_system_thread_create (GThreadFunc       func,
-                        gulong            stack_size,
-                        gboolean          joinable,
-                        GRealThread      *thread,
-                        GError          **error)
+GRealThread *
+g_system_thread_new (GThreadFunc   func,
+                     gulong        stack_size,
+                     gboolean      joinable,
+                     GError      **error)
 {
+  GRealThread *thread;
   guint ignore;
   GThreadData *retval;
 
-  g_return_if_fail (func);
-
+  thread = g_slice_new0 (GRealThread);
   retval = g_new(GThreadData, 1);
   retval->func = func;
   retval->data = thread;
@@ -525,10 +518,12 @@ g_system_thread_create (GThreadFunc       func,
                    "Error creating thread: %s", win_error);
       g_free (retval);
       g_free (win_error);
-      return;
+      return thread;
     }
 
   *(GThreadData **) &(thread->system_thread) = retval;
+
+  return thread;
 }
 
 void
diff --git a/glib/gthread.c b/glib/gthread.c
index e6c0c70..e259bad 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -694,8 +694,8 @@ g_thread_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);
 
-  /* The lock makes sure that thread->system_thread is written,
-   * before thread->thread.func is called. See g_thread_new_internal().
+  /* The lock makes sure that g_thread_new_internal() has a chance to
+   * setup 'func' and 'data' before we make the call.
    */
   G_LOCK (g_thread_new);
   G_UNLOCK (g_thread_new);
@@ -804,15 +804,12 @@ g_thread_new_internal (const gchar   *name,
 
   g_return_val_if_fail (func != NULL, NULL);
 
-  result = g_system_thread_new ();
-
+  G_LOCK (g_thread_new);
+  result = g_system_thread_new (proxy, stack_size, joinable, &local_error);
   result->thread.joinable = joinable;
   result->thread.func = func;
   result->thread.data = data;
   result->name = name;
-  G_LOCK (g_thread_new);
-  g_system_thread_create (proxy, stack_size, joinable,
-                          result, &local_error);
   G_UNLOCK (g_thread_new);
 
   if (local_error)
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 58f065a..565cd10 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -32,15 +32,13 @@ G_BEGIN_DECLS
 typedef struct _GRealThread GRealThread;
 
 G_GNUC_INTERNAL
-void            g_system_thread_wait            (GRealThread      *thread);
+void            g_system_thread_wait            (GRealThread  *thread);
 
 G_GNUC_INTERNAL
-GRealThread *   g_system_thread_new             (void);
-G_GNUC_INTERNAL void     g_system_thread_create (GThreadFunc       func,
-                                                 gulong            stack_size,
-                                                 gboolean          joinable,
-                                                 GRealThread      *thread,
-                                                 GError          **error);
+GRealThread *   g_system_thread_new             (GThreadFunc   func,
+                                                 gulong        stack_size,
+                                                 gboolean      joinable,
+                                                 GError      **error);
 G_GNUC_INTERNAL
 void            g_system_thread_free            (GRealThread  *thread);
 



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