libglib: stop using g_mutex_new

Use G_MUTEX_INIT or g_mutex_init() as appropriate.
This commit is contained in:
Ryan Lortie 2011-09-17 17:56:33 -04:00
parent f35362f3ae
commit 2c7388c19a
5 changed files with 101 additions and 112 deletions

View File

@ -90,7 +90,7 @@
*/
struct _GAsyncQueue
{
GMutex *mutex;
GMutex mutex;
GCond *cond;
GQueue queue;
GDestroyNotify item_free_func;
@ -114,7 +114,7 @@ GAsyncQueue*
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;
@ -198,7 +198,7 @@ g_async_queue_unref_and_unlock (GAsyncQueue *queue)
{
g_return_if_fail (queue);
g_mutex_unlock (queue->mutex);
g_mutex_unlock (&queue->mutex);
g_async_queue_unref (queue);
}
@ -220,7 +220,7 @@ g_async_queue_unref (GAsyncQueue *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)
@ -243,7 +243,7 @@ g_async_queue_lock (GAsyncQueue *queue)
{
g_return_if_fail (queue);
g_mutex_lock (queue->mutex);
g_mutex_lock (&queue->mutex);
}
/**
@ -257,7 +257,7 @@ g_async_queue_unlock (GAsyncQueue *queue)
{
g_return_if_fail (queue);
g_mutex_unlock (queue->mutex);
g_mutex_unlock (&queue->mutex);
}
/**
@ -273,9 +273,9 @@ g_async_queue_push (GAsyncQueue* queue, gpointer data)
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);
}
/**
@ -329,9 +329,9 @@ g_async_queue_push_sorted (GAsyncQueue *queue,
{
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
@ -405,14 +405,14 @@ g_async_queue_pop_intern_unlocked (GAsyncQueue *queue,
{
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))
@ -443,9 +443,9 @@ g_async_queue_pop (GAsyncQueue* 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;
}
@ -485,9 +485,9 @@ g_async_queue_try_pop (GAsyncQueue* 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, TRUE, NULL);
g_mutex_unlock (queue->mutex);
g_mutex_unlock (&queue->mutex);
return retval;
}
@ -532,9 +532,9 @@ g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
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;
}
@ -583,9 +583,9 @@ g_async_queue_length (GAsyncQueue* queue)
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;
}
@ -651,9 +651,9 @@ g_async_queue_sort (GAsyncQueue *queue,
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);
}
/**
@ -700,5 +700,5 @@ _g_async_queue_get_mutex (GAsyncQueue* queue)
{
g_return_val_if_fail (queue, NULL);
return queue->mutex;
return &queue->mutex;
}

View File

@ -600,7 +600,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 = 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;
@ -614,14 +614,14 @@ profiler_log (ProfilerJob job,
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;
}
}
@ -645,7 +645,7 @@ profiler_log (ProfilerJob job,
else
profile_frees += n_bytes;
}
g_mutex_unlock (gmem_profile_mutex);
g_mutex_unlock (&gmem_profile_mutex);
}
static void
@ -711,7 +711,7 @@ g_mem_profile (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;
@ -719,14 +719,14 @@ g_mem_profile (void)
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);
@ -950,7 +950,4 @@ _g_mem_thread_init_noprivate_nomessage (void)
* unlocking a mutex does not yet work.
*/
g_mem_init_nomessage();
#ifndef G_DISABLE_CHECKS
gmem_profile_mutex = g_mutex_new ();
#endif
}

View File

@ -102,7 +102,7 @@ struct _GLogHandler
/* --- 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;
@ -328,10 +328,10 @@ g_log_set_always_fatal (GLogLevelFlags fatal_mask)
/* 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;
}
@ -351,7 +351,7 @@ g_log_set_fatal_mask (const gchar *log_domain,
/* 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)
@ -361,7 +361,7 @@ g_log_set_fatal_mask (const gchar *log_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;
}
@ -384,7 +384,7 @@ g_log_set_handler (const gchar *log_domain,
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)
@ -397,7 +397,7 @@ g_log_set_handler (const gchar *log_domain,
handler->next = domain->handlers;
domain->handlers = handler;
g_mutex_unlock (g_messages_lock);
g_mutex_unlock (&g_messages_lock);
return handler_id;
}
@ -408,11 +408,11 @@ g_log_set_default_handler (GLogFunc log_func,
{
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;
}
@ -444,10 +444,10 @@ void
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
@ -461,7 +461,7 @@ g_log_remove_handler (const gchar *log_domain,
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)
{
@ -478,7 +478,7 @@ g_log_remove_handler (const gchar *log_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;
}
@ -486,7 +486,7 @@ g_log_remove_handler (const gchar *log_domain,
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);
}
@ -525,7 +525,7 @@ g_logv (const gchar *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;
@ -538,7 +538,7 @@ g_logv (const gchar *log_domain,
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));
@ -553,11 +553,11 @@ g_logv (const gchar *log_domain,
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);
}
}
@ -1066,10 +1066,10 @@ g_set_print_handler (GPrintFunc func)
{
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;
}
@ -1102,9 +1102,9 @@ g_print (const gchar *format,
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);
@ -1145,10 +1145,10 @@ g_set_printerr_handler (GPrintFunc func)
{
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;
}
@ -1179,9 +1179,9 @@ g_printerr (const gchar *format,
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);
@ -1214,7 +1214,6 @@ g_printf_string_upper_bound (const gchar *format,
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 ();

View File

@ -170,14 +170,14 @@ typedef struct {
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;
@ -212,7 +212,7 @@ static SliceConfig slice_config = {
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
@ -346,11 +346,11 @@ g_slice_init_nomessage (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 */
@ -399,10 +399,6 @@ _g_slice_thread_init_nomessage (void)
*/
}
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
@ -444,7 +440,7 @@ thread_memory_from_self (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
@ -454,7 +450,7 @@ thread_memory_from_self (void)
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)
{
@ -615,12 +611,12 @@ magazine_cache_trim (Allocator *allocator,
}
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;
@ -632,7 +628,7 @@ magazine_cache_trim (Allocator *allocator,
slab_allocator_free_chunk (chunk_size, chunk);
}
}
g_mutex_unlock (allocator->slab_mutex);
g_mutex_unlock (&allocator->slab_mutex);
}
}
@ -643,7 +639,7 @@ magazine_cache_push_magazine (guint ix,
{
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)
@ -668,14 +664,14 @@ static ChunkLink*
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;
@ -686,7 +682,7 @@ magazine_cache_pop_magazine (guint ix,
chunk->data = NULL;
}
chunk->next = NULL;
g_mutex_unlock (allocator->slab_mutex);
g_mutex_unlock (&allocator->slab_mutex);
*countp = i;
return head;
}
@ -699,7 +695,7 @@ magazine_cache_pop_magazine (guint ix,
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;
@ -731,13 +727,13 @@ private_thread_memory_cleanup (gpointer data)
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);
}
}
}
@ -834,9 +830,9 @@ g_slice_alloc (gsize mem_size)
}
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);
@ -896,9 +892,9 @@ g_slice_free1 (gsize 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 */
{
@ -956,7 +952,7 @@ g_slice_free_chain_with_offset (gsize mem_size,
}
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;
@ -968,7 +964,7 @@ g_slice_free_chain_with_offset (gsize mem_size,
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)
@ -1354,7 +1350,7 @@ smc_tree_insert (SmcKType key,
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)
@ -1376,7 +1372,7 @@ smc_tree_insert (SmcKType key,
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
@ -1387,7 +1383,7 @@ smc_tree_lookup (SmcKType key,
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);
@ -1399,7 +1395,7 @@ smc_tree_lookup (SmcKType key,
*value_p = entry->value;
}
}
g_mutex_unlock (smc_tree_mutex);
g_mutex_unlock (&smc_tree_mutex);
return found_one;
}
@ -1408,7 +1404,7 @@ smc_tree_remove (SmcKType key)
{
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);
@ -1428,7 +1424,7 @@ smc_tree_remove (SmcKType key)
found_one = TRUE;
}
}
g_mutex_unlock (smc_tree_mutex);
g_mutex_unlock (&smc_tree_mutex);
return found_one;
}
@ -1436,7 +1432,7 @@ smc_tree_remove (SmcKType key)
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;
@ -1468,7 +1464,7 @@ g_slice_debug_tree_statistics (void)
}
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

View File

@ -873,7 +873,7 @@ static GThreadFunctions g_thread_functions_for_glib_use_old = {
/* 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;
@ -940,7 +940,6 @@ g_thread_init_glib (void)
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 */
@ -1046,24 +1045,24 @@ g_once_impl (GOnce *once,
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;
}
@ -1106,7 +1105,7 @@ gboolean
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))
@ -1116,10 +1115,10 @@ g_once_init_enter_impl (volatile gsize *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;
}
@ -1146,10 +1145,10 @@ g_once_init_leave (volatile gsize *value_location,
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 ------------------------------------------------------ */
@ -1279,9 +1278,7 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
if (!result)
{
g_assert (g_once_mutex);
g_mutex_lock (g_once_mutex);
g_mutex_lock (&g_once_mutex);
result = *mutex;
if (!result)
@ -1290,7 +1287,7 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
g_atomic_pointer_set (mutex, result);
}
g_mutex_unlock (g_once_mutex);
g_mutex_unlock (&g_once_mutex);
}
return result;