diff options
author | Sebastian Wilhelmi <wilhelmi@google.com> | 2006-05-10 00:44:50 +0000 |
---|---|---|
committer | Sebastian Wilhelmi <wilhelmi@src.gnome.org> | 2006-05-10 00:44:50 +0000 |
commit | e4f8f3b95c2a3b4188a38378bd30b548dba505c2 (patch) | |
tree | 7c51c50729c143d4bae67da6de9914f109e3e9a4 /gthread | |
parent | 307391459ddd322bccee190d8ded32fb462e8c50 (diff) |
Renamed to glib/gthreadprivate.h and moved system thread identifier
2006-05-09 Sebastian Wilhelmi <wilhelmi@google.com>
* glib/gthreadinit.h: Renamed to glib/gthreadprivate.h and moved
system thread identifier comparision and assignment macros from
glib/gthread.c to glib/gthreadprivate.h.
* glib/Makefile.am, glib/gatomic.c, glib/gconvert.c, glib/gmain.c,
glib/gmem.c, glib/gmessages.c, glib/grand.c, glib/gslice.c,
glib/gthread.c, glib/gutils.c, gthread/gthread-impl.c: Use
glib/gthreadprivate.h instead of glib/gthreadinit.h.
* gthread/gthread-impl.c: Use GSystemThread instead of GThread for
owner determination. This fixes #311043 and is mostly modeled
after the patch from jylefort@FreeBSD.org.
Diffstat (limited to 'gthread')
-rw-r--r-- | gthread/gthread-impl.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index 7c20b65f1..89e7ffc84 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -34,10 +34,11 @@ #include "config.h" #include "glib.h" -#include "gthreadinit.h" +#include "gthreadprivate.h" #ifdef G_THREADS_ENABLED +static GSystemThread zero_thread; /* This is initialized to all zero */ static gboolean thread_system_already_initialized = FALSE; static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT + 1]; @@ -74,7 +75,7 @@ typedef struct _ErrorCheckInfo ErrorCheckInfo; struct _ErrorCheckInfo { gchar *location; - GThread *owner; + GSystemThread owner; }; static GMutex * @@ -92,7 +93,9 @@ g_mutex_lock_errorcheck_impl (GMutex *mutex, gchar *location) { ErrorCheckInfo *info; - GThread *self = g_thread_self (); + GSystemThread self; + + g_thread_functions_for_glib_use.thread_self (&self); if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; @@ -114,14 +117,14 @@ g_mutex_lock_errorcheck_impl (GMutex *mutex, } info = G_MUTEX_DEBUG_INFO (mutex); - if (info->owner == self) + if (g_system_thread_equal (info->owner, self)) g_error ("Trying to recursivly lock a mutex at '%s', " "previously locked at '%s'", location, info->location); g_thread_functions_for_glib_use_default.mutex_lock (mutex); - info->owner = self; + g_system_thread_assign (info->owner, self); info->location = location; } @@ -131,7 +134,9 @@ g_mutex_trylock_errorcheck_impl (GMutex *mutex, gchar *location) { ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex); - GThread *self = g_thread_self (); + GSystemThread self; + + g_thread_functions_for_glib_use.thread_self (&self); if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; @@ -143,7 +148,7 @@ g_mutex_trylock_errorcheck_impl (GMutex *mutex, return TRUE; } - if (info->owner == self) + if (g_system_thread_equal (info->owner, self)) g_error ("Trying to recursivly lock a mutex at '%s', " "previously locked at '%s'", location, info->location); @@ -151,7 +156,7 @@ g_mutex_trylock_errorcheck_impl (GMutex *mutex, if (!g_thread_functions_for_glib_use_default.mutex_trylock (mutex)) return FALSE; - info->owner = self; + g_system_thread_assign (info->owner, self); info->location = location; return TRUE; @@ -163,20 +168,22 @@ g_mutex_unlock_errorcheck_impl (GMutex *mutex, gchar *location) { ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex); - GThread *self = g_thread_self (); + GSystemThread self; + + g_thread_functions_for_glib_use.thread_self (&self); if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; - if (!info || info->owner == NULL) + if (!info || g_system_thread_equal (info->owner, zero_thread)) g_error ("Trying to unlock an unlocked mutex at '%s'", location); - if (info->owner != self) + if (!g_system_thread_equal (info->owner, self)) g_warning ("Trying to unlock a mutex at '%s', " "previously locked by a different thread at '%s'", location, info->location); - info->owner = NULL; + g_system_thread_assign (info->owner, zero_thread); info->location = NULL; g_thread_functions_for_glib_use_default.mutex_unlock (mutex); @@ -192,7 +199,7 @@ g_mutex_free_errorcheck_impl (GMutex *mutex, if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; - if (info && info->owner != NULL) + if (info && !g_system_thread_equal (info->owner, zero_thread)) g_error ("Trying to free a locked mutex at '%s', " "which was previously locked at '%s'", location, info->location); @@ -209,25 +216,27 @@ g_cond_wait_errorcheck_impl (GCond *cond, { ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex); - GThread *self = g_thread_self (); + GSystemThread self; + + g_thread_functions_for_glib_use.thread_self (&self); if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; - if (!info || info->owner == NULL) + if (!info || g_system_thread_equal (info->owner, zero_thread)) g_error ("Trying to use an unlocked mutex in g_cond_wait() at '%s'", location); - if (info->owner != self) + if (!g_system_thread_equal (info->owner, self)) g_error ("Trying to use a mutex locked by another thread in " "g_cond_wait() at '%s'", location); - info->owner = NULL; + g_system_thread_assign (info->owner, zero_thread); location = info->location; g_thread_functions_for_glib_use_default.cond_wait (cond, mutex); - info->owner = self; + g_system_thread_assign (info->owner, self); info->location = location; } @@ -240,28 +249,30 @@ g_cond_timed_wait_errorcheck_impl (GCond *cond, gchar *location) { ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex); - GThread *self = g_thread_self (); + GSystemThread self; gboolean retval; + g_thread_functions_for_glib_use.thread_self (&self); + if (magic != G_MUTEX_DEBUG_MAGIC) location = "unknown"; - if (!info || info->owner == NULL) + if (!info || g_system_thread_equal (info->owner, zero_thread)) g_error ("Trying to use an unlocked mutex in g_cond_timed_wait() at '%s'", location); - if (info->owner != self) + if (!g_system_thread_equal (info->owner, self)) g_error ("Trying to use a mutex locked by another thread in " "g_cond_timed_wait() at '%s'", location); - info->owner = NULL; + g_system_thread_assign (info->owner, zero_thread); location = info->location; retval = g_thread_functions_for_glib_use_default.cond_timed_wait (cond, mutex, end_time); - info->owner = self; + g_system_thread_assign (info->owner, self); info->location = location; return retval; |