diff options
author | Ryan Lortie <desrt@desrt.ca> | 2012-07-02 23:34:43 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2012-07-02 23:34:43 -0400 |
commit | cc3221d143889375683a63ed888d984fe8aabe9a (patch) | |
tree | 70b6ed4fa7088a1061d3b4348dbc79772df1d451 /gsettings | |
parent | 4eea8cb823c5a113d8209b04102f17f08df853d6 (diff) | |
download | dconf-cc3221d143889375683a63ed888d984fe8aabe9a.tar.gz |
Implement change signals
Support receiving and properly exposing change notifications.
This required some changes to improve the thread-safety of destroying a
DConfEngine.
It is possible that a signal would be arriving (in the worker thread) at
the exact instant that a DConfEngine was being destroyed (from the
finalize of the DConfClient or DConfSettingsBackend). This could lead
to the object being accessed after it was finalized.
We can avoid this by using weak references and by being more careful
about when the DConfEngine is freed (by taking a ref to it in the signal
handler and releasing it when done).
Diffstat (limited to 'gsettings')
-rw-r--r-- | gsettings/dconfsettingsbackend.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/gsettings/dconfsettingsbackend.c b/gsettings/dconfsettingsbackend.c index 85aef4e..53a982c 100644 --- a/gsettings/dconfsettingsbackend.c +++ b/gsettings/dconfsettingsbackend.c @@ -141,9 +141,22 @@ dconf_settings_backend_sync (GSettingsBackend *backend) } static void +dconf_settings_backend_free_weak_ref (gpointer data) +{ + GWeakRef *weak_ref = data; + + g_weak_ref_clear (weak_ref); + g_slice_free (GWeakRef, weak_ref); +} + +static void dconf_settings_backend_init (DConfSettingsBackend *dcsb) { - dcsb->engine = dconf_engine_new (dcsb); + GWeakRef *weak_ref; + + weak_ref = g_slice_new (GWeakRef); + g_weak_ref_init (weak_ref, dcsb); + dcsb->engine = dconf_engine_new (weak_ref, dconf_settings_backend_free_weak_ref); } static void @@ -151,7 +164,7 @@ dconf_settings_backend_finalize (GObject *object) { DConfSettingsBackend *dcsb = (DConfSettingsBackend *) object; - dconf_engine_free (dcsb->engine); + dconf_engine_unref (dcsb->engine); G_OBJECT_CLASS (dconf_settings_backend_parent_class) ->finalize (object); @@ -202,4 +215,24 @@ dconf_engine_change_notify (DConfEngine *engine, const gchar *tag, gpointer user_data) { + GWeakRef *weak_ref = user_data; + DConfSettingsBackend *dcsb; + + dcsb = g_weak_ref_get (weak_ref); + + if (dcsb == NULL) + return; + + if (changes[0] == NULL) + return; + + if (changes[1] == NULL) + { + if (g_str_has_suffix (prefix, "/")) + g_settings_backend_path_changed (G_SETTINGS_BACKEND (dcsb), prefix, NULL); + else + g_settings_backend_changed (G_SETTINGS_BACKEND (dcsb), prefix, NULL); + } + else + g_settings_backend_keys_changed (G_SETTINGS_BACKEND (dcsb), prefix, changes, NULL); } |