Skip to content

Commit 0768969

Browse files
committed
Use GLib.Once for singletons
1 parent e3e1ede commit 0768969

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/Background/BackgroundCache.vala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@
55
*/
66

77
public class Gala.BackgroundCache : Object {
8-
private static BackgroundCache? instance = null;
9-
8+
private static GLib.Once<BackgroundCache> instance;
109
public static unowned BackgroundCache get_default () {
11-
if (instance == null)
12-
instance = new BackgroundCache ();
13-
14-
return instance;
10+
return instance.once (() => { return new BackgroundCache (); });
1511
}
1612

1713
public signal void file_changed (string filename);
1814

1915
private Gee.HashMap<string,FileMonitor> file_monitors;
2016
private BackgroundSource background_source;
21-
2217
private Animation animation;
2318

24-
public BackgroundCache () {
25-
Object ();
26-
}
27-
2819
construct {
2920
file_monitors = new Gee.HashMap<string,FileMonitor> ();
3021
}

src/PluginManager.vala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
*/
66

77
public class Gala.PluginManager : Object {
8-
private static PluginManager? instance = null;
8+
private static GLib.Once<PluginManager> instance;
99
public static unowned PluginManager get_default () {
10-
if (instance == null)
11-
instance = new PluginManager ();
12-
13-
return instance;
10+
return instance.once (() => { return new PluginManager (); });
1411
}
1512

1613
public delegate PluginInfo RegisterPluginFunction ();

0 commit comments

Comments
 (0)