[glib] GIO: switch a couple more GMutex users to _init()
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GIO: switch a couple more GMutex users to _init()
- Date: Tue, 4 Oct 2011 15:59:32 +0000 (UTC)
commit c474cd71ba3fe205865966c4a1467916597d43c4
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Oct 3 23:44:37 2011 -0400
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
gio/gioscheduler.c | 41 ++++++++++++++++++-----------------------
gio/gtlsinteraction.c | 38 +++++++++++++++++++-------------------
2 files changed, 37 insertions(+), 42 deletions(-)
---
diff --git a/gio/gioscheduler.c b/gio/gioscheduler.c
index 960f62c..9f83977 100644
--- a/gio/gioscheduler.c
+++ b/gio/gioscheduler.c
@@ -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
@@ -289,26 +289,19 @@ 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;
}
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,10 +335,10 @@ 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);
g_source_set_callback (source, mainloop_proxy_func, proxy,
@@ -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,7 +389,9 @@ 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);
g_source_set_callback (source, mainloop_proxy_func, proxy,
diff --git a/gio/gtlsinteraction.c b/gio/gtlsinteraction.c
index 28c3f11..6ad4127 100644
--- a/gio/gtlsinteraction.c
+++ b/gio/gtlsinteraction.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]