Don't use the thread_equal vfunc anymore

Just move the g_system_thread_equal implementation into
the posix and win32 implementations, and drop some micro macro
optimization.
This commit is contained in:
Matthias Clasen 2011-09-18 23:10:25 -04:00 committed by Ryan Lortie
parent e00bcfcdec
commit cc7631cd19
4 changed files with 18 additions and 17 deletions

View File

@ -681,8 +681,9 @@ g_thread_self_posix_impl (gpointer thread)
*(pthread_t*)thread = pthread_self();
}
static gboolean
g_thread_equal_posix_impl (gpointer thread1, gpointer thread2)
gboolean
g_system_thread_equal (gpointer thread1,
gpointer thread2)
{
return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
}
@ -710,7 +711,7 @@ GThreadFunctions g_thread_functions_for_glib_use =
g_thread_exit_posix_impl,
g_thread_set_priority_posix_impl,
g_thread_self_posix_impl,
g_thread_equal_posix_impl
g_system_thread_equal,
};
/* vim:set foldmethod=marker: */

View File

@ -499,6 +499,13 @@ g_thread_join_win32_impl (gpointer thread)
g_free (target);
}
gboolean
g_system_thread_equal (gpointer thread1,
gpointer thread2)
{
return ((GSystemThread*)thread1)->dummy_pointer == ((GSystemThread*)thread2)->dummy_pointer;
}
/* {{{1 SRWLock and CONDITION_VARIABLE emulation (for Windows XP) */
static CRITICAL_SECTION g_thread_xp_lock;

View File

@ -1196,7 +1196,7 @@ g_static_rec_mutex_lock (GStaticRecMutex* mutex)
G_THREAD_UF (thread_self, (&self));
if (g_system_thread_equal (self, mutex->owner))
if (g_system_thread_equal (&self, &mutex->owner))
{
mutex->depth++;
return;
@ -1229,7 +1229,7 @@ g_static_rec_mutex_trylock (GStaticRecMutex* mutex)
G_THREAD_UF (thread_self, (&self));
if (g_system_thread_equal (self, mutex->owner))
if (g_system_thread_equal (&self, &mutex->owner))
{
mutex->depth++;
return TRUE;
@ -1293,7 +1293,7 @@ g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
G_THREAD_UF (thread_self, (&self));
if (g_system_thread_equal (self, mutex->owner))
if (g_system_thread_equal (&self, &mutex->owner))
{
mutex->depth += depth;
return;
@ -1859,8 +1859,7 @@ g_thread_join (GThread* thread)
g_return_val_if_fail (thread, 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));
@ -1913,7 +1912,7 @@ g_thread_set_priority (GThread* thread,
GRealThread* real = (GRealThread*) thread;
g_return_if_fail (thread);
g_return_if_fail (!g_system_thread_equal (real->system_thread, zero_thread));
g_return_if_fail (!g_system_thread_equal (&real->system_thread, &zero_thread));
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);

View File

@ -27,21 +27,15 @@ G_BEGIN_DECLS
/* System thread identifier comparison and assignment */
#if GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P
# define g_system_thread_equal_simple(thread1, thread2) \
((thread1).dummy_pointer == (thread2).dummy_pointer)
# define g_system_thread_assign(dest, src) \
((dest).dummy_pointer = (src).dummy_pointer)
#else /* GLIB_SIZEOF_SYSTEM_THREAD != SIZEOF_VOID_P */
# define g_system_thread_equal_simple(thread1, thread2) \
(memcmp (&(thread1), &(thread2), GLIB_SIZEOF_SYSTEM_THREAD) == 0)
# define g_system_thread_assign(dest, src) \
(memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
#endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */
#define g_system_thread_equal(thread1, thread2) \
(g_thread_functions_for_glib_use.thread_equal ? \
g_thread_functions_for_glib_use.thread_equal (&(thread1), &(thread2)) :\
g_system_thread_equal_simple((thread1), (thread2)))
G_GNUC_INTERNAL gboolean g_system_thread_equal (gpointer thread1,
gpointer thread2);
/* Is called from gthread/gthread-impl.c */
void g_thread_init_glib (void);