From e2df6975f9e80044d186af2c64fb98ca32096dc9 Mon Sep 17 00:00:00 2001 From: Till Lorentzen Date: Thu, 28 May 2015 10:10:10 +0200 Subject: [PATCH] Used gendarme DoubleCheckLockingRule to avoid singleton problems --- src/Global.cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Global.cs b/src/Global.cs index a0f80ed..dd33299 100644 --- a/src/Global.cs +++ b/src/Global.cs @@ -61,22 +61,25 @@ public static class Global { private const string interface_name = "org.freedesktop.Notifications"; private const string object_path = "/org/freedesktop/Notifications"; - private static INotifications dbus_object = null; + private static volatile INotifications dbus_object = null; private static object dbus_object_lock = new object (); internal static INotifications DBusObject { get { - if (dbus_object != null) - return dbus_object; + if (dbus_object == null) { + lock (dbus_object_lock) { + if (dbus_object == null) { + if (! Bus.Session.NameHasOwner (interface_name)) { + Bus.Session.StartServiceByName (interface_name); + } - lock (dbus_object_lock) { - if (! Bus.Session.NameHasOwner (interface_name)) - Bus.Session.StartServiceByName (interface_name); - - dbus_object = Bus.Session.GetObject - (interface_name, new ObjectPath (object_path)); - return dbus_object; + dbus_object = Bus.Session.GetObject + (interface_name, new ObjectPath (object_path)); + } + } } + + return dbus_object; } } @@ -85,7 +88,7 @@ public static string[] Capabilities { return DBusObject.Capabilities; } } - + public static ServerInformation ServerInformation { get { return DBusObject.ServerInformation;