<SUBSECTION>
GMutex
-G_MUTEX_INIT
g_mutex_init
g_mutex_clear
g_mutex_new
<SUBSECTION>
GRecMutex
-G_REC_MUTEX_INIT
g_rec_mutex_init
g_rec_mutex_clear
g_rec_mutex_lock
<SUBSECTION>
GRWLock
-G_RW_LOCK_INIT
g_rw_lock_init
g_rw_lock_clear
g_rw_lock_writer_lock
<SUBSECTION>
GCond
-G_COND_INIT
g_cond_new
g_cond_free
g_cond_init
#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;
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 */
#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
#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) \
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;
/* --- 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;
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
* 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 {
* 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 {
* 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 {
* 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().
* 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:
* int
* give_me_next_number (void)
* {
- * static GMutex mutex = G_MUTEX_INIT;
+ * static GMutex mutex;
* static int current_number = 0;
* int ret_val;
*
* 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 -------------------------------------- */
/**
* 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
*/
* <example>
* <title>An array with access functions</title>
* <programlisting>
- * GRWLock lock = G_RW_LOCK_INIT;
+ * GRWLock lock;
* GPtrArray *array;
*
* gpointer
* </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
*/
* 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 ---------------------------------------- */
/**
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);
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;
#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
}
/* == 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 >
#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
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
static void
test_mutex4 (void)
{
- GMutex mutex = G_MUTEX_INIT;
+ static GMutex mutex;
gboolean ret;
ret = g_mutex_trylock (&mutex);
g_mutex_unlock (&mutex);
g_mutex_unlock (&mutex);
- g_mutex_clear (&mutex);
}
#define LOCKS 48
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) */
}
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
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);
g_rec_mutex_unlock (&mutex);
g_rec_mutex_unlock (&mutex);
- g_rec_mutex_clear (&mutex);
}
#define LOCKS 48
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);
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);
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);
ret = g_rw_lock_writer_trylock (&lock);
g_assert (!ret);
g_rw_lock_reader_unlock (&lock);
-
- g_rw_lock_clear (&lock);
}
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,
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));
/* --- 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;
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;