locks: drop _INIT macros

All locks are now zero-initialised, so we can drop the G_*_INIT macros
for them.

Adjust various users around GLib accordingly and change the docs.

https://bugzilla.gnome.org/show_bug.cgi?id=659866
This commit is contained in:
Ryan Lortie 2011-10-02 20:51:38 -04:00
parent 3315aee709
commit 2a677d1370
22 changed files with 44 additions and 128 deletions

View File

@ -605,7 +605,6 @@ g_thread_foreach
<SUBSECTION>
GMutex
G_MUTEX_INIT
g_mutex_init
g_mutex_clear
g_mutex_new
@ -616,7 +615,6 @@ g_mutex_unlock
<SUBSECTION>
GRecMutex
G_REC_MUTEX_INIT
g_rec_mutex_init
g_rec_mutex_clear
g_rec_mutex_lock
@ -625,7 +623,6 @@ g_rec_mutex_unlock
<SUBSECTION>
GRWLock
G_RW_LOCK_INIT
g_rw_lock_init
g_rw_lock_clear
g_rw_lock_writer_lock
@ -678,7 +675,6 @@ g_static_rw_lock_free
<SUBSECTION>
GCond
G_COND_INIT
g_cond_new
g_cond_free
g_cond_init

View File

@ -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;

View File

@ -126,7 +126,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 */

View File

@ -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

View File

@ -7,7 +7,7 @@
#else
/* could be vastly improved... */
#define GLIB_CTOR(func) \
static GMutex g__##func##_mutex = G_MUTEX_INIT; \
static GMutex g__##func##_mutex; \
static gboolean g__##func##_initialised; \
static void func (void)
#define GLIB_ENSURE_CTOR(func) \

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -139,8 +139,7 @@ g_mutex_get_impl (GMutex *mutex)
* This function is useful to initialize a mutex that has been
* allocated on the stack, or as part of a larger structure.
* It is not necessary to initialize a mutex that has been
* created with g_mutex_new(). Also see #G_MUTEX_INIT for an
* alternative way to initialize statically allocated mutexes.
* created with g_mutex_new() or that has been statically allocated.
*
* |[
* typedef struct {
@ -317,9 +316,8 @@ g_rec_mutex_get_impl (GRecMutex *rec_mutex)
* that has been allocated on the stack, or as part of a larger
* structure.
* It is not necessary to initialize a recursive mutex that has
* been created with g_rec_mutex_new(). Also see #G_REC_MUTEX_INIT
* for an alternative way to initialize statically allocated
* recursive mutexes.
* been created with g_rec_mutex_new(). It is not necessary to
* initialise a recursive mutex that has been statically allocated.
*
* |[
* typedef struct {
@ -475,9 +473,9 @@ g_rw_lock_get_impl (GRWLock *lock)
* Initializes a #GRWLock so that it can be used.
*
* This function is useful to initialize a lock that has been
* allocated on the stack, or as part of a larger structure.
* Also see #G_RW_LOCK_INIT for an alternative way to initialize
* statically allocated locks.
* allocated on the stack, or as part of a larger structure. It is not
* necessary to initialise a reader-writer lock that has been statically
* allocated.
*
* |[
* typedef struct {
@ -683,8 +681,7 @@ g_cond_get_impl (GCond *cond)
* This function is useful to initialize a #GCond that has been
* allocated on the stack, or as part of a larger structure.
* It is not necessary to initialize a #GCond that has been
* created with g_cond_new(). Also see #G_COND_INIT for an
* alternative way to initialize statically allocated #GConds.
* created with g_cond_new() or that has been statically allocated.
*
* To undo the effect of g_cond_init() when a #GCond is no longer
* needed, use g_cond_clear().

View File

@ -71,13 +71,8 @@ g_thread_abort (gint status,
* that only get the kernel involved in cases of contention (similar
* to how futex()-based mutexes work on Linux). The biggest advantage
* of these new types is that they can be statically initialised to
* zero. This allows us to use them directly and still support:
*
* GMutex mutex = G_MUTEX_INIT;
*
* and
*
* GCond cond = G_COND_INIT;
* zero. That means that they are completely ABI compatible with our
* GMutex and GCond APIs.
*
* Unfortunately, Windows XP lacks these facilities and GLib still
* needs to support Windows XP. Our approach here is as follows:

View File

@ -298,7 +298,7 @@
* int
* give_me_next_number (void)
* {
* static GMutex mutex = G_MUTEX_INIT;
* static GMutex mutex;
* static int current_number = 0;
* int ret_val;
*
@ -315,19 +315,6 @@
* functions.
*/
/**
* G_MUTEX_INIT:
*
* Initializer for statically allocated #GMutexes.
* Alternatively, g_mutex_init() can be used.
*
* |[
* GMutex mutex = G_MUTEX_INIT;
* ]|
*
* Since: 2.32
*/
/* GRecMutex Documentation {{{1 -------------------------------------- */
/**
@ -340,22 +327,7 @@
* unlock the recursive mutex as often as it has been locked.
*
* A GRecMutex should only be accessed with the
* <function>g_rec_mutex_</function> functions. Before a GRecMutex
* can be used, it has to be initialized with #G_REC_MUTEX_INIT or
* g_rec_mutex_init().
*
* Since: 2.32
*/
/**
* G_REC_MUTEX_INIT:
*
* Initializer for statically allocated #GRecMutexes.
* Alternatively, g_rec_mutex_init() can be used.
*
* |[
* GRecMutex mutex = G_REC_MUTEX_INIT;
* ]|
* <function>g_rec_mutex_</function> functions.
*
* Since: 2.32
*/
@ -379,7 +351,7 @@
* <example>
* <title>An array with access functions</title>
* <programlisting>
* GRWLock lock = G_RW_LOCK_INIT;
* GRWLock lock;
* GPtrArray *array;
*
* gpointer
@ -425,21 +397,7 @@
* </example>
*
* A GRWLock should only be accessed with the
* <function>g_rw_lock_</function> functions. Before it can be used,
* it has to be initialized with #G_RW_LOCK_INIT or g_rw_lock_init().
*
* Since: 2.32
*/
/**
* G_RW_LOCK_INIT:
*
* Initializer for statically allocated #GRWLocks.
* Alternatively, g_rw_lock_init_init() can be used.
*
* |[
* GRWLock lock = G_RW_LOCK_INIT;
* ]|
* <function>g_rw_lock_</function> functions.
*
* Since: 2.32
*/
@ -507,19 +465,6 @@
* functions.
*/
/**
* G_COND_INIT:
*
* Initializer for statically allocated #GConds.
* Alternatively, g_cond_init() can be used.
*
* |[
* GCond cond = G_COND_INIT;
* ]|
*
* Since: 2.32
*/
/* GThread Documentation {{{1 ---------------------------------------- */
/**
@ -578,8 +523,8 @@ g_thread_error_quark (void)
gboolean g_threads_got_initialized = FALSE;
GSystemThread zero_thread; /* This is initialized to all zero */
GMutex g_once_mutex = G_MUTEX_INIT;
static GCond g_once_cond = G_COND_INIT;
GMutex g_once_mutex;
static GCond g_once_cond;
static GSList *g_once_init_list = NULL;
static void g_thread_cleanup (gpointer data);

View File

@ -59,25 +59,21 @@ typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
#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
{
gpointer impl;
};
#define G_REC_MUTEX_INIT { NULL }
struct _GRecMutex
{
gpointer impl;
@ -168,8 +164,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
#define G_LOCK_DEFINE(name) GMutex G_LOCK_NAME (name)
#define G_LOCK_EXTERN(name) extern GMutex G_LOCK_NAME (name)
#ifdef G_DEBUG_LOCKS

View File

@ -709,7 +709,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 >

View File

@ -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

View File

@ -40,13 +40,12 @@ test_mutex1 (void)
static void
test_mutex2 (void)
{
GMutex mutex = G_MUTEX_INIT;
static GMutex mutex;
g_mutex_lock (&mutex);
g_mutex_unlock (&mutex);
g_mutex_lock (&mutex);
g_mutex_unlock (&mutex);
g_mutex_clear (&mutex);
}
static void
@ -65,7 +64,7 @@ test_mutex3 (void)
static void
test_mutex4 (void)
{
GMutex mutex = G_MUTEX_INIT;
static GMutex mutex;
gboolean ret;
ret = g_mutex_trylock (&mutex);
@ -76,7 +75,6 @@ test_mutex4 (void)
g_mutex_unlock (&mutex);
g_mutex_unlock (&mutex);
g_mutex_clear (&mutex);
}
#define LOCKS 48
@ -159,7 +157,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) */

View File

@ -253,9 +253,9 @@ test_static_private4 (void)
}
static GStaticPrivate sp5 = G_STATIC_PRIVATE_INIT;
static GMutex m5 = G_MUTEX_INIT;
static GCond c5a = G_COND_INIT;
static GCond c5b = G_COND_INIT;
static GMutex m5;
static GCond c5a;
static GCond c5b;
static gint count5;
static gpointer

View File

@ -38,19 +38,18 @@ test_rec_mutex1 (void)
static void
test_rec_mutex2 (void)
{
GRecMutex mutex = G_REC_MUTEX_INIT;
static GRecMutex mutex;
g_rec_mutex_lock (&mutex);
g_rec_mutex_unlock (&mutex);
g_rec_mutex_lock (&mutex);
g_rec_mutex_unlock (&mutex);
g_rec_mutex_clear (&mutex);
}
static void
test_rec_mutex3 (void)
{
GRecMutex mutex = G_REC_MUTEX_INIT;
static GRecMutex mutex;
gboolean ret;
ret = g_rec_mutex_trylock (&mutex);
@ -61,7 +60,6 @@ test_rec_mutex3 (void)
g_rec_mutex_unlock (&mutex);
g_rec_mutex_unlock (&mutex);
g_rec_mutex_clear (&mutex);
}
#define LOCKS 48

View File

@ -38,19 +38,18 @@ test_rwlock1 (void)
static void
test_rwlock2 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
static GRWLock lock;
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock3 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
static GRWLock lock;
gboolean ret;
ret = g_rw_lock_writer_trylock (&lock);
@ -59,26 +58,23 @@ test_rwlock3 (void)
g_assert (!ret);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock4 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
static GRWLock lock;
g_rw_lock_reader_lock (&lock);
g_rw_lock_reader_unlock (&lock);
g_rw_lock_reader_lock (&lock);
g_rw_lock_reader_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock5 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
static GRWLock lock;
gboolean ret;
ret = g_rw_lock_reader_trylock (&lock);
@ -88,14 +84,12 @@ test_rwlock5 (void)
g_rw_lock_reader_unlock (&lock);
g_rw_lock_reader_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock6 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
static GRWLock lock;
gboolean ret;
g_rw_lock_writer_lock (&lock);
@ -107,8 +101,6 @@ test_rwlock6 (void)
ret = g_rw_lock_writer_trylock (&lock);
g_assert (!ret);
g_rw_lock_reader_unlock (&lock);
g_rw_lock_clear (&lock);
}

View File

@ -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,

View File

@ -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));

View File

@ -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;

View File

@ -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;