mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 08:28:53 +02:00
libglib: stop using g_mutex_new
Use G_MUTEX_INIT or g_mutex_init() as appropriate.
This commit is contained in:
@@ -90,7 +90,7 @@
|
|||||||
*/
|
*/
|
||||||
struct _GAsyncQueue
|
struct _GAsyncQueue
|
||||||
{
|
{
|
||||||
GMutex *mutex;
|
GMutex mutex;
|
||||||
GCond *cond;
|
GCond *cond;
|
||||||
GQueue queue;
|
GQueue queue;
|
||||||
GDestroyNotify item_free_func;
|
GDestroyNotify item_free_func;
|
||||||
@@ -114,7 +114,7 @@ GAsyncQueue*
|
|||||||
g_async_queue_new (void)
|
g_async_queue_new (void)
|
||||||
{
|
{
|
||||||
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
|
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
|
||||||
retval->mutex = g_mutex_new ();
|
g_mutex_init (&retval->mutex);
|
||||||
retval->cond = NULL;
|
retval->cond = NULL;
|
||||||
g_queue_init (&retval->queue);
|
g_queue_init (&retval->queue);
|
||||||
retval->waiting_threads = 0;
|
retval->waiting_threads = 0;
|
||||||
@@ -198,7 +198,7 @@ g_async_queue_unref_and_unlock (GAsyncQueue *queue)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (queue);
|
g_return_if_fail (queue);
|
||||||
|
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
g_async_queue_unref (queue);
|
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))
|
if (g_atomic_int_dec_and_test (&queue->ref_count))
|
||||||
{
|
{
|
||||||
g_return_if_fail (queue->waiting_threads == 0);
|
g_return_if_fail (queue->waiting_threads == 0);
|
||||||
g_mutex_free (queue->mutex);
|
g_mutex_clear (&queue->mutex);
|
||||||
if (queue->cond)
|
if (queue->cond)
|
||||||
g_cond_free (queue->cond);
|
g_cond_free (queue->cond);
|
||||||
if (queue->item_free_func)
|
if (queue->item_free_func)
|
||||||
@@ -243,7 +243,7 @@ g_async_queue_lock (GAsyncQueue *queue)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (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_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 (queue);
|
||||||
g_return_if_fail (data);
|
g_return_if_fail (data);
|
||||||
|
|
||||||
g_mutex_lock (queue->mutex);
|
g_mutex_lock (&queue->mutex);
|
||||||
g_async_queue_push_unlocked (queue, data);
|
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_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_async_queue_push_sorted_unlocked (queue, data, func, user_data);
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@@ -405,14 +405,14 @@ g_async_queue_pop_intern_unlocked (GAsyncQueue *queue,
|
|||||||
{
|
{
|
||||||
queue->waiting_threads++;
|
queue->waiting_threads++;
|
||||||
while (!g_queue_peek_tail_link (&queue->queue))
|
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--;
|
queue->waiting_threads--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
queue->waiting_threads++;
|
queue->waiting_threads++;
|
||||||
while (!g_queue_peek_tail_link (&queue->queue))
|
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;
|
break;
|
||||||
queue->waiting_threads--;
|
queue->waiting_threads--;
|
||||||
if (!g_queue_peek_tail_link (&queue->queue))
|
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_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);
|
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -485,9 +485,9 @@ g_async_queue_try_pop (GAsyncQueue* queue)
|
|||||||
|
|
||||||
g_return_val_if_fail (queue, NULL);
|
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);
|
retval = g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -532,9 +532,9 @@ g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
|
|||||||
|
|
||||||
g_return_val_if_fail (queue, NULL);
|
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);
|
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -583,9 +583,9 @@ g_async_queue_length (GAsyncQueue* queue)
|
|||||||
|
|
||||||
g_return_val_if_fail (queue, 0);
|
g_return_val_if_fail (queue, 0);
|
||||||
|
|
||||||
g_mutex_lock (queue->mutex);
|
g_mutex_lock (&queue->mutex);
|
||||||
retval = queue->queue.length - queue->waiting_threads;
|
retval = queue->queue.length - queue->waiting_threads;
|
||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (&queue->mutex);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -651,9 +651,9 @@ g_async_queue_sort (GAsyncQueue *queue,
|
|||||||
g_return_if_fail (queue != NULL);
|
g_return_if_fail (queue != NULL);
|
||||||
g_return_if_fail (func != 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_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);
|
g_return_val_if_fail (queue, NULL);
|
||||||
|
|
||||||
return queue->mutex;
|
return &queue->mutex;
|
||||||
}
|
}
|
||||||
|
17
glib/gmem.c
17
glib/gmem.c
@@ -600,7 +600,7 @@ static guint *profile_data = NULL;
|
|||||||
static gsize profile_allocs = 0;
|
static gsize profile_allocs = 0;
|
||||||
static gsize profile_zinit = 0;
|
static gsize profile_zinit = 0;
|
||||||
static gsize profile_frees = 0;
|
static gsize profile_frees = 0;
|
||||||
static GMutex *gmem_profile_mutex = NULL;
|
static GMutex gmem_profile_mutex = G_MUTEX_INIT;
|
||||||
#ifdef G_ENABLE_DEBUG
|
#ifdef G_ENABLE_DEBUG
|
||||||
static volatile gsize g_trap_free_size = 0;
|
static volatile gsize g_trap_free_size = 0;
|
||||||
static volatile gsize g_trap_realloc_size = 0;
|
static volatile gsize g_trap_realloc_size = 0;
|
||||||
@@ -614,14 +614,14 @@ profiler_log (ProfilerJob job,
|
|||||||
gsize n_bytes,
|
gsize n_bytes,
|
||||||
gboolean success)
|
gboolean success)
|
||||||
{
|
{
|
||||||
g_mutex_lock (gmem_profile_mutex);
|
g_mutex_lock (&gmem_profile_mutex);
|
||||||
if (!profile_data)
|
if (!profile_data)
|
||||||
{
|
{
|
||||||
profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8,
|
profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8,
|
||||||
sizeof (profile_data[0]));
|
sizeof (profile_data[0]));
|
||||||
if (!profile_data) /* memory system kiddin' me, eh? */
|
if (!profile_data) /* memory system kiddin' me, eh? */
|
||||||
{
|
{
|
||||||
g_mutex_unlock (gmem_profile_mutex);
|
g_mutex_unlock (&gmem_profile_mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -645,7 +645,7 @@ profiler_log (ProfilerJob job,
|
|||||||
else
|
else
|
||||||
profile_frees += n_bytes;
|
profile_frees += n_bytes;
|
||||||
}
|
}
|
||||||
g_mutex_unlock (gmem_profile_mutex);
|
g_mutex_unlock (&gmem_profile_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -711,7 +711,7 @@ g_mem_profile (void)
|
|||||||
if (G_UNLIKELY (!g_mem_initialized))
|
if (G_UNLIKELY (!g_mem_initialized))
|
||||||
g_mem_init_nomessage();
|
g_mem_init_nomessage();
|
||||||
|
|
||||||
g_mutex_lock (gmem_profile_mutex);
|
g_mutex_lock (&gmem_profile_mutex);
|
||||||
|
|
||||||
local_allocs = profile_allocs;
|
local_allocs = profile_allocs;
|
||||||
local_zinit = profile_zinit;
|
local_zinit = profile_zinit;
|
||||||
@@ -719,14 +719,14 @@ g_mem_profile (void)
|
|||||||
|
|
||||||
if (!profile_data)
|
if (!profile_data)
|
||||||
{
|
{
|
||||||
g_mutex_unlock (gmem_profile_mutex);
|
g_mutex_unlock (&gmem_profile_mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (local_data, profile_data,
|
memcpy (local_data, profile_data,
|
||||||
(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
|
(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");
|
g_print ("GLib Memory statistics (successful operations):\n");
|
||||||
profile_print_locked (local_data, TRUE);
|
profile_print_locked (local_data, TRUE);
|
||||||
@@ -950,7 +950,4 @@ _g_mem_thread_init_noprivate_nomessage (void)
|
|||||||
* unlocking a mutex does not yet work.
|
* unlocking a mutex does not yet work.
|
||||||
*/
|
*/
|
||||||
g_mem_init_nomessage();
|
g_mem_init_nomessage();
|
||||||
#ifndef G_DISABLE_CHECKS
|
|
||||||
gmem_profile_mutex = g_mutex_new ();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@@ -102,7 +102,7 @@ struct _GLogHandler
|
|||||||
|
|
||||||
|
|
||||||
/* --- variables --- */
|
/* --- variables --- */
|
||||||
static GMutex *g_messages_lock = NULL;
|
static GMutex g_messages_lock = G_MUTEX_INIT;
|
||||||
static GLogDomain *g_log_domains = NULL;
|
static GLogDomain *g_log_domains = NULL;
|
||||||
static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
|
static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
|
||||||
static GPrintFunc glib_print_func = NULL;
|
static GPrintFunc glib_print_func = NULL;
|
||||||
@@ -328,10 +328,10 @@ g_log_set_always_fatal (GLogLevelFlags fatal_mask)
|
|||||||
/* remove bogus flag */
|
/* remove bogus flag */
|
||||||
fatal_mask &= ~G_LOG_FLAG_FATAL;
|
fatal_mask &= ~G_LOG_FLAG_FATAL;
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
old_mask = g_log_always_fatal;
|
old_mask = g_log_always_fatal;
|
||||||
g_log_always_fatal = fatal_mask;
|
g_log_always_fatal = fatal_mask;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return old_mask;
|
return old_mask;
|
||||||
}
|
}
|
||||||
@@ -351,7 +351,7 @@ g_log_set_fatal_mask (const gchar *log_domain,
|
|||||||
/* remove bogus flag */
|
/* remove bogus flag */
|
||||||
fatal_mask &= ~G_LOG_FLAG_FATAL;
|
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);
|
domain = g_log_find_domain_L (log_domain);
|
||||||
if (!domain)
|
if (!domain)
|
||||||
@@ -361,7 +361,7 @@ g_log_set_fatal_mask (const gchar *log_domain,
|
|||||||
domain->fatal_mask = fatal_mask;
|
domain->fatal_mask = fatal_mask;
|
||||||
g_log_domain_check_free_L (domain);
|
g_log_domain_check_free_L (domain);
|
||||||
|
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return old_flags;
|
return old_flags;
|
||||||
}
|
}
|
||||||
@@ -384,7 +384,7 @@ g_log_set_handler (const gchar *log_domain,
|
|||||||
|
|
||||||
handler = g_new (GLogHandler, 1);
|
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);
|
domain = g_log_find_domain_L (log_domain);
|
||||||
if (!domain)
|
if (!domain)
|
||||||
@@ -397,7 +397,7 @@ g_log_set_handler (const gchar *log_domain,
|
|||||||
handler->next = domain->handlers;
|
handler->next = domain->handlers;
|
||||||
domain->handlers = handler;
|
domain->handlers = handler;
|
||||||
|
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return handler_id;
|
return handler_id;
|
||||||
}
|
}
|
||||||
@@ -408,11 +408,11 @@ g_log_set_default_handler (GLogFunc log_func,
|
|||||||
{
|
{
|
||||||
GLogFunc old_log_func;
|
GLogFunc old_log_func;
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
old_log_func = default_log_func;
|
old_log_func = default_log_func;
|
||||||
default_log_func = log_func;
|
default_log_func = log_func;
|
||||||
default_log_data = user_data;
|
default_log_data = user_data;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return old_log_func;
|
return old_log_func;
|
||||||
}
|
}
|
||||||
@@ -444,10 +444,10 @@ void
|
|||||||
g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
|
g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
fatal_log_func = log_func;
|
fatal_log_func = log_func;
|
||||||
fatal_log_data = user_data;
|
fatal_log_data = user_data;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -461,7 +461,7 @@ g_log_remove_handler (const gchar *log_domain,
|
|||||||
if (!log_domain)
|
if (!log_domain)
|
||||||
log_domain = "";
|
log_domain = "";
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
domain = g_log_find_domain_L (log_domain);
|
domain = g_log_find_domain_L (log_domain);
|
||||||
if (domain)
|
if (domain)
|
||||||
{
|
{
|
||||||
@@ -478,7 +478,7 @@ g_log_remove_handler (const gchar *log_domain,
|
|||||||
else
|
else
|
||||||
domain->handlers = work->next;
|
domain->handlers = work->next;
|
||||||
g_log_domain_check_free_L (domain);
|
g_log_domain_check_free_L (domain);
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
g_free (work);
|
g_free (work);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -486,7 +486,7 @@ g_log_remove_handler (const gchar *log_domain,
|
|||||||
work = last->next;
|
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_warning ("%s: could not find handler with id `%d' for domain \"%s\"",
|
||||||
G_STRLOC, handler_id, log_domain);
|
G_STRLOC, handler_id, log_domain);
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ g_logv (const gchar *log_domain,
|
|||||||
test_level |= G_LOG_FLAG_RECURSION;
|
test_level |= G_LOG_FLAG_RECURSION;
|
||||||
|
|
||||||
/* check recursion and lookup handler */
|
/* 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 : "");
|
domain = g_log_find_domain_L (log_domain ? log_domain : "");
|
||||||
if (depth)
|
if (depth)
|
||||||
test_level |= G_LOG_FLAG_RECURSION;
|
test_level |= G_LOG_FLAG_RECURSION;
|
||||||
@@ -538,7 +538,7 @@ g_logv (const gchar *log_domain,
|
|||||||
else
|
else
|
||||||
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
|
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
|
||||||
domain = NULL;
|
domain = NULL;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
|
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)
|
if (test_level != orig_test_level)
|
||||||
{
|
{
|
||||||
/* need a relookup, not nice, but not too bad either */
|
/* 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 : "");
|
domain = g_log_find_domain_L (log_domain ? log_domain : "");
|
||||||
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
|
log_func = g_log_domain_get_handler_L (domain, test_level, &data);
|
||||||
domain = NULL;
|
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;
|
GPrintFunc old_print_func;
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
old_print_func = glib_print_func;
|
old_print_func = glib_print_func;
|
||||||
glib_print_func = func;
|
glib_print_func = func;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return old_print_func;
|
return old_print_func;
|
||||||
}
|
}
|
||||||
@@ -1102,9 +1102,9 @@ g_print (const gchar *format,
|
|||||||
string = g_strdup_vprintf (format, args);
|
string = g_strdup_vprintf (format, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
local_glib_print_func = glib_print_func;
|
local_glib_print_func = glib_print_func;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
if (local_glib_print_func)
|
if (local_glib_print_func)
|
||||||
local_glib_print_func (string);
|
local_glib_print_func (string);
|
||||||
@@ -1145,10 +1145,10 @@ g_set_printerr_handler (GPrintFunc func)
|
|||||||
{
|
{
|
||||||
GPrintFunc old_printerr_func;
|
GPrintFunc old_printerr_func;
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
old_printerr_func = glib_printerr_func;
|
old_printerr_func = glib_printerr_func;
|
||||||
glib_printerr_func = func;
|
glib_printerr_func = func;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
return old_printerr_func;
|
return old_printerr_func;
|
||||||
}
|
}
|
||||||
@@ -1179,9 +1179,9 @@ g_printerr (const gchar *format,
|
|||||||
string = g_strdup_vprintf (format, args);
|
string = g_strdup_vprintf (format, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
g_mutex_lock (g_messages_lock);
|
g_mutex_lock (&g_messages_lock);
|
||||||
local_glib_printerr_func = glib_printerr_func;
|
local_glib_printerr_func = glib_printerr_func;
|
||||||
g_mutex_unlock (g_messages_lock);
|
g_mutex_unlock (&g_messages_lock);
|
||||||
|
|
||||||
if (local_glib_printerr_func)
|
if (local_glib_printerr_func)
|
||||||
local_glib_printerr_func (string);
|
local_glib_printerr_func (string);
|
||||||
@@ -1214,7 +1214,6 @@ g_printf_string_upper_bound (const gchar *format,
|
|||||||
void
|
void
|
||||||
_g_messages_thread_init_nomessage (void)
|
_g_messages_thread_init_nomessage (void)
|
||||||
{
|
{
|
||||||
g_messages_lock = g_mutex_new ();
|
|
||||||
g_log_depth = g_private_new (NULL);
|
g_log_depth = g_private_new (NULL);
|
||||||
g_messages_prefixed_init ();
|
g_messages_prefixed_init ();
|
||||||
g_debug_init ();
|
g_debug_init ();
|
||||||
|
@@ -170,14 +170,14 @@ typedef struct {
|
|||||||
SliceConfig config;
|
SliceConfig config;
|
||||||
gsize max_slab_chunk_size_for_magazine_cache;
|
gsize max_slab_chunk_size_for_magazine_cache;
|
||||||
/* magazine cache */
|
/* magazine cache */
|
||||||
GMutex *magazine_mutex;
|
GMutex magazine_mutex;
|
||||||
ChunkLink **magazines; /* array of MAX_SLAB_INDEX (allocator) */
|
ChunkLink **magazines; /* array of MAX_SLAB_INDEX (allocator) */
|
||||||
guint *contention_counters; /* array of MAX_SLAB_INDEX (allocator) */
|
guint *contention_counters; /* array of MAX_SLAB_INDEX (allocator) */
|
||||||
gint mutex_counter;
|
gint mutex_counter;
|
||||||
guint stamp_counter;
|
guint stamp_counter;
|
||||||
guint last_stamp;
|
guint last_stamp;
|
||||||
/* slab allocator */
|
/* slab allocator */
|
||||||
GMutex *slab_mutex;
|
GMutex slab_mutex;
|
||||||
SlabInfo **slab_stack; /* array of MAX_SLAB_INDEX (allocator) */
|
SlabInfo **slab_stack; /* array of MAX_SLAB_INDEX (allocator) */
|
||||||
guint color_accu;
|
guint color_accu;
|
||||||
} Allocator;
|
} Allocator;
|
||||||
@@ -212,7 +212,7 @@ static SliceConfig slice_config = {
|
|||||||
15 * 1000, /* working_set_msecs */
|
15 * 1000, /* working_set_msecs */
|
||||||
1, /* color increment, alt: 0x7fffffff */
|
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 --- */
|
/* --- auxiliary funcitons --- */
|
||||||
void
|
void
|
||||||
@@ -346,11 +346,11 @@ g_slice_init_nomessage (void)
|
|||||||
allocator->slab_stack = g_new0 (SlabInfo*, MAX_SLAB_INDEX (allocator));
|
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->mutex_counter = 0;
|
||||||
allocator->stamp_counter = MAX_STAMP_COUNTER; /* force initial update */
|
allocator->stamp_counter = MAX_STAMP_COUNTER; /* force initial update */
|
||||||
allocator->last_stamp = 0;
|
allocator->last_stamp = 0;
|
||||||
allocator->slab_mutex = NULL; /* _g_slice_thread_init_nomessage() */
|
g_mutex_init (&allocator->slab_mutex);
|
||||||
allocator->color_accu = 0;
|
allocator->color_accu = 0;
|
||||||
magazine_cache_update_stamp();
|
magazine_cache_update_stamp();
|
||||||
/* values cached for performance reasons */
|
/* 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);
|
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 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 */
|
static ThreadMemory *single_thread_memory = NULL; /* remember single-thread info for multi-threaded case */
|
||||||
if (single_thread_memory && g_thread_supported ())
|
if (single_thread_memory && g_thread_supported ())
|
||||||
{
|
{
|
||||||
g_mutex_lock (allocator->slab_mutex);
|
g_mutex_lock (&allocator->slab_mutex);
|
||||||
if (single_thread_memory)
|
if (single_thread_memory)
|
||||||
{
|
{
|
||||||
/* GSlice has been used before g_thread_init(), and now
|
/* GSlice has been used before g_thread_init(), and now
|
||||||
@@ -454,7 +450,7 @@ thread_memory_from_self (void)
|
|||||||
tmem = single_thread_memory;
|
tmem = single_thread_memory;
|
||||||
single_thread_memory = NULL; /* slab_mutex protected when multi-threaded */
|
single_thread_memory = NULL; /* slab_mutex protected when multi-threaded */
|
||||||
}
|
}
|
||||||
g_mutex_unlock (allocator->slab_mutex);
|
g_mutex_unlock (&allocator->slab_mutex);
|
||||||
}
|
}
|
||||||
if (!tmem)
|
if (!tmem)
|
||||||
{
|
{
|
||||||
@@ -615,12 +611,12 @@ magazine_cache_trim (Allocator *allocator,
|
|||||||
}
|
}
|
||||||
current = prev;
|
current = prev;
|
||||||
}
|
}
|
||||||
g_mutex_unlock (allocator->magazine_mutex);
|
g_mutex_unlock (&allocator->magazine_mutex);
|
||||||
/* free trash */
|
/* free trash */
|
||||||
if (trash)
|
if (trash)
|
||||||
{
|
{
|
||||||
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
||||||
g_mutex_lock (allocator->slab_mutex);
|
g_mutex_lock (&allocator->slab_mutex);
|
||||||
while (trash)
|
while (trash)
|
||||||
{
|
{
|
||||||
current = trash;
|
current = trash;
|
||||||
@@ -632,7 +628,7 @@ magazine_cache_trim (Allocator *allocator,
|
|||||||
slab_allocator_free_chunk (chunk_size, chunk);
|
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 *current = magazine_chain_prepare_fields (magazine_chunks);
|
||||||
ChunkLink *next, *prev;
|
ChunkLink *next, *prev;
|
||||||
g_mutex_lock (allocator->magazine_mutex);
|
g_mutex_lock (&allocator->magazine_mutex);
|
||||||
/* add magazine at head */
|
/* add magazine at head */
|
||||||
next = allocator->magazines[ix];
|
next = allocator->magazines[ix];
|
||||||
if (next)
|
if (next)
|
||||||
@@ -668,14 +664,14 @@ static ChunkLink*
|
|||||||
magazine_cache_pop_magazine (guint ix,
|
magazine_cache_pop_magazine (guint ix,
|
||||||
gsize *countp)
|
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])
|
if (!allocator->magazines[ix])
|
||||||
{
|
{
|
||||||
guint magazine_threshold = allocator_get_magazine_threshold (allocator, ix);
|
guint magazine_threshold = allocator_get_magazine_threshold (allocator, ix);
|
||||||
gsize i, chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
gsize i, chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
||||||
ChunkLink *chunk, *head;
|
ChunkLink *chunk, *head;
|
||||||
g_mutex_unlock (allocator->magazine_mutex);
|
g_mutex_unlock (&allocator->magazine_mutex);
|
||||||
g_mutex_lock (allocator->slab_mutex);
|
g_mutex_lock (&allocator->slab_mutex);
|
||||||
head = slab_allocator_alloc_chunk (chunk_size);
|
head = slab_allocator_alloc_chunk (chunk_size);
|
||||||
head->data = NULL;
|
head->data = NULL;
|
||||||
chunk = head;
|
chunk = head;
|
||||||
@@ -686,7 +682,7 @@ magazine_cache_pop_magazine (guint ix,
|
|||||||
chunk->data = NULL;
|
chunk->data = NULL;
|
||||||
}
|
}
|
||||||
chunk->next = NULL;
|
chunk->next = NULL;
|
||||||
g_mutex_unlock (allocator->slab_mutex);
|
g_mutex_unlock (&allocator->slab_mutex);
|
||||||
*countp = i;
|
*countp = i;
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
@@ -699,7 +695,7 @@ magazine_cache_pop_magazine (guint ix,
|
|||||||
magazine_chain_next (prev) = next;
|
magazine_chain_next (prev) = next;
|
||||||
magazine_chain_prev (next) = prev;
|
magazine_chain_prev (next) = prev;
|
||||||
allocator->magazines[ix] = next == current ? NULL : next;
|
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 */
|
/* clear special fields and hand out */
|
||||||
*countp = (gsize) magazine_chain_count (current);
|
*countp = (gsize) magazine_chain_count (current);
|
||||||
magazine_chain_prev (current) = NULL;
|
magazine_chain_prev (current) = NULL;
|
||||||
@@ -731,13 +727,13 @@ private_thread_memory_cleanup (gpointer data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
const gsize chunk_size = SLAB_CHUNK_SIZE (allocator, ix);
|
||||||
g_mutex_lock (allocator->slab_mutex);
|
g_mutex_lock (&allocator->slab_mutex);
|
||||||
while (mag->chunks)
|
while (mag->chunks)
|
||||||
{
|
{
|
||||||
ChunkLink *chunk = magazine_chain_pop_head (&mag->chunks);
|
ChunkLink *chunk = magazine_chain_pop_head (&mag->chunks);
|
||||||
slab_allocator_free_chunk (chunk_size, chunk);
|
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 */
|
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);
|
mem = slab_allocator_alloc_chunk (chunk_size);
|
||||||
g_mutex_unlock (allocator->slab_mutex);
|
g_mutex_unlock (&allocator->slab_mutex);
|
||||||
}
|
}
|
||||||
else /* delegate to system malloc */
|
else /* delegate to system malloc */
|
||||||
mem = g_malloc (mem_size);
|
mem = g_malloc (mem_size);
|
||||||
@@ -896,9 +892,9 @@ g_slice_free1 (gsize mem_size,
|
|||||||
{
|
{
|
||||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||||
memset (mem_block, 0, chunk_size);
|
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);
|
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 /* 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 */
|
else if (acat == 2) /* allocate through slab allocator */
|
||||||
{
|
{
|
||||||
g_mutex_lock (allocator->slab_mutex);
|
g_mutex_lock (&allocator->slab_mutex);
|
||||||
while (slice)
|
while (slice)
|
||||||
{
|
{
|
||||||
guint8 *current = slice;
|
guint8 *current = slice;
|
||||||
@@ -968,7 +964,7 @@ g_slice_free_chain_with_offset (gsize mem_size,
|
|||||||
memset (current, 0, chunk_size);
|
memset (current, 0, chunk_size);
|
||||||
slab_allocator_free_chunk (chunk_size, current);
|
slab_allocator_free_chunk (chunk_size, current);
|
||||||
}
|
}
|
||||||
g_mutex_unlock (allocator->slab_mutex);
|
g_mutex_unlock (&allocator->slab_mutex);
|
||||||
}
|
}
|
||||||
else /* delegate to system malloc */
|
else /* delegate to system malloc */
|
||||||
while (slice)
|
while (slice)
|
||||||
@@ -1354,7 +1350,7 @@ smc_tree_insert (SmcKType key,
|
|||||||
unsigned int ix0, ix1;
|
unsigned int ix0, ix1;
|
||||||
SmcEntry *entry;
|
SmcEntry *entry;
|
||||||
|
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (&smc_tree_mutex);
|
||||||
ix0 = SMC_TRUNK_HASH (key);
|
ix0 = SMC_TRUNK_HASH (key);
|
||||||
ix1 = SMC_BRANCH_HASH (key);
|
ix1 = SMC_BRANCH_HASH (key);
|
||||||
if (!smc_tree_root)
|
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 = smc_tree_branch_grow_L (&smc_tree_root[ix0][ix1], entry - smc_tree_root[ix0][ix1].entries);
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
entry->value = value;
|
entry->value = value;
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (&smc_tree_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -1387,7 +1383,7 @@ smc_tree_lookup (SmcKType key,
|
|||||||
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
||||||
gboolean found_one = FALSE;
|
gboolean found_one = FALSE;
|
||||||
*value_p = 0;
|
*value_p = 0;
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (&smc_tree_mutex);
|
||||||
if (smc_tree_root && smc_tree_root[ix0])
|
if (smc_tree_root && smc_tree_root[ix0])
|
||||||
{
|
{
|
||||||
entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
|
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;
|
*value_p = entry->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (&smc_tree_mutex);
|
||||||
return found_one;
|
return found_one;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1408,7 +1404,7 @@ smc_tree_remove (SmcKType key)
|
|||||||
{
|
{
|
||||||
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
||||||
gboolean found_one = FALSE;
|
gboolean found_one = FALSE;
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (&smc_tree_mutex);
|
||||||
if (smc_tree_root && smc_tree_root[ix0])
|
if (smc_tree_root && smc_tree_root[ix0])
|
||||||
{
|
{
|
||||||
SmcEntry *entry = smc_tree_branch_lookup_nearest_L (&smc_tree_root[ix0][ix1], key);
|
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;
|
found_one = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (&smc_tree_mutex);
|
||||||
return found_one;
|
return found_one;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1436,7 +1432,7 @@ smc_tree_remove (SmcKType key)
|
|||||||
void
|
void
|
||||||
g_slice_debug_tree_statistics (void)
|
g_slice_debug_tree_statistics (void)
|
||||||
{
|
{
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (&smc_tree_mutex);
|
||||||
if (smc_tree_root)
|
if (smc_tree_root)
|
||||||
{
|
{
|
||||||
unsigned int i, j, t = 0, o = 0, b = 0, su = 0, ex = 0, en = 4294967295u;
|
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
|
else
|
||||||
fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
|
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):
|
/* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
|
||||||
* PID %CPU %MEM VSZ RSS COMMAND
|
* PID %CPU %MEM VSZ RSS COMMAND
|
||||||
|
@@ -873,7 +873,7 @@ static GThreadFunctions g_thread_functions_for_glib_use_old = {
|
|||||||
|
|
||||||
/* Local Data {{{1 -------------------------------------------------------- */
|
/* Local Data {{{1 -------------------------------------------------------- */
|
||||||
|
|
||||||
static GMutex *g_once_mutex = NULL;
|
static GMutex g_once_mutex = G_MUTEX_INIT;
|
||||||
static GCond *g_once_cond = NULL;
|
static GCond *g_once_cond = NULL;
|
||||||
static GPrivate *g_thread_specific_private = NULL;
|
static GPrivate *g_thread_specific_private = NULL;
|
||||||
static GRealThread *g_thread_all_threads = NULL;
|
static GRealThread *g_thread_all_threads = NULL;
|
||||||
@@ -940,7 +940,6 @@ g_thread_init_glib (void)
|
|||||||
GRealThread* main_thread = (GRealThread*) g_thread_self ();
|
GRealThread* main_thread = (GRealThread*) g_thread_self ();
|
||||||
|
|
||||||
/* mutex and cond creation works without g_threads_got_initialized */
|
/* mutex and cond creation works without g_threads_got_initialized */
|
||||||
g_once_mutex = g_mutex_new ();
|
|
||||||
g_once_cond = g_cond_new ();
|
g_once_cond = g_cond_new ();
|
||||||
|
|
||||||
/* we may only create mutex and cond in here */
|
/* we may only create mutex and cond in here */
|
||||||
@@ -1046,24 +1045,24 @@ g_once_impl (GOnce *once,
|
|||||||
GThreadFunc func,
|
GThreadFunc func,
|
||||||
gpointer arg)
|
gpointer arg)
|
||||||
{
|
{
|
||||||
g_mutex_lock (g_once_mutex);
|
g_mutex_lock (&g_once_mutex);
|
||||||
|
|
||||||
while (once->status == G_ONCE_STATUS_PROGRESS)
|
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)
|
if (once->status != G_ONCE_STATUS_READY)
|
||||||
{
|
{
|
||||||
once->status = G_ONCE_STATUS_PROGRESS;
|
once->status = G_ONCE_STATUS_PROGRESS;
|
||||||
g_mutex_unlock (g_once_mutex);
|
g_mutex_unlock (&g_once_mutex);
|
||||||
|
|
||||||
once->retval = func (arg);
|
once->retval = func (arg);
|
||||||
|
|
||||||
g_mutex_lock (g_once_mutex);
|
g_mutex_lock (&g_once_mutex);
|
||||||
once->status = G_ONCE_STATUS_READY;
|
once->status = G_ONCE_STATUS_READY;
|
||||||
g_cond_broadcast (g_once_cond);
|
g_cond_broadcast (g_once_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_unlock (g_once_mutex);
|
g_mutex_unlock (&g_once_mutex);
|
||||||
|
|
||||||
return once->retval;
|
return once->retval;
|
||||||
}
|
}
|
||||||
@@ -1106,7 +1105,7 @@ gboolean
|
|||||||
g_once_init_enter_impl (volatile gsize *value_location)
|
g_once_init_enter_impl (volatile gsize *value_location)
|
||||||
{
|
{
|
||||||
gboolean need_init = FALSE;
|
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_atomic_pointer_get (value_location) == NULL)
|
||||||
{
|
{
|
||||||
if (!g_slist_find (g_once_init_list, (void*) value_location))
|
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
|
else
|
||||||
do
|
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));
|
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;
|
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_return_if_fail (g_once_init_list != NULL);
|
||||||
|
|
||||||
g_atomic_pointer_set (value_location, initialization_value);
|
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_once_init_list = g_slist_remove (g_once_init_list, (void*) value_location);
|
||||||
g_cond_broadcast (g_once_cond);
|
g_cond_broadcast (g_once_cond);
|
||||||
g_mutex_unlock (g_once_mutex);
|
g_mutex_unlock (&g_once_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GStaticMutex {{{1 ------------------------------------------------------ */
|
/* GStaticMutex {{{1 ------------------------------------------------------ */
|
||||||
@@ -1279,9 +1278,7 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
|
|||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
g_assert (g_once_mutex);
|
g_mutex_lock (&g_once_mutex);
|
||||||
|
|
||||||
g_mutex_lock (g_once_mutex);
|
|
||||||
|
|
||||||
result = *mutex;
|
result = *mutex;
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -1290,7 +1287,7 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
|
|||||||
g_atomic_pointer_set (mutex, result);
|
g_atomic_pointer_set (mutex, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_unlock (g_once_mutex);
|
g_mutex_unlock (&g_once_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user