mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-16 12:45:13 +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;
|
gpointer data;
|
||||||
GDestroyNotify notify;
|
GDestroyNotify notify;
|
||||||
|
|
||||||
GMutex *ack_lock;
|
GMutex ack_lock;
|
||||||
GCond *ack_condition;
|
GCond ack_condition;
|
||||||
} MainLoopProxy;
|
} MainLoopProxy;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -290,12 +290,9 @@ mainloop_proxy_func (gpointer data)
|
|||||||
if (proxy->notify)
|
if (proxy->notify)
|
||||||
proxy->notify (proxy->data);
|
proxy->notify (proxy->data);
|
||||||
|
|
||||||
if (proxy->ack_lock)
|
g_mutex_lock (&proxy->ack_lock);
|
||||||
{
|
g_cond_signal (&proxy->ack_condition);
|
||||||
g_mutex_lock (proxy->ack_lock);
|
g_mutex_unlock (&proxy->ack_lock);
|
||||||
g_cond_signal (proxy->ack_condition);
|
|
||||||
g_mutex_unlock (proxy->ack_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -303,12 +300,8 @@ mainloop_proxy_func (gpointer data)
|
|||||||
static void
|
static void
|
||||||
mainloop_proxy_free (MainLoopProxy *proxy)
|
mainloop_proxy_free (MainLoopProxy *proxy)
|
||||||
{
|
{
|
||||||
if (proxy->ack_lock)
|
g_mutex_clear (&proxy->ack_lock);
|
||||||
{
|
g_cond_clear (&proxy->ack_condition);
|
||||||
g_mutex_free (proxy->ack_lock);
|
|
||||||
g_cond_free (proxy->ack_condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (proxy);
|
g_free (proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,9 +335,9 @@ g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
|
|||||||
proxy->func = func;
|
proxy->func = func;
|
||||||
proxy->data = user_data;
|
proxy->data = user_data;
|
||||||
proxy->notify = notify;
|
proxy->notify = notify;
|
||||||
proxy->ack_lock = g_mutex_new ();
|
g_mutex_init (&proxy->ack_lock);
|
||||||
proxy->ack_condition = g_cond_new ();
|
g_cond_init (&proxy->ack_condition);
|
||||||
g_mutex_lock (proxy->ack_lock);
|
g_mutex_lock (&proxy->ack_lock);
|
||||||
|
|
||||||
source = g_idle_source_new ();
|
source = g_idle_source_new ();
|
||||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
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_attach (source, job->context);
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
|
|
||||||
g_cond_wait (proxy->ack_condition, proxy->ack_lock);
|
g_cond_wait (&proxy->ack_condition, &proxy->ack_lock);
|
||||||
g_mutex_unlock (proxy->ack_lock);
|
g_mutex_unlock (&proxy->ack_lock);
|
||||||
|
|
||||||
ret_val = proxy->ret_val;
|
ret_val = proxy->ret_val;
|
||||||
mainloop_proxy_free (proxy);
|
mainloop_proxy_free (proxy);
|
||||||
@ -396,6 +389,8 @@ g_io_scheduler_job_send_to_mainloop_async (GIOSchedulerJob *job,
|
|||||||
proxy->func = func;
|
proxy->func = func;
|
||||||
proxy->data = user_data;
|
proxy->data = user_data;
|
||||||
proxy->notify = notify;
|
proxy->notify = notify;
|
||||||
|
g_mutex_init (&proxy->ack_lock);
|
||||||
|
g_cond_init (&proxy->ack_condition);
|
||||||
|
|
||||||
source = g_idle_source_new ();
|
source = g_idle_source_new ();
|
||||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
||||||
|
@ -106,7 +106,7 @@ struct _GTlsInteractionPrivate {
|
|||||||
G_DEFINE_TYPE (GTlsInteraction, g_tls_interaction, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (GTlsInteraction, g_tls_interaction, G_TYPE_OBJECT);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GMutex *mutex;
|
GMutex mutex;
|
||||||
|
|
||||||
/* Input arguments */
|
/* Input arguments */
|
||||||
GTlsInteraction *interaction;
|
GTlsInteraction *interaction;
|
||||||
@ -121,7 +121,7 @@ typedef struct {
|
|||||||
GTlsInteractionResult result;
|
GTlsInteractionResult result;
|
||||||
GError *error;
|
GError *error;
|
||||||
gboolean complete;
|
gboolean complete;
|
||||||
GCond *cond;
|
GCond cond;
|
||||||
} InvokeClosure;
|
} InvokeClosure;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -132,8 +132,8 @@ invoke_closure_free (gpointer data)
|
|||||||
g_object_unref (closure->interaction);
|
g_object_unref (closure->interaction);
|
||||||
g_clear_object (&closure->argument);
|
g_clear_object (&closure->argument);
|
||||||
g_clear_object (&closure->cancellable);
|
g_clear_object (&closure->cancellable);
|
||||||
g_cond_free (closure->cond);
|
g_cond_clear (&closure->cond);
|
||||||
g_mutex_free (closure->mutex);
|
g_mutex_clear (&closure->mutex);
|
||||||
g_clear_error (&closure->error);
|
g_clear_error (&closure->error);
|
||||||
|
|
||||||
/* Insurance that we've actually used these before freeing */
|
/* 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->interaction = g_object_ref (interaction);
|
||||||
closure->argument = argument ? g_object_ref (argument) : NULL;
|
closure->argument = argument ? g_object_ref (argument) : NULL;
|
||||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||||
closure->mutex = g_mutex_new ();
|
g_mutex_init (&closure->mutex);
|
||||||
closure->cond = g_cond_new ();
|
g_cond_init (&closure->cond);
|
||||||
closure->result = G_TLS_INTERACTION_UNHANDLED;
|
closure->result = G_TLS_INTERACTION_UNHANDLED;
|
||||||
return closure;
|
return closure;
|
||||||
}
|
}
|
||||||
@ -164,12 +164,12 @@ invoke_closure_wait_and_free (InvokeClosure *closure,
|
|||||||
{
|
{
|
||||||
GTlsInteractionResult result;
|
GTlsInteractionResult result;
|
||||||
|
|
||||||
g_mutex_lock (closure->mutex);
|
g_mutex_lock (&closure->mutex);
|
||||||
|
|
||||||
while (!closure->complete)
|
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)
|
if (closure->error)
|
||||||
{
|
{
|
||||||
@ -219,7 +219,7 @@ on_invoke_ask_password_sync (gpointer user_data)
|
|||||||
InvokeClosure *closure = user_data;
|
InvokeClosure *closure = user_data;
|
||||||
GTlsInteractionClass *klass;
|
GTlsInteractionClass *klass;
|
||||||
|
|
||||||
g_mutex_lock (closure->mutex);
|
g_mutex_lock (&closure->mutex);
|
||||||
|
|
||||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||||
g_assert (klass->ask_password);
|
g_assert (klass->ask_password);
|
||||||
@ -230,8 +230,8 @@ on_invoke_ask_password_sync (gpointer user_data)
|
|||||||
&closure->error);
|
&closure->error);
|
||||||
|
|
||||||
closure->complete = TRUE;
|
closure->complete = TRUE;
|
||||||
g_cond_signal (closure->cond);
|
g_cond_signal (&closure->cond);
|
||||||
g_mutex_unlock (closure->mutex);
|
g_mutex_unlock (&closure->mutex);
|
||||||
|
|
||||||
return FALSE; /* don't call again */
|
return FALSE; /* don't call again */
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ on_async_as_sync_complete (GObject *source,
|
|||||||
InvokeClosure *closure = user_data;
|
InvokeClosure *closure = user_data;
|
||||||
GTlsInteractionClass *klass;
|
GTlsInteractionClass *klass;
|
||||||
|
|
||||||
g_mutex_lock (closure->mutex);
|
g_mutex_lock (&closure->mutex);
|
||||||
|
|
||||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||||
g_assert (klass->ask_password_finish);
|
g_assert (klass->ask_password_finish);
|
||||||
@ -254,8 +254,8 @@ on_async_as_sync_complete (GObject *source,
|
|||||||
&closure->error);
|
&closure->error);
|
||||||
|
|
||||||
closure->complete = TRUE;
|
closure->complete = TRUE;
|
||||||
g_cond_signal (closure->cond);
|
g_cond_signal (&closure->cond);
|
||||||
g_mutex_unlock (closure->mutex);
|
g_mutex_unlock (&closure->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -264,7 +264,7 @@ on_invoke_ask_password_async_as_sync (gpointer user_data)
|
|||||||
InvokeClosure *closure = user_data;
|
InvokeClosure *closure = user_data;
|
||||||
GTlsInteractionClass *klass;
|
GTlsInteractionClass *klass;
|
||||||
|
|
||||||
g_mutex_lock (closure->mutex);
|
g_mutex_lock (&closure->mutex);
|
||||||
|
|
||||||
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
klass = G_TLS_INTERACTION_GET_CLASS (closure->interaction);
|
||||||
g_assert (klass->ask_password_async);
|
g_assert (klass->ask_password_async);
|
||||||
@ -279,7 +279,7 @@ on_invoke_ask_password_async_as_sync (gpointer user_data)
|
|||||||
closure->callback = NULL;
|
closure->callback = NULL;
|
||||||
closure->user_data = NULL;
|
closure->user_data = NULL;
|
||||||
|
|
||||||
g_mutex_unlock (closure->mutex);
|
g_mutex_unlock (&closure->mutex);
|
||||||
|
|
||||||
return FALSE; /* don't call again */
|
return FALSE; /* don't call again */
|
||||||
}
|
}
|
||||||
@ -353,9 +353,9 @@ g_tls_interaction_invoke_ask_password (GTlsInteraction *interaction,
|
|||||||
{
|
{
|
||||||
while (!closure->complete)
|
while (!closure->complete)
|
||||||
{
|
{
|
||||||
g_mutex_unlock (closure->mutex);
|
g_mutex_unlock (&closure->mutex);
|
||||||
g_main_context_iteration (interaction->priv->context, TRUE);
|
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);
|
g_main_context_release (interaction->priv->context);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user