[gnome-builder] upower: cleanup system bus connection when context is released
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] upower: cleanup system bus connection when context is released
- Date: Mon, 27 Apr 2015 22:27:29 +0000 (UTC)
commit 55a79968dfd562e969a307e465f9049a77d8cee1
Author: Christian Hergert <christian hergert me>
Date: Mon Apr 27 15:23:39 2015 -0700
upower: cleanup system bus connection when context is released
This helps ensure that we release the upower connection when we close
our last context. Otherwise, we can get into a state where exit-on-close
will kill our process.
When that happens, we fail to save all of our file state, which is very
much a bad thing.
libide/ide-battery-monitor.c | 29 +++++++++++++++++++++++++++++
libide/ide-context.c | 4 ++++
libide/ide-internal.h | 2 ++
3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-battery-monitor.c b/libide/ide-battery-monitor.c
index 243403e..7d702ce 100644
--- a/libide/ide-battery-monitor.c
+++ b/libide/ide-battery-monitor.c
@@ -24,6 +24,7 @@
static GDBusProxy *gUPowerProxy;
static GDBusProxy *gUPowerDeviceProxy;
+static gint gUPowerHold;
G_LOCK_DEFINE_STATIC (proxy_lock);
@@ -152,3 +153,31 @@ ide_battery_monitor_get_should_conserve (void)
return should_conserve;
}
+
+void
+_ide_battery_monitor_shutdown (void)
+{
+ G_LOCK (proxy_lock);
+
+ if (--gUPowerHold == 0)
+ {
+ g_clear_object (&gUPowerProxy);
+ g_clear_object (&gUPowerDeviceProxy);
+ }
+
+ G_UNLOCK (proxy_lock);
+}
+
+void
+_ide_battery_monitor_init (void)
+{
+ g_autoptr(GDBusProxy) proxy = NULL;
+ g_autoptr(GDBusProxy) device_proxy = NULL;
+
+ G_LOCK (proxy_lock);
+ gUPowerHold++;
+ G_UNLOCK (proxy_lock);
+
+ proxy = ide_battery_monitor_get_proxy ();
+ device_proxy = ide_battery_monitor_get_device_proxy ();
+}
diff --git a/libide/ide-context.c b/libide/ide-context.c
index 31e2583..c81b445 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -542,6 +542,8 @@ ide_context_finalize (GObject *object)
G_OBJECT_CLASS (ide_context_parent_class)->finalize (object);
+ _ide_battery_monitor_shutdown ();
+
IDE_EXIT;
}
@@ -746,6 +748,8 @@ ide_context_init (IdeContext *self)
IDE_ENTRY;
+ _ide_battery_monitor_init ();
+
self->recent_manager = g_object_ref (gtk_recent_manager_get_default ());
self->root_build_dir = g_build_filename (g_get_user_cache_dir (),
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 5f82588..7565061 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -51,6 +51,8 @@ gboolean _ide_back_forward_list_save_finish (IdeBackForwardList *s
GError **error);
IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
IdeFile *file);
+void _ide_battery_monitor_init (void);
+void _ide_battery_monitor_shutdown (void);
void _ide_buffer_set_changed_on_volume (IdeBuffer *self,
gboolean changed_on_volume);
gboolean _ide_buffer_get_loading (IdeBuffer *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]