[glib] GDummyTlsBackend: cache the GDummyTlsDatabase



commit f79e39154d4028dac1366e813aba0cabdd48c9c2
Author: Dan Winship <danw gnome org>
Date:   Sun Nov 17 09:45:20 2013 -0500

    GDummyTlsBackend: cache the GDummyTlsDatabase
    
    The default GTlsDatabase is supposed to be a singleton (and libsoup
    has tests that will fail if it's not).

 gio/gdummytlsbackend.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/gio/gdummytlsbackend.c b/gio/gdummytlsbackend.c
index 5a2463b..535942f 100644
--- a/gio/gdummytlsbackend.c
+++ b/gio/gdummytlsbackend.c
@@ -62,19 +62,42 @@ G_DEFINE_TYPE_WITH_CODE (GDummyTlsBackend, g_dummy_tls_backend, G_TYPE_OBJECT,
                                                         -100))
 
 static void
-g_dummy_tls_backend_init (GDummyTlsBackend *backend)
+g_dummy_tls_backend_init (GDummyTlsBackend *dummy)
 {
 }
 
 static void
+g_dummy_tls_backend_finalize (GObject *object)
+{
+  GDummyTlsBackend *dummy = G_DUMMY_TLS_BACKEND (object);
+
+  g_clear_object (&dummy->database);
+
+  G_OBJECT_CLASS (g_dummy_tls_backend_parent_class)->finalize (object);
+}
+
+static void
 g_dummy_tls_backend_class_init (GDummyTlsBackendClass *backend_class)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (backend_class);
+
+  object_class->finalize = g_dummy_tls_backend_finalize;
 }
 
-static GTlsDatabase*
+static GTlsDatabase *
 g_dummy_tls_backend_get_default_database (GTlsBackend *backend)
 {
-  return g_object_new (_g_dummy_tls_database_get_type (), NULL);
+  GDummyTlsBackend *dummy = G_DUMMY_TLS_BACKEND (backend);
+
+  if (g_once_init_enter (&dummy->database))
+    {
+      GTlsDatabase *tlsdb;
+
+      tlsdb = g_object_new (_g_dummy_tls_database_get_type (), NULL);
+      g_once_init_leave (&dummy->database, tlsdb);
+    }
+
+  return g_object_ref (dummy->database);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]