[glib/wip/mutexes: 46/58] GSystemThread: port 'self' 'join' and 'create'



commit 03c371dbf3e4aab96a3618d4a77eabf3f9144783
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Sep 18 23:58:12 2011 -0400

    GSystemThread: port 'self' 'join' and 'create'
    
    Switch 'self' 'join' and 'create' from using the vtable to being called
    via normal g_system_thread_* internal API (implemented in each of
    gthread-{posix,win32}.c).
    
    Again, we can put NULL in the vtable since these were never used from
    gthread.h.

 glib/gthread-posix.c  |   32 ++++++++++++++++----------------
 glib/gthread-win32.c  |   32 ++++++++++++++++----------------
 glib/gthread.c        |   18 +++++++++---------
 glib/gthreadprivate.h |   10 ++++++++++
 4 files changed, 51 insertions(+), 41 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 950e571..3e7349f 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -492,15 +492,15 @@ _g_thread_impl_init(void)
 #endif /* _SC_THREAD_STACK_MIN */
 }
 
-static void
-g_thread_create_posix_impl (GThreadFunc thread_func,
-			    gpointer arg,
-			    gulong stack_size,
-			    gboolean joinable,
-			    gboolean bound,
-			    GThreadPriority priority,
-			    gpointer thread,
-			    GError **error)
+void
+g_system_thread_create (GThreadFunc       thread_func,
+                        gpointer          arg,
+                        gulong            stack_size,
+                        gboolean          joinable,
+                        gboolean          bound,
+                        GThreadPriority   priority,
+                        gpointer          thread,
+                        GError          **error)
 {
   pthread_attr_t attr;
   gint ret;
@@ -558,8 +558,8 @@ g_thread_yield (void)
   sched_yield ();
 }
 
-static void
-g_thread_join_posix_impl (gpointer thread)
+void
+g_system_thread_join (gpointer thread)
 {
   gpointer ignore;
   posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore));
@@ -571,8 +571,8 @@ g_system_thread_exit (void)
   pthread_exit (NULL);
 }
 
-static void
-g_thread_self_posix_impl (gpointer thread)
+void
+g_system_thread_self (gpointer thread)
 {
   *(pthread_t*)thread = pthread_self();
 }
@@ -601,12 +601,12 @@ GThreadFunctions g_thread_functions_for_glib_use =
   g_private_new,
   g_private_get,
   g_private_set,
-  g_thread_create_posix_impl,
+  NULL,
   g_thread_yield,
-  g_thread_join_posix_impl,
+  NULL,
   g_system_thread_exit,
   NULL,
-  g_thread_self_posix_impl,
+  NULL,
   g_system_thread_equal,
 };
 
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index a71dae2..97a10d2 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -316,8 +316,8 @@ struct _GThreadData
   gboolean joinable;
 };
 
-static void
-g_thread_self_win32_impl (gpointer thread)
+void
+g_system_thread_self (gpointer thread)
 {
   GThreadData *self = TlsGetValue (g_thread_self_tls);
 
@@ -406,15 +406,15 @@ g_thread_proxy (gpointer data)
   return 0;
 }
 
-static void
-g_thread_create_win32_impl (GThreadFunc func,
-			    gpointer data,
-			    gulong stack_size,
-			    gboolean joinable,
-			    gboolean bound,
-			    GThreadPriority priority,
-			    gpointer thread,
-			    GError **error)
+void
+g_system_thread_create (GThreadFunc       func,
+                        gpointer          data,
+                        gulong            stack_size,
+                        gboolean          joinable,
+                        gboolean          bound,
+                        GThreadPriority   priority,
+                        gpointer          thread,
+                        GError          **error)
 {
   guint ignore;
   GThreadData *retval;
@@ -449,8 +449,8 @@ g_thread_yield (void)
   Sleep(0);
 }
 
-static void
-g_thread_join_win32_impl (gpointer thread)
+void
+g_system_thread_join (gpointer thread)
 {
   GThreadData *target = *(GThreadData **)thread;
 
@@ -768,12 +768,12 @@ GThreadFunctions g_thread_functions_for_glib_use =
   g_private_new,         /* private thread data */
   g_private_get,
   g_private_set,
-  g_thread_create_win32_impl,       /* thread */
+  NULL,                  /* thread */
   g_thread_yield,
-  g_thread_join_win32_impl,
+  NULL,
   g_system_thread_exit,
   NULL,
-  g_thread_self_win32_impl,
+  NULL,
   g_system_thread_equal
 };
 
diff --git a/glib/gthread.c b/glib/gthread.c
index dd99afa..a9b162d 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -708,7 +708,7 @@ g_thread_init_glib (void)
   g_threads_got_initialized = TRUE;
   g_private_init (&g_thread_specific_private, g_thread_cleanup);
   g_private_set (&g_thread_specific_private, main_thread);
-  G_THREAD_UF (thread_self, (&main_thread->system_thread));
+  g_system_thread_self (&main_thread->system_thread);
 
   /* accomplish log system initialization to enable messaging */
   _g_messages_thread_init_nomessage ();
@@ -1188,7 +1188,7 @@ g_static_rec_mutex_lock (GStaticRecMutex* mutex)
   if (!g_thread_supported ())
     return;
 
-  G_THREAD_UF (thread_self, (&self));
+  g_system_thread_self (&self);
 
   if (g_system_thread_equal (&self, &mutex->owner))
     {
@@ -1221,7 +1221,7 @@ g_static_rec_mutex_trylock (GStaticRecMutex* mutex)
   if (!g_thread_supported ())
     return TRUE;
 
-  G_THREAD_UF (thread_self, (&self));
+  g_system_thread_self (&self);
 
   if (g_system_thread_equal (&self, &mutex->owner))
     {
@@ -1285,7 +1285,7 @@ g_static_rec_mutex_lock_full   (GStaticRecMutex *mutex,
   if (depth == 0)
     return;
 
-  G_THREAD_UF (thread_self, (&self));
+  g_system_thread_self (&self);
 
   if (g_system_thread_equal (&self, &mutex->owner))
     {
@@ -1771,9 +1771,9 @@ g_thread_create_full (GThreadFunc       func,
   result->thread.data = data;
   result->private_data = NULL;
   G_LOCK (g_thread);
-  G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
-			       stack_size, joinable, bound, 0,
-			       &result->system_thread, &local_error));
+  g_system_thread_create (g_thread_create_proxy, result,
+                          stack_size, joinable, bound, 0,
+                          &result->system_thread, &local_error);
   if (!local_error)
     {
       result->next = g_thread_all_threads;
@@ -1844,7 +1844,7 @@ g_thread_join (GThread* thread)
   g_return_val_if_fail (thread->joinable, NULL);
   g_return_val_if_fail (!g_system_thread_equal (&real->system_thread, &zero_thread), NULL);
 
-  G_THREAD_UF (thread_join, (&real->system_thread));
+  g_system_thread_join (&real->system_thread);
 
   retval = real->retval;
 
@@ -1913,7 +1913,7 @@ g_thread_self (void)
       thread->thread.data = NULL;
       thread->private_data = NULL;
 
-      G_THREAD_UF (thread_self, (&thread->system_thread));
+      g_system_thread_self (&thread->system_thread);
 
       g_private_set (&g_thread_specific_private, thread);
 
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 15f2452..f4d7288 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -34,6 +34,16 @@ G_BEGIN_DECLS
    (memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
 #endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */
 
+G_GNUC_INTERNAL void     g_system_thread_self  (gpointer thread);
+G_GNUC_INTERNAL void     g_system_thread_join  (gpointer thread);
+G_GNUC_INTERNAL void     g_system_thread_create (GThreadFunc       func,
+                                                 gpointer          data,
+                                                 gulong            stack_size,
+                                                 gboolean          joinable,
+                                                 gboolean          bound,
+                                                 GThreadPriority   priority,
+                                                 gpointer          thread,
+                                                 GError          **error);
 G_GNUC_INTERNAL gboolean g_system_thread_equal (gpointer thread1,
                                                 gpointer thread2);
 



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