[glib/wip/linux: 4/6] GMutex: change implementation to clean up header
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/linux: 4/6] GMutex: change implementation to clean up header
- Date: Sun, 2 Oct 2011 16:58:30 +0000 (UTC)
commit d381cd250854e89539737029db16447c2dca8689
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Sep 30 15:23:09 2011 -0400
GMutex: change implementation to clean up header
Don't #include <pthread.h> or try to use any of the types declared
therein from public glib headers (avoiding the problems that goes along
with that).
Use the exact same definition for all types on all platforms.
This means that the implementation has to be pretty much completely
changed. We use the existing GRecMutex code as a model and apply the
same concept to GMutex, GCond and GRWLock.
We can drop the _INIT macros now -- everything is zero-initialised.
This represents a (rather small) performance regression on POSIX. We'll
fix that up by adding an optimised case for Linux and another case for
systems where our new ABI happens to be compatible with the pthread ABI
on that system (OpenBSD and FreeBSD are notable examples of this).
https://bugzilla.gnome.org/show_bug.cgi?id=659866
gio/gunionvolumemonitor.c | 2 +-
glib/deprecated/gthread.h | 2 +-
glib/gbitlock.c | 2 +-
glib/gmem.c | 2 +-
glib/gmessages.c | 2 +-
glib/gmutex-posix.c | 216 ++++++++++++++++++++++++++++++++++-----------
glib/gmutex.h | 76 +++++-----------
glib/gslice.c | 2 +-
glib/gthread-win32.c | 16 ++--
glib/gthread.c | 4 +-
glib/gthread.h | 2 +-
glib/gvarianttypeinfo.c | 2 +-
glib/tests/cond.c | 4 +-
glib/tests/mutex.c | 6 +-
glib/tests/rec-mutex.c | 4 +-
glib/tests/rwlock.c | 10 +-
gmodule/gmodule.c | 2 +-
gobject/gparam.c | 2 +-
gobject/gtype.c | 4 +-
tests/thread-test.c | 2 +-
20 files changed, 221 insertions(+), 141 deletions(-)
---
diff --git a/gio/gunionvolumemonitor.c b/gio/gunionvolumemonitor.c
index 6d9b21b..cd814ad 100644
--- a/gio/gunionvolumemonitor.c
+++ b/gio/gunionvolumemonitor.c
@@ -52,7 +52,7 @@ static void g_union_volume_monitor_remove_monitor (GUnionVolumeMonitor *union_mo
#define g_union_volume_monitor_get_type _g_union_volume_monitor_get_type
G_DEFINE_TYPE (GUnionVolumeMonitor, g_union_volume_monitor, G_TYPE_VOLUME_MONITOR);
-static GRecMutex the_volume_monitor_mutex = G_REC_MUTEX_INIT;
+static GRecMutex the_volume_monitor_mutex;
static GUnionVolumeMonitor *the_volume_monitor = NULL;
diff --git a/glib/deprecated/gthread.h b/glib/deprecated/gthread.h
index 668064a..0353481 100644
--- a/glib/deprecated/gthread.h
+++ b/glib/deprecated/gthread.h
@@ -119,7 +119,7 @@ typedef struct {
struct _GMutex *unused;
GMutex mutex;
} GStaticMutex;
-#define G_STATIC_MUTEX_INIT { NULL, G_MUTEX_INIT }
+#define G_STATIC_MUTEX_INIT { NULL, { NULL } }
#define g_static_mutex_get_mutex(s) (&(s)->mutex)
#endif /* G_OS_WIN32 */
diff --git a/glib/gbitlock.c b/glib/gbitlock.c
index 1d241fb..1b2d172 100644
--- a/glib/gbitlock.c
+++ b/glib/gbitlock.c
@@ -36,7 +36,7 @@
#endif
#ifndef HAVE_FUTEX
-static GMutex g_futex_mutex = G_MUTEX_INIT;
+static GMutex g_futex_mutex;
static GSList *g_futex_address_list = NULL;
#endif
diff --git a/glib/gmem.c b/glib/gmem.c
index 0e1b5cf..f19dbc5 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -623,7 +623,7 @@ static guint *profile_data = NULL;
static gsize profile_allocs = 0;
static gsize profile_zinit = 0;
static gsize profile_frees = 0;
-static GMutex gmem_profile_mutex = G_MUTEX_INIT;
+static GMutex gmem_profile_mutex;
#ifdef G_ENABLE_DEBUG
static volatile gsize g_trap_free_size = 0;
static volatile gsize g_trap_realloc_size = 0;
diff --git a/glib/gmessages.c b/glib/gmessages.c
index acd55c7..c583188 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -101,7 +101,7 @@ struct _GLogHandler
/* --- variables --- */
-static GMutex g_messages_lock = G_MUTEX_INIT;
+static GMutex g_messages_lock;
static GLogDomain *g_log_domains = NULL;
static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
static GPrintFunc glib_print_func = NULL;
diff --git a/glib/gmutex-posix.c b/glib/gmutex-posix.c
index 1ced38f..341753f 100644
--- a/glib/gmutex-posix.c
+++ b/glib/gmutex-posix.c
@@ -50,6 +50,57 @@ g_mutex_abort (gint status,
/* {{{1 GMutex */
+static pthread_mutex_t *
+g_mutex_impl_new (void)
+{
+ pthread_mutexattr_t *pattr = NULL;
+ pthread_mutex_t *mutex;
+ gint status;
+
+ mutex = malloc (sizeof (pthread_mutex_t));
+ if G_UNLIKELY (mutex == NULL)
+ g_mutex_abort (errno, "malloc");
+
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
+ pattr = &attr;
+#endif
+
+ if G_UNLIKELY ((status = pthread_mutex_init (mutex, pattr)) != 0)
+ g_mutex_abort (status, "pthread_mutex_init");
+
+#ifdef PTHREAD_ADAPTIVE_MUTEX_NP
+ pthread_mutexattr_destroy (&attr);
+#endif
+
+ return mutex;
+}
+
+static void
+g_mutex_impl_free (pthread_mutex_t *mutex)
+{
+ pthread_mutex_destroy (mutex);
+ free (mutex);
+}
+
+static pthread_mutex_t *
+g_mutex_get_impl (GMutex *mutex)
+{
+ pthread_mutex_t *impl = mutex->p;
+
+ if G_UNLIKELY (impl == NULL)
+ {
+ impl = g_mutex_impl_new ();
+ if (!g_atomic_pointer_compare_and_exchange (&mutex->p, NULL, impl))
+ g_mutex_impl_free (impl);
+ impl = mutex->p;
+ }
+
+ return impl;
+}
+
/**
* g_mutex_init:
* @mutex: an uninitialized #GMutex
@@ -85,21 +136,7 @@ g_mutex_abort (gint status,
void
g_mutex_init (GMutex *mutex)
{
- gint status;
- pthread_mutexattr_t *pattr = NULL;
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
- pthread_mutexattr_t attr;
- pthread_mutexattr_init (&attr);
- pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
- pattr = &attr;
-#endif
-
- if G_UNLIKELY ((status = pthread_mutex_init (&mutex->impl, pattr)) != 0)
- g_mutex_abort (status, "pthread_mutex_init");
-
-#ifdef PTHREAD_ADAPTIVE_MUTEX_NP
- pthread_mutexattr_destroy (&attr);
-#endif
+ mutex->p = g_mutex_impl_new ();
}
/**
@@ -119,10 +156,7 @@ g_mutex_init (GMutex *mutex)
void
g_mutex_clear (GMutex *mutex)
{
- gint status;
-
- if G_UNLIKELY ((status = pthread_mutex_destroy (&mutex->impl)) != 0)
- g_mutex_abort (status, "pthread_mutex_destroy");
+ g_mutex_impl_free (mutex->p);
}
/**
@@ -146,7 +180,7 @@ g_mutex_lock (GMutex *mutex)
{
gint status;
- if G_UNLIKELY ((status = pthread_mutex_lock (&mutex->impl)) != 0)
+ if G_UNLIKELY ((status = pthread_mutex_lock (g_mutex_get_impl (mutex))) != 0)
g_mutex_abort (status, "pthread_mutex_lock");
}
@@ -168,8 +202,8 @@ g_mutex_unlock (GMutex *mutex)
{
gint status;
- if G_UNLIKELY ((status = pthread_mutex_unlock (&mutex->impl)) != 0)
- g_mutex_abort (status, "pthread_mutex_lock");
+ if G_UNLIKELY ((status = pthread_mutex_unlock (mutex->p)) != 0)
+ g_mutex_abort (status, "pthread_mutex_unlock");
}
/**
@@ -195,7 +229,7 @@ g_mutex_trylock (GMutex *mutex)
{
gint status;
- if G_LIKELY ((status = pthread_mutex_trylock (&mutex->impl)) == 0)
+ if G_LIKELY ((status = pthread_mutex_trylock (g_mutex_get_impl (mutex))) == 0)
return TRUE;
if G_UNLIKELY (status != EBUSY)
@@ -211,13 +245,15 @@ g_rec_mutex_impl_new (void)
{
pthread_mutexattr_t attr;
pthread_mutex_t *mutex;
+ gint status;
mutex = malloc (sizeof (pthread_mutex_t));
if G_UNLIKELY (mutex == NULL)
g_mutex_abort (errno, "malloc");
pthread_mutexattr_init (&attr);
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init (mutex, &attr);
+ if G_UNLIKELY ((status = pthread_mutex_init (mutex, &attr)) != 0)
+ g_mutex_abort (status, "pthread_mutex_init");
pthread_mutexattr_destroy (&attr);
return mutex;
@@ -233,14 +269,14 @@ g_rec_mutex_impl_free (pthread_mutex_t *mutex)
static pthread_mutex_t *
g_rec_mutex_get_impl (GRecMutex *mutex)
{
- pthread_mutex_t *impl = mutex->impl;
+ pthread_mutex_t *impl = mutex->p;
- if G_UNLIKELY (mutex->impl == NULL)
+ if G_UNLIKELY (impl == NULL)
{
impl = g_rec_mutex_impl_new ();
- if (!g_atomic_pointer_compare_and_exchange (&mutex->impl, NULL, impl))
+ if (!g_atomic_pointer_compare_and_exchange (&mutex->p, NULL, impl))
g_rec_mutex_impl_free (impl);
- impl = mutex->impl;
+ impl = mutex->p;
}
return impl;
@@ -283,7 +319,7 @@ g_rec_mutex_get_impl (GRecMutex *mutex)
void
g_rec_mutex_init (GRecMutex *rec_mutex)
{
- rec_mutex->impl = g_rec_mutex_impl_new ();
+ rec_mutex->p = g_rec_mutex_impl_new ();
}
/**
@@ -304,8 +340,8 @@ g_rec_mutex_init (GRecMutex *rec_mutex)
void
g_rec_mutex_clear (GRecMutex *rec_mutex)
{
- if (rec_mutex->impl)
- g_rec_mutex_impl_free (rec_mutex->impl);
+ if (rec_mutex->p)
+ g_rec_mutex_impl_free (rec_mutex->p);
}
/**
@@ -343,7 +379,7 @@ g_rec_mutex_lock (GRecMutex *mutex)
void
g_rec_mutex_unlock (GRecMutex *rec_mutex)
{
- pthread_mutex_unlock (rec_mutex->impl);
+ pthread_mutex_unlock (rec_mutex->p);
}
/**
@@ -369,6 +405,46 @@ g_rec_mutex_trylock (GRecMutex *rec_mutex)
/* {{{1 GRWLock */
+static pthread_rwlock_t *
+g_rw_lock_impl_new (void)
+{
+ pthread_rwlock_t *rwlock;
+ gint status;
+
+ rwlock = malloc (sizeof (pthread_rwlock_t));
+ if G_UNLIKELY (rwlock == NULL)
+ g_mutex_abort (errno, "malloc");
+
+ if G_UNLIKELY ((status = pthread_rwlock_init (rwlock, NULL)) != 0)
+ g_mutex_abort (status, "pthread_rwlock_init");
+
+ return rwlock;
+}
+
+static void
+g_rw_lock_impl_free (pthread_rwlock_t *rwlock)
+{
+ pthread_rwlock_destroy (rwlock);
+ free (rwlock);
+}
+
+static pthread_rwlock_t *
+g_rw_lock_get_impl (GRWLock *lock)
+{
+ pthread_rwlock_t *impl = lock->p;
+
+ if G_UNLIKELY (impl == NULL)
+ {
+ impl = g_rw_lock_impl_new ();
+ if (!g_atomic_pointer_compare_and_exchange (&lock->p, NULL, impl))
+ g_rw_lock_impl_free (impl);
+ impl = lock->p;
+ }
+
+ return impl;
+}
+
+
/**
* g_rw_lock_init:
* @lock: an uninitialized #GRWLock
@@ -403,7 +479,7 @@ g_rec_mutex_trylock (GRecMutex *rec_mutex)
void
g_rw_lock_init (GRWLock *lock)
{
- pthread_rwlock_init (&lock->impl, NULL);
+ lock->p = g_rw_lock_impl_new ();
}
/**
@@ -420,7 +496,7 @@ g_rw_lock_init (GRWLock *lock)
void
g_rw_lock_clear (GRWLock *lock)
{
- pthread_rwlock_destroy (&lock->impl);
+ g_rw_lock_impl_free (lock->p);
}
/**
@@ -436,7 +512,7 @@ g_rw_lock_clear (GRWLock *lock)
void
g_rw_lock_writer_lock (GRWLock *lock)
{
- pthread_rwlock_wrlock (&lock->impl);
+ pthread_rwlock_wrlock (g_rw_lock_get_impl (lock));
}
/**
@@ -454,7 +530,7 @@ g_rw_lock_writer_lock (GRWLock *lock)
gboolean
g_rw_lock_writer_trylock (GRWLock *lock)
{
- if (pthread_rwlock_trywrlock (&lock->impl) != 0)
+ if (pthread_rwlock_trywrlock (g_rw_lock_get_impl (lock)) != 0)
return FALSE;
return TRUE;
@@ -474,7 +550,7 @@ g_rw_lock_writer_trylock (GRWLock *lock)
void
g_rw_lock_writer_unlock (GRWLock *lock)
{
- pthread_rwlock_unlock (&lock->impl);
+ pthread_rwlock_unlock (lock->p);
}
/**
@@ -493,7 +569,7 @@ g_rw_lock_writer_unlock (GRWLock *lock)
void
g_rw_lock_reader_lock (GRWLock *lock)
{
- pthread_rwlock_rdlock (&lock->impl);
+ pthread_rwlock_rdlock (g_rw_lock_get_impl (lock));
}
/**
@@ -511,7 +587,7 @@ g_rw_lock_reader_lock (GRWLock *lock)
gboolean
g_rw_lock_reader_trylock (GRWLock *lock)
{
- if (pthread_rwlock_tryrdlock (&lock->impl) != 0)
+ if (pthread_rwlock_tryrdlock (g_rw_lock_get_impl (lock)) != 0)
return FALSE;
return TRUE;
@@ -531,11 +607,50 @@ g_rw_lock_reader_trylock (GRWLock *lock)
void
g_rw_lock_reader_unlock (GRWLock *lock)
{
- pthread_rwlock_unlock (&lock->impl);
+ pthread_rwlock_unlock (lock->p);
}
/* {{{1 GCond */
+static pthread_cond_t *
+g_cond_impl_new (void)
+{
+ pthread_cond_t *cond;
+ gint status;
+
+ cond = malloc (sizeof (pthread_cond_t));
+ if G_UNLIKELY (cond == NULL)
+ g_mutex_abort (errno, "malloc");
+
+ if G_UNLIKELY ((status = pthread_cond_init (cond, NULL)) != 0)
+ g_mutex_abort (status, "pthread_cond_init");
+
+ return cond;
+}
+
+static void
+g_cond_impl_free (pthread_cond_t *cond)
+{
+ pthread_cond_destroy (cond);
+ free (cond);
+}
+
+static pthread_cond_t *
+g_cond_get_impl (GCond *cond)
+{
+ pthread_cond_t *impl = cond->p;
+
+ if G_UNLIKELY (impl == NULL)
+ {
+ impl = g_cond_impl_new ();
+ if (!g_atomic_pointer_compare_and_exchange (&cond->p, NULL, impl))
+ g_cond_impl_free (impl);
+ impl = cond->p;
+ }
+
+ return impl;
+}
+
/**
* g_cond_init:
* @cond: an uninitialized #GCond
@@ -559,10 +674,7 @@ g_rw_lock_reader_unlock (GRWLock *lock)
void
g_cond_init (GCond *cond)
{
- gint status;
-
- if G_UNLIKELY ((status = pthread_cond_init (&cond->impl, NULL)) != 0)
- g_mutex_abort (status, "pthread_cond_init");
+ cond->p = g_cond_impl_new ();
}
/**
@@ -582,10 +694,7 @@ g_cond_init (GCond *cond)
void
g_cond_clear (GCond *cond)
{
- gint status;
-
- if G_UNLIKELY ((status = pthread_cond_destroy (&cond->impl)) != 0)
- g_mutex_abort (status, "pthread_cond_destroy");
+ g_cond_impl_free (cond->p);
}
/**
@@ -605,7 +714,8 @@ g_cond_wait (GCond *cond,
{
gint status;
- if G_UNLIKELY ((status = pthread_cond_wait (&cond->impl, &mutex->impl)) != 0)
+ /* the mutex is locked so ->p is set */
+ if G_UNLIKELY ((status = pthread_cond_wait (g_cond_get_impl (cond), mutex->p)) != 0)
g_mutex_abort (status, "pthread_cond_wait");
}
@@ -626,7 +736,7 @@ g_cond_signal (GCond *cond)
{
gint status;
- if G_UNLIKELY ((status = pthread_cond_signal (&cond->impl)) != 0)
+ if G_UNLIKELY ((status = pthread_cond_signal (g_cond_get_impl (cond))) != 0)
g_mutex_abort (status, "pthread_cond_signal");
}
@@ -647,7 +757,7 @@ g_cond_broadcast (GCond *cond)
{
gint status;
- if G_UNLIKELY ((status = pthread_cond_broadcast (&cond->impl)) != 0)
+ if G_UNLIKELY ((status = pthread_cond_broadcast (g_cond_get_impl (cond))) != 0)
g_mutex_abort (status, "pthread_cond_broadcast");
}
@@ -688,7 +798,7 @@ g_cond_timed_wait (GCond *cond,
end_time.tv_sec = abs_time->tv_sec;
end_time.tv_nsec = abs_time->tv_usec * 1000;
- if ((status = pthread_cond_timedwait (&cond->impl, &mutex->impl, &end_time)) == 0)
+ if ((status = pthread_cond_timedwait (g_cond_get_impl (cond), mutex->p, &end_time)) == 0)
return TRUE;
if G_UNLIKELY (status != ETIMEDOUT)
@@ -722,7 +832,7 @@ g_cond_timedwait (GCond *cond,
end_time.tv_sec = abs_time / 1000000;
end_time.tv_nsec = (abs_time % 1000000) * 1000;
- if ((status = pthread_cond_timedwait (&cond->impl, &mutex->impl, &end_time)) == 0)
+ if ((status = pthread_cond_timedwait (g_cond_get_impl (cond), mutex->p, &end_time)) == 0)
return TRUE;
if G_UNLIKELY (status != ETIMEDOUT)
diff --git a/glib/gmutex.h b/glib/gmutex.h
index 6d8232a..688eccd 100644
--- a/glib/gmutex.h
+++ b/glib/gmutex.h
@@ -30,71 +30,41 @@
G_BEGIN_DECLS
-typedef struct _GMutex GMutex;
-typedef struct _GRecMutex GRecMutex;
-typedef struct _GRWLock GRWLock;
-typedef struct _GCond GCond;
-typedef struct _GPrivate GPrivate;
-
-#ifdef G_OS_WIN32
-
-#define G_MUTEX_INIT { NULL }
-struct _GMutex
-{
- gpointer impl;
-};
-
-#define G_RW_LOCK_INIT { NULL }
-struct _GRWLock
-{
- gpointer impl;
-};
-
-#define G_COND_INIT { NULL }
-struct _GCond
+typedef union
{
- gpointer impl;
-};
-#else
+ /*< private >*/
+ gpointer p;
+ guint i[2];
+} GMutex;
-#include <pthread.h>
-
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
-#define G_MUTEX_INIT { PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP }
-#else
-#define G_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER }
-#endif
-struct _GMutex
-{
- pthread_mutex_t impl;
-};
-
-#define G_RW_LOCK_INIT { PTHREAD_RWLOCK_INITIALIZER }
-struct _GRWLock
+typedef union
{
- pthread_rwlock_t impl;
-};
+ /*< private >*/
+ gpointer p;
+ guint i[2];
+} GRWLock;
-#define G_COND_INIT { PTHREAD_COND_INITIALIZER }
-struct _GCond
+typedef union
{
- pthread_cond_t impl;
-};
-
-#endif
+ /*< private >*/
+ gpointer p;
+ guint i[2];
+} GRecMutex;
-#define G_REC_MUTEX_INIT { NULL }
-struct _GRecMutex
+typedef struct
{
- gpointer impl;
-};
+ /*< private >*/
+ gpointer p;
+ guint i[2];
+} GCond;
#define G_PRIVATE_INIT(notify) { NULL, (notify) }
-struct _GPrivate
+typedef struct
{
+ /*< private >*/
gpointer p;
GDestroyNotify notify;
-};
+} GPrivate;
void g_mutex_init (GMutex *mutex);
void g_mutex_clear (GMutex *mutex);
diff --git a/glib/gslice.c b/glib/gslice.c
index 11a297c..4f34fa9 100644
--- a/glib/gslice.c
+++ b/glib/gslice.c
@@ -212,7 +212,7 @@ static SliceConfig slice_config = {
15 * 1000, /* working_set_msecs */
1, /* color increment, alt: 0x7fffffff */
};
-static GMutex smc_tree_mutex = G_MUTEX_INIT; /* mutex for G_SLICE=debug-blocks */
+static GMutex smc_tree_mutex; /* mutex for G_SLICE=debug-blocks */
/* --- auxiliary funcitons --- */
void
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index cf8d587..ceaf0ad 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -178,14 +178,14 @@ g_rec_mutex_impl_free (CRITICAL_SECTION *cs)
static CRITICAL_SECTION *
g_rec_mutex_get_impl (GRecMutex *mutex)
{
- CRITICAL_SECTION *impl = mutex->impl;
+ CRITICAL_SECTION *impl = mutex->p;
- if G_UNLIKELY (mutex->impl == NULL)
+ if G_UNLIKELY (impl == NULL)
{
impl = g_rec_mutex_impl_new ();
- if (InterlockedCompareExchangePointer (&mutex->impl, impl, NULL) != NULL)
+ if (InterlockedCompareExchangePointer (&mutex->p, impl, NULL) != NULL)
g_rec_mutex_impl_free (impl);
- impl = mutex->impl;
+ impl = mutex->p;
}
return impl;
@@ -194,14 +194,14 @@ g_rec_mutex_get_impl (GRecMutex *mutex)
void
g_rec_mutex_init (GRecMutex *mutex)
{
- mutex->impl = g_rec_mutex_impl_new ();
+ mutex->p = g_rec_mutex_impl_new ();
}
void
g_rec_mutex_clear (GRecMutex *mutex)
{
- if (mutex->impl)
- g_rec_mutex_impl_free (mutex->impl);
+ if (mutex->p)
+ g_rec_mutex_impl_free (mutex->p);
}
void
@@ -213,7 +213,7 @@ g_rec_mutex_lock (GRecMutex *mutex)
void
g_rec_mutex_unlock (GRecMutex *mutex)
{
- LeaveCriticalSection (mutex->impl);
+ LeaveCriticalSection (mutex->p);
}
gboolean
diff --git a/glib/gthread.c b/glib/gthread.c
index 6f51627..bd79901 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -655,9 +655,9 @@ struct _GRealThread
gboolean g_threads_got_initialized = FALSE;
GSystemThread zero_thread; /* This is initialized to all zero */
-GMutex g_once_mutex = G_MUTEX_INIT;
+GMutex g_once_mutex;
-static GCond g_once_cond = G_COND_INIT;
+static GCond g_once_cond;
static void g_thread_cleanup (gpointer data);
static GPrivate g_thread_specific_private = G_PRIVATE_INIT (g_thread_cleanup);
static GRealThread *g_thread_all_threads = NULL;
diff --git a/glib/gthread.h b/glib/gthread.h
index 3ef336f..c05b0e0 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -144,7 +144,7 @@ g_once_init_enter (volatile gsize *value_location)
#define G_LOCK_NAME(name) g__ ## name ## _lock
#define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
#define G_LOCK_DEFINE(name) \
- GMutex G_LOCK_NAME (name) = G_MUTEX_INIT
+ GMutex G_LOCK_NAME (name)
#define G_LOCK_EXTERN(name) extern GMutex G_LOCK_NAME (name)
#ifdef G_DEBUG_LOCKS
diff --git a/glib/gvarianttypeinfo.c b/glib/gvarianttypeinfo.c
index 51337cc..ab3c6f8 100644
--- a/glib/gvarianttypeinfo.c
+++ b/glib/gvarianttypeinfo.c
@@ -710,7 +710,7 @@ g_variant_type_info_member_info (GVariantTypeInfo *info,
}
/* == new/ref/unref == */
-static GRecMutex g_variant_type_info_lock = G_REC_MUTEX_INIT;
+static GRecMutex g_variant_type_info_lock;
static GHashTable *g_variant_type_info_table;
/* < private >
diff --git a/glib/tests/cond.c b/glib/tests/cond.c
index 246a341..221ece0 100644
--- a/glib/tests/cond.c
+++ b/glib/tests/cond.c
@@ -22,8 +22,8 @@
#include <glib.h>
-static GCond cond = G_COND_INIT;
-static GMutex mutex = G_MUTEX_INIT;
+static GCond cond;
+static GMutex mutex;
static volatile gint next;
static void
diff --git a/glib/tests/mutex.c b/glib/tests/mutex.c
index 66ec5fb..67ae0c2 100644
--- a/glib/tests/mutex.c
+++ b/glib/tests/mutex.c
@@ -40,7 +40,7 @@ test_mutex1 (void)
static void
test_mutex2 (void)
{
- GMutex mutex = G_MUTEX_INIT;
+ static GMutex mutex = { };
g_mutex_lock (&mutex);
g_mutex_unlock (&mutex);
@@ -65,7 +65,7 @@ test_mutex3 (void)
static void
test_mutex4 (void)
{
- GMutex mutex = G_MUTEX_INIT;
+ static GMutex mutex = { };
gboolean ret;
ret = g_mutex_trylock (&mutex);
@@ -159,7 +159,7 @@ test_mutex5 (void)
static gboolean
do_addition (gint *value)
{
- static GMutex lock = G_MUTEX_INIT;
+ static GMutex lock;
gboolean more;
/* test performance of "good" cases (ie: short critical sections) */
diff --git a/glib/tests/rec-mutex.c b/glib/tests/rec-mutex.c
index 67b6cff..ef3e734 100644
--- a/glib/tests/rec-mutex.c
+++ b/glib/tests/rec-mutex.c
@@ -40,7 +40,7 @@ test_rec_mutex1 (void)
static void
test_rec_mutex2 (void)
{
- GRecMutex mutex = G_REC_MUTEX_INIT;
+ GRecMutex mutex = { };
g_rec_mutex_lock (&mutex);
g_rec_mutex_unlock (&mutex);
@@ -52,7 +52,7 @@ test_rec_mutex2 (void)
static void
test_rec_mutex3 (void)
{
- GRecMutex mutex = G_REC_MUTEX_INIT;
+ GRecMutex mutex = { };
gboolean ret;
ret = g_rec_mutex_trylock (&mutex);
diff --git a/glib/tests/rwlock.c b/glib/tests/rwlock.c
index 63946e4..da59809 100644
--- a/glib/tests/rwlock.c
+++ b/glib/tests/rwlock.c
@@ -38,7 +38,7 @@ test_rwlock1 (void)
static void
test_rwlock2 (void)
{
- GRWLock lock = G_RW_LOCK_INIT;
+ GRWLock lock = { };
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
@@ -50,7 +50,7 @@ test_rwlock2 (void)
static void
test_rwlock3 (void)
{
- GRWLock lock = G_RW_LOCK_INIT;
+ GRWLock lock = { };
gboolean ret;
ret = g_rw_lock_writer_trylock (&lock);
@@ -66,7 +66,7 @@ test_rwlock3 (void)
static void
test_rwlock4 (void)
{
- GRWLock lock = G_RW_LOCK_INIT;
+ GRWLock lock = { };
g_rw_lock_reader_lock (&lock);
g_rw_lock_reader_unlock (&lock);
@@ -78,7 +78,7 @@ test_rwlock4 (void)
static void
test_rwlock5 (void)
{
- GRWLock lock = G_RW_LOCK_INIT;
+ GRWLock lock = { };
gboolean ret;
ret = g_rw_lock_reader_trylock (&lock);
@@ -95,7 +95,7 @@ test_rwlock5 (void)
static void
test_rwlock6 (void)
{
- GRWLock lock = G_RW_LOCK_INIT;
+ GRWLock lock = { };
gboolean ret;
g_rw_lock_writer_lock (&lock);
diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c
index 4d7e811..3a61985 100644
--- a/gmodule/gmodule.c
+++ b/gmodule/gmodule.c
@@ -326,7 +326,7 @@ _g_module_debug_init (void)
module_debug_initialized = TRUE;
}
-static GRecMutex g_module_global_lock = G_REC_MUTEX_INIT;
+static GRecMutex g_module_global_lock;
GModule*
g_module_open (const gchar *file_name,
diff --git a/gobject/gparam.c b/gobject/gparam.c
index ec4cb89..22f72b2 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -891,7 +891,7 @@ param_spec_pool_equals (gconstpointer key_spec_1,
GParamSpecPool*
g_param_spec_pool_new (gboolean type_prefixing)
{
- static GMutex init_mutex = G_MUTEX_INIT;
+ static GMutex init_mutex;
GParamSpecPool *pool = g_new (GParamSpecPool, 1);
memcpy (&pool->mutex, &init_mutex, sizeof (init_mutex));
diff --git a/gobject/gtype.c b/gobject/gtype.c
index da16240..a966200 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -368,8 +368,8 @@ typedef struct {
/* --- variables --- */
-static GRWLock type_rw_lock = G_RW_LOCK_INIT;
-static GRecMutex class_init_rec_mutex = G_REC_MUTEX_INIT;
+static GRWLock type_rw_lock;
+static GRecMutex class_init_rec_mutex;
static guint static_n_class_cache_funcs = 0;
static ClassCacheFunc *static_class_cache_funcs = NULL;
static guint static_n_iface_check_funcs = 0;
diff --git a/tests/thread-test.c b/tests/thread-test.c
index fa4f02b..0f41fc7 100644
--- a/tests/thread-test.c
+++ b/tests/thread-test.c
@@ -110,7 +110,7 @@ test_g_static_rec_mutex (void)
static GStaticPrivate test_g_static_private_private1 = G_STATIC_PRIVATE_INIT;
static GStaticPrivate test_g_static_private_private2 = G_STATIC_PRIVATE_INIT;
-static GMutex test_g_static_private_mutex = G_MUTEX_INIT;
+static GMutex test_g_static_private_mutex;
static guint test_g_static_private_counter = 0;
static guint test_g_static_private_ready = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]