Skip to content

Commit

Permalink
Use static field initialization for system/session bus singletons. Fi…
Browse files Browse the repository at this point in the history
…x possible race resulting in double instantiation.
  • Loading branch information
garuma committed Sep 21, 2010
1 parent 43231e2 commit 055982a
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/Bus.cs
Expand Up @@ -10,40 +10,18 @@ namespace DBus
{
public sealed class Bus : Connection
{
static Bus systemBus = null;
static Bus systemBus = Address.StarterBusType == "system" ? Starter : Bus.Open (Address.System);
public static Bus System
{
get {
if (systemBus == null) {
try {
if (Address.StarterBusType == "system")
systemBus = Starter;
else
systemBus = Bus.Open (Address.System);
} catch (Exception e) {
throw new Exception ("Unable to open the system message bus.", e);
}
}

return systemBus;
}
}

static Bus sessionBus = null;
static Bus sessionBus = Address.StarterBusType == "session" ? Starter : Bus.Open (Address.Session);
public static Bus Session
{
get {
if (sessionBus == null) {
try {
if (Address.StarterBusType == "session")
sessionBus = Starter;
else
sessionBus = Bus.Open (Address.Session);
} catch (Exception e) {
throw new Exception ("Unable to open the session message bus.", e);
}
}

return sessionBus;
}
}
Expand Down

0 comments on commit 055982a

Please sign in to comment.