summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2012-07-10 13:58:03 -0400
committerRyan Lortie <desrt@desrt.ca>2012-07-10 13:58:03 -0400
commit4860be9319e971da6a21fe9f0e83a86b2581314e (patch)
tree9fcc99e56072ae39005814f35b5c5babc44f7659 /engine
parent2f86e0288643ec2024bc8f32a5c287b88e82d7ab (diff)
downloaddconf-4860be9319e971da6a21fe9f0e83a86b2581314e.tar.gz
Reimplement sync() functionality
Add dconf_engine_sync() that does the same thing as the code in the GSettings backend used to do, in a cleaner way. Update the GSettings backend to use the new call. Add a new call to DConfClient wrapping the engine call as well.
Diffstat (limited to 'engine')
-rw-r--r--engine/dconf-engine.c39
-rw-r--r--engine/dconf-engine.h4
2 files changed, 42 insertions, 1 deletions
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index c1410b6..8d9837a 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -161,7 +161,8 @@ struct _DConfEngine
DConfEngineSource **sources; /* Array never changes, but each source changes internally. */
gint n_sources;
- GMutex queue_lock; /* This lock is for pending, in_flight */
+ GMutex queue_lock; /* This lock is for pending, in_flight, queue_cond */
+ GCond queue_cond; /* Signalled when the queues empty */
GQueue pending; /* DConfChangeset */
GQueue in_flight; /* DConfChangeset */
@@ -233,6 +234,7 @@ dconf_engine_new (gpointer user_data,
g_mutex_init (&engine->sources_lock);
g_mutex_init (&engine->queue_lock);
+ g_cond_init (&engine->queue_cond);
engine->sources = dconf_engine_profile_open (NULL, &engine->n_sources);
@@ -279,6 +281,7 @@ dconf_engine_unref (DConfEngine *engine)
g_mutex_clear (&engine->sources_lock);
g_mutex_clear (&engine->queue_lock);
+ g_cond_clear (&engine->queue_cond);
g_free (engine->last_handled);
@@ -948,6 +951,16 @@ dconf_engine_manage_queue (DConfEngine *engine)
g_queue_push_tail (&engine->in_flight, oc->change);
}
+
+ if (g_queue_is_empty (&engine->in_flight))
+ {
+ /* The in-flight queue should not be empty if we have changes
+ * pending...
+ */
+ g_assert (g_queue_is_empty (&engine->pending));
+
+ g_cond_broadcast (&engine->queue_cond);
+ }
}
static gboolean
@@ -1123,3 +1136,27 @@ dconf_engine_handle_dbus_signal (GBusType type,
g_warning ("Need to handle writability changes"); /* XXX */
}
}
+
+gboolean
+dconf_engine_has_outstanding (DConfEngine *engine)
+{
+ gboolean has;
+
+ /* The in-flight queue will never be empty unless the pending queue is
+ * also empty, so we only really need to check one of them...
+ */
+ dconf_engine_lock_queues (engine);
+ has = !g_queue_is_empty (&engine->in_flight);
+ dconf_engine_unlock_queues (engine);
+
+ return has;
+}
+
+void
+dconf_engine_sync (DConfEngine *engine)
+{
+ dconf_engine_lock_queues (engine);
+ while (!g_queue_is_empty (&engine->in_flight))
+ g_cond_wait (&engine->queue_cond, &engine->queue_lock);
+ dconf_engine_unlock_queues (engine);
+}
diff --git a/engine/dconf-engine.h b/engine/dconf-engine.h
index bad8cf1..96ac42b 100644
--- a/engine/dconf-engine.h
+++ b/engine/dconf-engine.h
@@ -152,6 +152,10 @@ gboolean dconf_engine_change_sync (DConfEn
DConfChangeset *changeset,
gchar **tag,
GError **error);
+G_GNUC_INTERNAL
+gboolean dconf_engine_has_outstanding (DConfEngine *engine);
+G_GNUC_INTERNAL
+void dconf_engine_sync (DConfEngine *engine);
/* Asynchronous API: not implemented yet (and maybe never?) */