mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-15 20:25:12 +01:00
GIO: switch a couple more GMutex users to _init()
Move a couple more GIO users off of _new()/_free() to _init()/_clear(). https://bugzilla.gnome.org/show_bug.cgi?id=660739
This commit is contained in:
parent
e517fb6cb0
commit
c474cd71ba
@ -276,8 +276,8 @@ typedef struct {
|
||||
gpointer data;
|
||||
GDestroyNotify notify;
|
||||
|
||||
GMutex *ack_lock;
|
||||
GCond *ack_condition;
|
||||
GMutex ack_lock;
|
||||
GCond ack_condition;
|
||||
} MainLoopProxy;
|
||||
|
||||
static gboolean
|
||||
@ -290,12 +290,9 @@ mainloop_proxy_func (gpointer data)
|
||||
if (proxy->notify)
|
||||
proxy->notify (proxy->data);
|
||||
|
||||
if (proxy->ack_lock)
|
||||
{
|
||||
g_mutex_lock (proxy->ack_lock);
|
||||
g_cond_signal (proxy->ack_condition);
|
||||
g_mutex_unlock (proxy->ack_lock);
|
||||
}
|
||||
g_mutex_lock (&proxy->ack_lock);
|
||||
g_cond_signal (&proxy->ack_condition);
|
||||
g_mutex_unlock (&proxy->ack_lock);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -303,12 +300,8 @@ mainloop_proxy_func (gpointer data)
|
||||
static void
|
||||
mainloop_proxy_free (MainLoopProxy *proxy)
|
||||
{
|
||||
if (proxy->ack_lock)
|
||||
{
|
||||
g_mutex_free (proxy->ack_lock);
|
||||
g_cond_free (proxy->ack_condition);
|
||||
}
|
||||
|
||||
g_mutex_clear (&proxy->ack_lock);
|
||||
g_cond_clear (&proxy->ack_condition);
|
||||
g_free (proxy);
|
||||
}
|
||||
|
||||
@ -342,9 +335,9 @@ g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
|
||||
proxy->func = func;
|
||||
proxy->data = user_data;
|
||||
proxy->notify = notify;
|
||||
proxy->ack_lock = g_mutex_new ();
|
||||
proxy->ack_condition = g_cond_new ();
|
||||
g_mutex_lock (proxy->ack_lock);
|
||||
g_mutex_init (&proxy->ack_lock);
|
||||
g_cond_init (&proxy->ack_condition);
|
||||
g_mutex_lock (&proxy->ack_lock);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
||||
@ -354,8 +347,8 @@ g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
|
||||
g_source_attach (source, job->context);
|
||||
g_source_unref (source);
|
||||
|
||||
g_cond_wait (proxy->ack_condition, proxy->ack_lock);
|
||||
g_mutex_unlock (proxy->ack_lock);
|
||||
g_cond_wait (&proxy->ack_condition, &proxy->ack_lock);
|
||||
g_mutex_unlock (&proxy->ack_lock);
|
||||
|
||||
ret_val = proxy->ret_val;
|
||||
mainloop_proxy_free (proxy);
|
||||
@ -396,6 +389,8 @@ g_io_scheduler_job_send_to_mainloop_async (GIOSchedulerJob *job,
|
||||
proxy->func = func;
|
||||
proxy->data = user_data;
|
||||
proxy->notify = notify;
|
||||
g_mutex_init (&proxy->ack_lock);
|
||||
g_cond_init (&proxy->ack_condition);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
||||
|
@ -106,7 +106,7 @@ struct _GTlsInteractionPrivate {
|
||||
G_DEFINE_TYPE (GTlsInteraction, g_tls_interaction, G_TYPE_OBJECT);
|
||||
|
||||
typedef struct {
|
||||
GMutex *mutex;
|
||||
GMutex mutex;
|
||||
|
||||
/* Input arguments */
|
||||
GTlsInteraction *interaction;
|
||||
@ -121,7 +121,7 @@ typedef struct {
|
||||
GTlsInteractionResult result;
|
||||
GError *error;
|
||||
gboolean complete;
|
||||
GCond *cond;
|
||||
GCond cond;
|
||||
} InvokeClosure;
|
||||
|
||||
static void
|
||||
@ -132,8 +132,8 @@ invoke_closure_free (gpointer data)
|
||||
g_object_unref (closure->interaction);
|
||||
g_clear_object (&closure->argument);
|
||||
g_clear_object (&closure->cancellable);
|
||||
g_cond_free (closure->cond);
|
||||
g_mutex_free (closure->mutex);
|
||||
g_cond_clear (&closure->cond);
|
||||
g_mutex_clear (&closure->mutex);
|
||||
g_clear_error (&closure->error);
|
||||
|
||||
/* Insurance that we've actually used these before freeing */
|
||||
@ -152,8 +152,8 @@ invoke_closure_new (GTlsInteraction *interaction,
|
||||
closure->interaction = g_object_ref (interaction);
|
||||
closure->argument = argument ? g_object_ref (argument) : NULL;
|
||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||
closure->mutex = g_mutex_new ();
|
||||
closure->cond = g_cond_new ();
|
||||
g_mutex_init (&closure->mutex);
|
||||
g_cond_init (&closure->cond);
|
||||
closure->result = G_TLS_INTERACTION_UNHANDLED;
|
||||
return closure;
|
||||
}
|
||||
@ -164,12 +164,12 @@ invoke_closure_wait_and_free (InvokeClosure *closure,
|
||||
{
|
||||
GTlsInteractionResult result;
|
||||
|
||||
g_mutex_lock (closure->mutex);
|
||||
g_mutex_lock (&closure->mutex);
|
||||
|
||||
while (!closure->complete)
|
||||
g_cond_wait (closure->cond, closure->mutex);
|
||||
g_cond_wait (&closure->cond, &closure->mutex);
|
||||
|
||||
g_mutex_unlock (closure->mutex);
|
||||
g_mutex_unlock (&closure->mutex);
|
||||
|
||||
if (closure->error)
|
||||
{
|
||||
@ -219,7 +219,7 @@ on_invoke_ask_password_sync (gpointer user_data)
|
||||
InvokeClosure *closure = user_data;
|
||||
GTlsInteractionClass *klass;
|
||||
|
||||
g_mutex_lock (closure->mutex);
|
||||
g_mutex_lock (&closure->mutex);
|
||||
|
||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||
g_assert (klass->ask_password);
|
||||
@ -230,8 +230,8 @@ on_invoke_ask_password_sync (gpointer user_data)
|
||||
&closure->error);
|
||||
|
||||
closure->complete = TRUE;
|
||||
g_cond_signal (closure->cond);
|
||||
g_mutex_unlock (closure->mutex);
|
||||
g_cond_signal (&closure->cond);
|
||||
g_mutex_unlock (&closure->mutex);
|
||||
|
||||
return FALSE; /* don't call again */
|
||||
}
|
||||
@ -244,7 +244,7 @@ on_async_as_sync_complete (GObject *source,
|
||||
InvokeClosure *closure = user_data;
|
||||
GTlsInteractionClass *klass;
|
||||
|
||||
g_mutex_lock (closure->mutex);
|
||||
g_mutex_lock (&closure->mutex);
|
||||
|
||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||
g_assert (klass->ask_password_finish);
|
||||
@ -254,8 +254,8 @@ on_async_as_sync_complete (GObject *source,
|
||||
&closure->error);
|
||||
|
||||
closure->complete = TRUE;
|
||||
g_cond_signal (closure->cond);
|
||||
g_mutex_unlock (closure->mutex);
|
||||
g_cond_signal (&closure->cond);
|
||||
g_mutex_unlock (&closure->mutex);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -264,7 +264,7 @@ on_invoke_ask_password_async_as_sync (gpointer user_data)
|
||||
InvokeClosure *closure = user_data;
|
||||
GTlsInteractionClass *klass;
|
||||
|
||||
g_mutex_lock (closure->mutex);
|
||||
g_mutex_lock (&closure->mutex);
|
||||
|
||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||
g_assert (klass->ask_password_async);
|
||||
@ -279,7 +279,7 @@ on_invoke_ask_password_async_as_sync (gpointer user_data)
|
||||
closure->callback = NULL;
|
||||
closure->user_data = NULL;
|
||||
|
||||
g_mutex_unlock (closure->mutex);
|
||||
g_mutex_unlock (&closure->mutex);
|
||||
|
||||
return FALSE; /* don't call again */
|
||||
}
|
||||
@ -353,9 +353,9 @@ g_tls_interaction_invoke_ask_password (GTlsInteraction *interaction,
|
||||
{
|
||||
while (!closure->complete)
|
||||
{
|
||||
g_mutex_unlock (closure->mutex);
|
||||
g_mutex_unlock (&closure->mutex);
|
||||
g_main_context_iteration (interaction->priv->context, TRUE);
|
||||
g_mutex_lock (closure->mutex);
|
||||
g_mutex_lock (&closure->mutex);
|
||||
}
|
||||
g_main_context_release (interaction->priv->context);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user