Use G_MUTEX_INIT or g_mutex_init() as appropriate.
*/
struct _GAsyncQueue
{
- GMutex *mutex;
+ GMutex mutex;
GCond *cond;
GQueue queue;
GDestroyNotify item_free_func;
g_async_queue_new (void)
{
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
- retval->mutex = g_mutex_new ();
+ g_mutex_init (&retval->mutex);
retval->cond = NULL;
g_queue_init (&retval->queue);
retval->waiting_threads = 0;
{
g_return_if_fail (queue);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
g_async_queue_unref (queue);
}
if (g_atomic_int_dec_and_test (&queue->ref_count))
{
g_return_if_fail (queue->waiting_threads == 0);
- g_mutex_free (queue->mutex);
+ g_mutex_clear (&queue->mutex);
if (queue->cond)
g_cond_free (queue->cond);
if (queue->item_free_func)
{
g_return_if_fail (queue);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
}
/**
{
g_return_if_fail (queue);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
}
/**
g_return_if_fail (queue);
g_return_if_fail (data);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
g_async_queue_push_unlocked (queue, data);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
}
/**
{
g_return_if_fail (queue != NULL);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
g_async_queue_push_sorted_unlocked (queue, data, func, user_data);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
}
static gint
{
queue->waiting_threads++;
while (!g_queue_peek_tail_link (&queue->queue))
- g_cond_wait (queue->cond, queue->mutex);
+ g_cond_wait (queue->cond, &queue->mutex);
queue->waiting_threads--;
}
else
{
queue->waiting_threads++;
while (!g_queue_peek_tail_link (&queue->queue))
- if (!g_cond_timed_wait (queue->cond, queue->mutex, end_time))
+ if (!g_cond_timed_wait (queue->cond, &queue->mutex, end_time))
break;
queue->waiting_threads--;
if (!g_queue_peek_tail_link (&queue->queue))
g_return_val_if_fail (queue, NULL);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
return retval;
}
g_return_val_if_fail (queue, NULL);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
retval = g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
return retval;
}
g_return_val_if_fail (queue, NULL);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
return retval;
}
g_return_val_if_fail (queue, 0);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
retval = queue->queue.length - queue->waiting_threads;
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
return retval;
}
g_return_if_fail (queue != NULL);
g_return_if_fail (func != NULL);
- g_mutex_lock (queue->mutex);
+ g_mutex_lock (&queue->mutex);
g_async_queue_sort_unlocked (queue, func, user_data);
- g_mutex_unlock (queue->mutex);
+ g_mutex_unlock (&queue->mutex);
}
/**
{
g_return_val_if_fail (queue, NULL);
- return queue->mutex;
+ return &queue->mutex;
}
static gsize profile_allocs = 0;
static gsize profile_zinit = 0;
static gsize profile_frees = 0;
-static GMutex *gmem_profile_mutex = NULL;
+static GMutex gmem_profile_mutex = G_MUTEX_INIT;
#ifdef G_ENABLE_DEBUG
static volatile gsize g_trap_free_size = 0;
static volatile gsize g_trap_realloc_size = 0;
gsize n_bytes,
gboolean success)
{
- g_mutex_lock (gmem_profile_mutex);
+ g_mutex_lock (&gmem_profile_mutex);
if (!profile_data)
{
profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8,
sizeof (profile_data[0]));
if (!profile_data) /* memory system kiddin' me, eh? */
{
- g_mutex_unlock (gmem_profile_mutex);
+ g_mutex_unlock (&gmem_profile_mutex);
return;
}
}
else
profile_frees += n_bytes;
}
- g_mutex_unlock (gmem_profile_mutex);
+ g_mutex_unlock (&gmem_profile_mutex);
}
static void
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
- g_mutex_lock (gmem_profile_mutex);
+ g_mutex_lock (&gmem_profile_mutex);
local_allocs = profile_allocs;
local_zinit = profile_zinit;
if (!profile_data)
{
- g_mutex_unlock (gmem_profile_mutex);
+ g_mutex_unlock (&gmem_profile_mutex);
return;
}
memcpy (local_data, profile_data,
(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
- g_mutex_unlock (gmem_profile_mutex);
+ g_mutex_unlock (&gmem_profile_mutex);
g_print ("GLib Memory statistics (successful operations):\n");
profile_print_locked (local_data, TRUE);
* unlocking a mutex does not yet work.
*/
g_mem_init_nomessage();
-#ifndef G_DISABLE_CHECKS
- gmem_profile_mutex = g_mutex_new ();
-#endif
}
/* --- variables --- */
-static GMutex *g_messages_lock = NULL;
+static GMutex g_messages_lock = G_MUTEX_INIT;
static GLogDomain *g_log_domains = NULL;
static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
static GPrintFunc glib_print_func = NULL;
/* remove bogus flag */
fatal_mask &= ~G_LOG_FLAG_FATAL;
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
old_mask = g_log_always_fatal;
g_log_always_fatal = fatal_mask;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return old_mask;
}
/* remove bogus flag */
fatal_mask &= ~G_LOG_FLAG_FATAL;
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
domain = g_log_find_domain_L (log_domain);
if (!domain)
domain->fatal_mask = fatal_mask;
g_log_domain_check_free_L (domain);
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return old_flags;
}
handler = g_new (GLogHandler, 1);
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
domain = g_log_find_domain_L (log_domain);
if (!domain)
handler->next = domain->handlers;
domain->handlers = handler;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return handler_id;
}
{
GLogFunc old_log_func;
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
old_log_func = default_log_func;
default_log_func = log_func;
default_log_data = user_data;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return old_log_func;
}
g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
gpointer user_data)
{
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
fatal_log_func = log_func;
fatal_log_data = user_data;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
}
void
if (!log_domain)
log_domain = "";
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
domain = g_log_find_domain_L (log_domain);
if (domain)
{
else
domain->handlers = work->next;
g_log_domain_check_free_L (domain);
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
g_free (work);
return;
}
work = last->next;
}
}
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
g_warning ("%s: could not find handler with id `%d' for domain \"%s\"",
G_STRLOC, handler_id, log_domain);
}
test_level |= G_LOG_FLAG_RECURSION;
/* check recursion and lookup handler */
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
domain = g_log_find_domain_L (log_domain ? log_domain : "");
if (depth)
test_level |= G_LOG_FLAG_RECURSION;
else
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
domain = NULL;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
if (test_level != orig_test_level)
{
/* need a relookup, not nice, but not too bad either */
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
domain = g_log_find_domain_L (log_domain ? log_domain : "");
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
domain = NULL;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
}
}
{
GPrintFunc old_print_func;
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
old_print_func = glib_print_func;
glib_print_func = func;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return old_print_func;
}
string = g_strdup_vprintf (format, args);
va_end (args);
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
local_glib_print_func = glib_print_func;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
if (local_glib_print_func)
local_glib_print_func (string);
{
GPrintFunc old_printerr_func;
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
old_printerr_func = glib_printerr_func;
glib_printerr_func = func;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
return old_printerr_func;
}
string = g_strdup_vprintf (format, args);
va_end (args);
- g_mutex_lock (g_messages_lock);
+ g_mutex_lock (&g_messages_lock);
local_glib_printerr_func = glib_printerr_func;
- g_mutex_unlock (g_messages_lock);
+ g_mutex_unlock (&g_messages_lock);
if (local_glib_printerr_func)
local_glib_printerr_func (string);
void
_g_messages_thread_init_nomessage (void)
{
- g_messages_lock = g_mutex_new ();
g_log_depth = g_private_new (NULL);
g_messages_prefixed_init ();
g_debug_init ();
SliceConfig config;
gsize max_slab_chunk_size_for_magazine_cache;
/* magazine cache */
- GMutex *magazine_mutex;
+ GMutex magazine_mutex;
ChunkLink **magazines; /* array of MAX_SLAB_INDEX (allocator) */
guint *contention_counters; /* array of MAX_SLAB_INDEX (allocator) */
gint mutex_counter;
guint stamp_counter;
guint last_stamp;
/* slab allocator */
- GMutex *slab_mutex;
+ GMutex slab_mutex;
SlabInfo **slab_stack; /* array of MAX_SLAB_INDEX (allocator) */
guint color_accu;
} Allocator;
15 * 1000, /* working_set_msecs */
1, /* color increment, alt: 0x7fffffff */
};
-static GMutex *smc_tree_mutex = NULL; /* mutex for G_SLICE=debug-blocks */
+static GMutex smc_tree_mutex = G_MUTEX_INIT; /* mutex for G_SLICE=debug-blocks */
/* --- auxiliary funcitons --- */
void
allocator->slab_stack = g_new0 (SlabInfo*, MAX_SLAB_INDEX (allocator));
}
- allocator->magazine_mutex = NULL; /* _g_slice_thread_init_nomessage() */
+ g_mutex_init (&allocator->magazine_mutex);
allocator->mutex_counter = 0;
allocator->stamp_counter = MAX_STAMP_COUNTER; /* force initial update */
allocator->last_stamp = 0;
- allocator->slab_mutex = NULL; /* _g_slice_thread_init_nomessage() */
+ g_mutex_init (&allocator->slab_mutex);
allocator->color_accu = 0;
magazine_cache_update_stamp();
/* values cached for performance reasons */
*/
}
private_thread_memory = g_private_new (private_thread_memory_cleanup);
- allocator->magazine_mutex = g_mutex_new();
- allocator->slab_mutex = g_mutex_new();
- if (allocator->config.debug_blocks)
- smc_tree_mutex = g_mutex_new();
}
static inline void
static ThreadMemory *single_thread_memory = NULL; /* remember single-thread info for multi-threaded case */
if (single_thread_memory && g_thread_supported ())
{
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
if (single_thread_memory)
{
/* GSlice has been used before g_thread_init(), and now
tmem = single_thread_memory;
single_thread_memory = NULL; /* slab_mutex protected when multi-threaded */
}
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
if (!tmem)
{
}
current = prev;
}
- g_mutex_unlock (allocator->magazine_mutex);
+ g_mutex_unlock (&allocator->magazine_mutex);
/* free trash */
if (trash)
{
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
while (trash)
{
current = trash;
slab_allocator_free_chunk (chunk_size, chunk);
}
}
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
}
{
ChunkLink *current = magazine_chain_prepare_fields (magazine_chunks);
ChunkLink *next, *prev;
- g_mutex_lock (allocator->magazine_mutex);
+ g_mutex_lock (&allocator->magazine_mutex);
/* add magazine at head */
next = allocator->magazines[ix];
if (next)
magazine_cache_pop_magazine (guint ix,
gsize *countp)
{
- g_mutex_lock_a (allocator->magazine_mutex, &allocator->contention_counters[ix]);
+ g_mutex_lock_a (&allocator->magazine_mutex, &allocator->contention_counters[ix]);
if (!allocator->magazines[ix])
{
guint magazine_threshold = allocator_get_magazine_threshold (allocator, ix);
gsize i, chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
ChunkLink *chunk, *head;
- g_mutex_unlock (allocator->magazine_mutex);
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->magazine_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
head = slab_allocator_alloc_chunk (chunk_size);
head->data = NULL;
chunk = head;
chunk->data = NULL;
}
chunk->next = NULL;
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
*countp = i;
return head;
}
magazine_chain_next (prev) = next;
magazine_chain_prev (next) = prev;
allocator->magazines[ix] = next == current ? NULL : next;
- g_mutex_unlock (allocator->magazine_mutex);
+ g_mutex_unlock (&allocator->magazine_mutex);
/* clear special fields and hand out */
*countp = (gsize) magazine_chain_count (current);
magazine_chain_prev (current) = NULL;
else
{
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
while (mag->chunks)
{
ChunkLink *chunk = magazine_chain_pop_head (&mag->chunks);
slab_allocator_free_chunk (chunk_size, chunk);
}
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
}
}
}
else if (acat == 2) /* allocate through slab allocator */
{
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
mem = slab_allocator_alloc_chunk (chunk_size);
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
else /* delegate to system malloc */
mem = g_malloc (mem_size);
{
if (G_UNLIKELY (g_mem_gc_friendly))
memset (mem_block, 0, chunk_size);
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
slab_allocator_free_chunk (chunk_size, mem_block);
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
else /* delegate to system malloc */
{
}
else if (acat == 2) /* allocate through slab allocator */
{
- g_mutex_lock (allocator->slab_mutex);
+ g_mutex_lock (&allocator->slab_mutex);
while (slice)
{
guint8 *current = slice;
memset (current, 0, chunk_size);
slab_allocator_free_chunk (chunk_size, current);
}
- g_mutex_unlock (allocator->slab_mutex);
+ g_mutex_unlock (&allocator->slab_mutex);
}
else /* delegate to system malloc */
while (slice)
unsigned int ix0, ix1;
SmcEntry *entry;
- g_mutex_lock (smc_tree_mutex);
+ g_mutex_lock (&smc_tree_mutex);
ix0 = SMC_TRUNK_HASH (key);
ix1 = SMC_BRANCH_HASH (key);
if (!smc_tree_root)
entry = smc_tree_branch_grow_L (&smc_tree_root[ix0][ix1], entry - smc_tree_root[ix0][ix1].entries);
entry->key = key;
entry->value = value;
- g_mutex_unlock (smc_tree_mutex);
+ g_mutex_unlock (&smc_tree_mutex);
}
static gboolean
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
gboolean found_one = FALSE;
*value_p = 0;
- g_mutex_lock (smc_tree_mutex);
+ g_mutex_lock (&smc_tree_mutex);
if (smc_tree_root && smc_tree_root[ix0])
{
entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
*value_p = entry->value;
}
}
- g_mutex_unlock (smc_tree_mutex);
+ g_mutex_unlock (&smc_tree_mutex);
return found_one;
}
{
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
gboolean found_one = FALSE;
- g_mutex_lock (smc_tree_mutex);
+ g_mutex_lock (&smc_tree_mutex);
if (smc_tree_root && smc_tree_root[ix0])
{
SmcEntry *entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
found_one = TRUE;
}
}
- g_mutex_unlock (smc_tree_mutex);
+ g_mutex_unlock (&smc_tree_mutex);
return found_one;
}
void
g_slice_debug_tree_statistics (void)
{
- g_mutex_lock (smc_tree_mutex);
+ g_mutex_lock (&smc_tree_mutex);
if (smc_tree_root)
{
unsigned int i, j, t = 0, o = 0, b = 0, su = 0, ex = 0, en = 4294967295u;
}
else
fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
- g_mutex_unlock (smc_tree_mutex);
+ g_mutex_unlock (&smc_tree_mutex);
/* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
* PID %CPU %MEM VSZ RSS COMMAND
/* Local Data {{{1 -------------------------------------------------------- */
-static GMutex *g_once_mutex = NULL;
+static GMutex g_once_mutex = G_MUTEX_INIT;
static GCond *g_once_cond = NULL;
static GPrivate *g_thread_specific_private = NULL;
static GRealThread *g_thread_all_threads = NULL;
GRealThread* main_thread = (GRealThread*) g_thread_self ();
/* mutex and cond creation works without g_threads_got_initialized */
- g_once_mutex = g_mutex_new ();
g_once_cond = g_cond_new ();
/* we may only create mutex and cond in here */
GThreadFunc func,
gpointer arg)
{
- g_mutex_lock (g_once_mutex);
+ g_mutex_lock (&g_once_mutex);
while (once->status == G_ONCE_STATUS_PROGRESS)
- g_cond_wait (g_once_cond, g_once_mutex);
+ g_cond_wait (g_once_cond, &g_once_mutex);
if (once->status != G_ONCE_STATUS_READY)
{
once->status = G_ONCE_STATUS_PROGRESS;
- g_mutex_unlock (g_once_mutex);
+ g_mutex_unlock (&g_once_mutex);
once->retval = func (arg);
- g_mutex_lock (g_once_mutex);
+ g_mutex_lock (&g_once_mutex);
once->status = G_ONCE_STATUS_READY;
g_cond_broadcast (g_once_cond);
}
- g_mutex_unlock (g_once_mutex);
+ g_mutex_unlock (&g_once_mutex);
return once->retval;
}
g_once_init_enter_impl (volatile gsize *value_location)
{
gboolean need_init = FALSE;
- g_mutex_lock (g_once_mutex);
+ g_mutex_lock (&g_once_mutex);
if (g_atomic_pointer_get (value_location) == NULL)
{
if (!g_slist_find (g_once_init_list, (void*) value_location))
}
else
do
- g_cond_wait (g_once_cond, g_once_mutex);
+ g_cond_wait (g_once_cond, &g_once_mutex);
while (g_slist_find (g_once_init_list, (void*) value_location));
}
- g_mutex_unlock (g_once_mutex);
+ g_mutex_unlock (&g_once_mutex);
return need_init;
}
g_return_if_fail (g_once_init_list != NULL);
g_atomic_pointer_set (value_location, initialization_value);
- g_mutex_lock (g_once_mutex);
+ g_mutex_lock (&g_once_mutex);
g_once_init_list = g_slist_remove (g_once_init_list, (void*) value_location);
g_cond_broadcast (g_once_cond);
- g_mutex_unlock (g_once_mutex);
+ g_mutex_unlock (&g_once_mutex);
}
/* GStaticMutex {{{1 ------------------------------------------------------ */
if (!result)
{
- g_assert (g_once_mutex);
-
- g_mutex_lock (g_once_mutex);
+ g_mutex_lock (&g_once_mutex);
result = *mutex;
if (!result)
g_atomic_pointer_set (mutex, result);
}
- g_mutex_unlock (g_once_mutex);
+ g_mutex_unlock (&g_once_mutex);
}
return result;