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.
This commit is contained in:
Ryan Lortie 2011-09-18 23:58:12 -04:00
parent 51d92adeee
commit 7a69d46dc5
4 changed files with 51 additions and 41 deletions

View File

@ -492,15 +492,15 @@ _g_thread_impl_init(void)
#endif /* _SC_THREAD_STACK_MIN */ #endif /* _SC_THREAD_STACK_MIN */
} }
static void void
g_thread_create_posix_impl (GThreadFunc thread_func, g_system_thread_create (GThreadFunc thread_func,
gpointer arg, gpointer arg,
gulong stack_size, gulong stack_size,
gboolean joinable, gboolean joinable,
gboolean bound, gboolean bound,
GThreadPriority priority, GThreadPriority priority,
gpointer thread, gpointer thread,
GError **error) GError **error)
{ {
pthread_attr_t attr; pthread_attr_t attr;
gint ret; gint ret;
@ -558,8 +558,8 @@ g_thread_yield (void)
sched_yield (); sched_yield ();
} }
static void void
g_thread_join_posix_impl (gpointer thread) g_system_thread_join (gpointer thread)
{ {
gpointer ignore; gpointer ignore;
posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore)); posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore));
@ -571,8 +571,8 @@ g_system_thread_exit (void)
pthread_exit (NULL); pthread_exit (NULL);
} }
static void void
g_thread_self_posix_impl (gpointer thread) g_system_thread_self (gpointer thread)
{ {
*(pthread_t*)thread = pthread_self(); *(pthread_t*)thread = pthread_self();
} }
@ -601,12 +601,12 @@ GThreadFunctions g_thread_functions_for_glib_use =
g_private_new, g_private_new,
g_private_get, g_private_get,
g_private_set, g_private_set,
g_thread_create_posix_impl, NULL,
g_thread_yield, g_thread_yield,
g_thread_join_posix_impl, NULL,
g_system_thread_exit, g_system_thread_exit,
NULL, NULL,
g_thread_self_posix_impl, NULL,
g_system_thread_equal, g_system_thread_equal,
}; };

View File

@ -316,8 +316,8 @@ struct _GThreadData
gboolean joinable; gboolean joinable;
}; };
static void void
g_thread_self_win32_impl (gpointer thread) g_system_thread_self (gpointer thread)
{ {
GThreadData *self = TlsGetValue (g_thread_self_tls); GThreadData *self = TlsGetValue (g_thread_self_tls);
@ -406,15 +406,15 @@ g_thread_proxy (gpointer data)
return 0; return 0;
} }
static void void
g_thread_create_win32_impl (GThreadFunc func, g_system_thread_create (GThreadFunc func,
gpointer data, gpointer data,
gulong stack_size, gulong stack_size,
gboolean joinable, gboolean joinable,
gboolean bound, gboolean bound,
GThreadPriority priority, GThreadPriority priority,
gpointer thread, gpointer thread,
GError **error) GError **error)
{ {
guint ignore; guint ignore;
GThreadData *retval; GThreadData *retval;
@ -449,8 +449,8 @@ g_thread_yield (void)
Sleep(0); Sleep(0);
} }
static void void
g_thread_join_win32_impl (gpointer thread) g_system_thread_join (gpointer thread)
{ {
GThreadData *target = *(GThreadData **)thread; GThreadData *target = *(GThreadData **)thread;
@ -768,12 +768,12 @@ GThreadFunctions g_thread_functions_for_glib_use =
g_private_new, /* private thread data */ g_private_new, /* private thread data */
g_private_get, g_private_get,
g_private_set, g_private_set,
g_thread_create_win32_impl, /* thread */ NULL, /* thread */
g_thread_yield, g_thread_yield,
g_thread_join_win32_impl, NULL,
g_system_thread_exit, g_system_thread_exit,
NULL, NULL,
g_thread_self_win32_impl, NULL,
g_system_thread_equal g_system_thread_equal
}; };

View File

@ -708,7 +708,7 @@ g_thread_init_glib (void)
g_threads_got_initialized = TRUE; g_threads_got_initialized = TRUE;
g_private_init (&g_thread_specific_private, g_thread_cleanup); g_private_init (&g_thread_specific_private, g_thread_cleanup);
g_private_set (&g_thread_specific_private, main_thread); 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 */ /* accomplish log system initialization to enable messaging */
_g_messages_thread_init_nomessage (); _g_messages_thread_init_nomessage ();
@ -1188,7 +1188,7 @@ g_static_rec_mutex_lock (GStaticRecMutex* mutex)
if (!g_thread_supported ()) if (!g_thread_supported ())
return; return;
G_THREAD_UF (thread_self, (&self)); g_system_thread_self (&self);
if (g_system_thread_equal (&self, &mutex->owner)) if (g_system_thread_equal (&self, &mutex->owner))
{ {
@ -1221,7 +1221,7 @@ g_static_rec_mutex_trylock (GStaticRecMutex* mutex)
if (!g_thread_supported ()) if (!g_thread_supported ())
return TRUE; return TRUE;
G_THREAD_UF (thread_self, (&self)); g_system_thread_self (&self);
if (g_system_thread_equal (&self, &mutex->owner)) if (g_system_thread_equal (&self, &mutex->owner))
{ {
@ -1285,7 +1285,7 @@ g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
if (depth == 0) if (depth == 0)
return; return;
G_THREAD_UF (thread_self, (&self)); g_system_thread_self (&self);
if (g_system_thread_equal (&self, &mutex->owner)) if (g_system_thread_equal (&self, &mutex->owner))
{ {
@ -1771,9 +1771,9 @@ g_thread_create_full (GThreadFunc func,
result->thread.data = data; result->thread.data = data;
result->private_data = NULL; result->private_data = NULL;
G_LOCK (g_thread); G_LOCK (g_thread);
G_THREAD_UF (thread_create, (g_thread_create_proxy, result, g_system_thread_create (g_thread_create_proxy, result,
stack_size, joinable, bound, 0, stack_size, joinable, bound, 0,
&result->system_thread, &local_error)); &result->system_thread, &local_error);
if (!local_error) if (!local_error)
{ {
result->next = g_thread_all_threads; 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 (thread->joinable, NULL);
g_return_val_if_fail (!g_system_thread_equal (&real->system_thread, &zero_thread), 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; retval = real->retval;
@ -1913,7 +1913,7 @@ g_thread_self (void)
thread->thread.data = NULL; thread->thread.data = NULL;
thread->private_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); g_private_set (&g_thread_specific_private, thread);

View File

@ -34,6 +34,16 @@ G_BEGIN_DECLS
(memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD)) (memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
#endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */ #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, G_GNUC_INTERNAL gboolean g_system_thread_equal (gpointer thread1,
gpointer thread2); gpointer thread2);