mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-28 11:54:15 +02:00
Revamped errorcheck mutexes and added errorcheck cond_wait() and
2000-11-28 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * gthread-impl.c: Revamped errorcheck mutexes and added errorcheck cond_wait() and cond_timed_wait() funtions. This makes he whole thing work. Now we only show the location of the locking/unlocking for -DG_ERRORCHECK_MUTEXES and not the name of the mutex. * gthread.c: Set the thread data before locking the mutex, because the locking call might use g_thread_self (). * gthread.h: Do only show the location of the locking/unlocking for -DG_ERRORCHECK_MUTEXES and not the name of the mutex. Add the errorcheck capability for g_cond_wait and g_cond_timed_wait as well.
This commit is contained in:
committed by
Sebastian Wilhelmi
parent
dd58473e07
commit
fe0f325777
77
gthread.h
77
gthread.h
@@ -129,7 +129,7 @@ void g_thread_init (GThreadFunctions *vtable);
|
||||
* mutexes will check for re-locking and re-unlocking */
|
||||
|
||||
/* Initialize thread system with errorcheck mutexes. vtable must be
|
||||
* NULL.Do not call directly. Use #define G_ERRORCHECK_MUTEXES
|
||||
* NULL. Do not call directly. Use #define G_ERRORCHECK_MUTEXES
|
||||
* instead.
|
||||
*/
|
||||
void g_thread_init_with_errorcheck_mutexes (GThreadFunctions* vtable);
|
||||
@@ -145,51 +145,56 @@ void g_thread_init_with_errorcheck_mutexes (GThreadFunctions* vtable);
|
||||
GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
|
||||
|
||||
/* shorthands for conditional and unconditional function calls */
|
||||
#define G_THREAD_UF(op, arglist) \
|
||||
|
||||
#define G_THREAD_UF(op, arglist) \
|
||||
(*g_thread_functions_for_glib_use . op) arglist
|
||||
#define G_THREAD_CF(op, fail, arg) \
|
||||
#define G_THREAD_CF(op, fail, arg) \
|
||||
(g_thread_supported () ? G_THREAD_UF (op, arg) : (fail))
|
||||
#define G_THREAD_ECF(op, fail, mutex, name, type) \
|
||||
(g_thread_supported () ? \
|
||||
((type(*)(GMutex*, gulong, gchar*, gchar*)) \
|
||||
(*g_thread_functions_for_glib_use . op)) \
|
||||
(mutex, G_MUTEX_DEBUG_MAGIC, G_STRINGIFY (name), G_STRLOC) : (fail))
|
||||
#define G_THREAD_ECF(op, fail, mutex, type) \
|
||||
(g_thread_supported () ? ((type(*)(GMutex*, gulong, gchar*)) \
|
||||
(*g_thread_functions_for_glib_use . op)) \
|
||||
(mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (fail))
|
||||
|
||||
#ifndef G_ERRORCHECK_MUTEXES
|
||||
#define g_mutex_lock_with_debug_name(mutex, name) \
|
||||
G_THREAD_CF (mutex_lock, (void)0, (mutex))
|
||||
#define g_mutex_trylock_with_debug_name(mutex, name) \
|
||||
G_THREAD_CF (mutex_trylock, TRUE, (mutex))
|
||||
#define g_mutex_unlock_with_debug_name(mutex, name) \
|
||||
G_THREAD_CF (mutex_unlock, (void)0, (mutex))
|
||||
# define g_mutex_lock(mutex) \
|
||||
G_THREAD_CF (mutex_lock, (void)0, (mutex))
|
||||
# define g_mutex_trylock(mutex) \
|
||||
G_THREAD_CF (mutex_trylock, TRUE, (mutex))
|
||||
# define g_mutex_unlock(mutex) \
|
||||
G_THREAD_CF (mutex_unlock, (void)0, (mutex))
|
||||
# define g_cond_wait(cond, mutex) \
|
||||
G_THREAD_CF (cond_wait, (void)0, (cond, mutex))
|
||||
# define g_cond_timed_wait(cond, mutex, abs_time) \
|
||||
G_THREAD_CF (cond_timed_wait, TRUE, (cond, mutex, abs_time))
|
||||
#else /* G_ERRORCHECK_MUTEXES */
|
||||
#define g_mutex_lock_with_debug_name(mutex, name) \
|
||||
G_THREAD_ECF (mutex_lock, (void)0, mutex, name, void)
|
||||
#define g_mutex_trylock_with_debug_name(mutex, name) \
|
||||
G_THREAD_ECF (mutex_trylock, TRUE, mutex, name, gboolean)
|
||||
#define g_mutex_unlock_with_debug_name(mutex, name) \
|
||||
G_THREAD_ECF (mutex_unlock, (void)0, mutex, name, void)
|
||||
# define g_mutex_lock(mutex) \
|
||||
G_THREAD_ECF (mutex_lock, (void)0, mutex, void)
|
||||
# define g_mutex_trylock(mutex) \
|
||||
G_THREAD_ECF (mutex_trylock, TRUE, mutex, gboolean)
|
||||
# define g_mutex_unlock(mutex) \
|
||||
G_THREAD_ECF (mutex_unlock, (void)0, mutex, void)
|
||||
# define g_cond_wait(cond, mutex) \
|
||||
(g_thread_supported () ? ((void(*)(GCond*, GMutex*, gulong, gchar*))\
|
||||
g_thread_functions_for_glib_use.cond_wait) \
|
||||
(cond, mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (void) 0)
|
||||
# define g_cond_timed_wait(cond, mutex, abs_time) \
|
||||
(g_thread_supported () ? \
|
||||
((gboolean(*)(GCond*, GMutex*, GTimeVal*, gulong, gchar*)) \
|
||||
g_thread_functions_for_glib_use.cond_timed_wait) \
|
||||
(cond, mutex, abs_time, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : TRUE)
|
||||
#endif /* G_ERRORCHECK_MUTEXES */
|
||||
|
||||
#define g_thread_supported() (g_threads_got_initialized)
|
||||
#define g_mutex_new() G_THREAD_UF (mutex_new, ())
|
||||
#define g_mutex_lock(mutex) g_mutex_lock_with_debug_name(mutex, mutex)
|
||||
#define g_mutex_trylock(mutex) g_mutex_trylock_with_debug_name(mutex, mutex)
|
||||
#define g_mutex_unlock(mutex) g_mutex_unlock_with_debug_name(mutex, mutex)
|
||||
#define g_mutex_free(mutex) G_THREAD_CF (mutex_free, (void)0, (mutex))
|
||||
#define g_cond_new() G_THREAD_UF (cond_new, ())
|
||||
#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
|
||||
#define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
|
||||
#define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait, (void)0, (cond, \
|
||||
mutex))
|
||||
#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
|
||||
#define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
|
||||
TRUE, \
|
||||
(cond, mutex, \
|
||||
abs_time))
|
||||
#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
|
||||
#define g_private_get(private_key) G_THREAD_CF (private_get, \
|
||||
((gpointer)private_key), \
|
||||
(private_key))
|
||||
#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
|
||||
#define g_private_get(private_key) G_THREAD_CF (private_get, \
|
||||
((gpointer)private_key), \
|
||||
(private_key))
|
||||
#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
|
||||
(void) (private_key = \
|
||||
(GPrivate*) (value)), \
|
||||
@@ -215,11 +220,11 @@ void g_thread_set_priority (GThread *thread,
|
||||
* use
|
||||
*/
|
||||
#define g_static_mutex_lock(mutex) \
|
||||
g_mutex_lock_with_debug_name (g_static_mutex_get_mutex (mutex), mutex)
|
||||
g_mutex_lock (g_static_mutex_get_mutex (mutex))
|
||||
#define g_static_mutex_trylock(mutex) \
|
||||
g_mutex_trylock_with_debug_name (g_static_mutex_get_mutex (mutex), mutex)
|
||||
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
|
||||
#define g_static_mutex_unlock(mutex) \
|
||||
g_mutex_unlock_with_debug_name (g_static_mutex_get_mutex (mutex), mutex)
|
||||
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
|
||||
|
||||
struct _GStaticPrivate
|
||||
{
|
||||
|
Reference in New Issue
Block a user