[glib] GSettingSchemaSource: add refcounting
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GSettingSchemaSource: add refcounting
- Date: Thu, 17 Nov 2011 14:05:10 +0000 (UTC)
commit bf5626ddc20f973baf92edfc3c888ef77e9de1db
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Nov 15 07:31:20 2011 +0000
GSettingSchemaSource: add refcounting
gio/gsettingsschema.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index 3d47bd7..ad52a86 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -46,6 +46,8 @@ struct _GSettingsSchemaSource
{
GSettingsSchemaSource *parent;
GvdbTable *table;
+
+ gint ref_count;
};
static GSettingsSchemaSource *schema_sources;
@@ -55,13 +57,38 @@ prepend_schema_table (GvdbTable *table)
{
GSettingsSchemaSource *source;
+ /* we steal the reference from 'schema_sources' for our ->parent */
source = g_slice_new (GSettingsSchemaSource);
source->parent = schema_sources;
source->table = table;
+ source->ref_count = 1;
schema_sources = source;
}
+GSettingsSchemaSource *
+g_settings_schema_source_ref (GSettingsSchemaSource *source)
+{
+ g_atomic_int_inc (&source->ref_count);
+
+ return source;
+}
+
+void
+g_settings_schema_source_unref (GSettingsSchemaSource *source)
+{
+ if (g_atomic_int_dec_and_test (&source->ref_count))
+ {
+ if (source == schema_sources)
+ g_error ("g_settings_schema_source_unref() called too many times on the default schema source");
+
+ g_settings_schema_source_unref (source->parent);
+ gvdb_table_unref (source->table);
+
+ g_slice_free (GSettingsSchemaSource, source);
+ }
+}
+
static void
initialise_schema_sources (void)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]