diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5da9aa112bcb025865171202f0cf0d9a81e92bd9..9ca71544bbbf5dc44662651c44c79dd1404748f2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -94,7 +94,13 @@ installed-tests:
extends: .only-default
image: registry.gitlab.gnome.org/gnome/glib/fedora:v5
stage: build
+ before_script:
+ # FIXME move to docker image
+ - sudo dnf install -y gnome-desktop-testing python3-dbusmock xdg-desktop-portal
script:
+ # FIXME Install xdg-desktop-portal build deps before compiling glib,
+ # so it doesn't overwrite our own glib build
+ - sudo dnf install -y autoconf automake gettext-devel libtool diffutils fontconfig-devel json-glib-devel geoclue2-devel pipewire-devel fuse-devel make
# dtrace is disabled because it breaks the static-link.py test
- meson ${MESON_COMMON_OPTIONS}
--werror
@@ -106,6 +112,32 @@ installed-tests:
_build
- ninja -C _build
- sudo ninja -C _build install
+ # FIXME install libportal to build new xdg-desktop-portal
+ - git clone https://github.com/flatpak/libportal.git
+ - cd libportal/
+ - meson ${MESON_COMMON_OPTIONS} _build --prefix=/usr --libdir=/usr/lib64
+ - ninja -C _build
+ - sudo ninja -C _build install
+ - cd ..
+ # FIXME Install newer xdg-desktop-portal with
+ # GMemoryMonitor support, see:
+ # https://github.com/flatpak/xdg-desktop-portal/pull/365
+ - git clone --single-branch --branch wip/hadess/memory-monitor https://github.com/flatpak/xdg-desktop-portal.git
+ - cd xdg-desktop-portal
+ - ./autogen.sh --prefix=/usr --libdir=/usr/lib64 --disable-dependency-tracking && make && sudo make install
+ - cd ..
+ # FIXME install newer gobject-introspection
+ # with GMemoryMonitor support, see:
+ # https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/193
+ - sudo dnf install -y meson flex bison python3-devel
+ - git clone --single-branch --branch wip/hadess/add-memory-monitor https://gitlab.gnome.org/GNOME/gobject-introspection.git
+ - cd gobject-introspection
+ - /usr/bin/meson _build --prefix=/usr --libdir=/usr/lib64
+ - ninja -C _build
+ - sudo ninja -C _build install
+ - cd ..
+ # FIXME: Add update until stable https://bodhi.fedoraproject.org/updates/FEDORA-2019-e830287661
+ - sudo dnf upgrade -y --enablerepo=updates-testing --advisory=FEDORA-2019-e830287661
# FIXME: Add update until stable https://bodhi.fedoraproject.org/updates/FEDORA-2019-161b129d4d
- sudo dnf upgrade -y --enablerepo=updates-testing --advisory=FEDORA-2019-161b129d4d
# Work-around https://gitlab.gnome.org/GNOME/gnome-desktop-testing/merge_requests/2
diff --git a/docs/reference/gio/gio-docs.xml b/docs/reference/gio/gio-docs.xml
index 0ce0e2d4229ed3fac2006ec9cbb26b4aae1f7475..20044f0d3203d51278a7010d246d04cff89fa197 100644
--- a/docs/reference/gio/gio-docs.xml
+++ b/docs/reference/gio/gio-docs.xml
@@ -232,6 +232,7 @@
+
diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt
index 0480d3f63138776e8cdc15c67341aab14db370ce..c6a261efe67a9e2e3bc08c96a674623d6763265f 100644
--- a/docs/reference/gio/gio-sections-common.txt
+++ b/docs/reference/gio/gio-sections-common.txt
@@ -4170,6 +4170,23 @@ G_DBUS_OBJECT_MANAGER_SERVER_GET_CLASS
GDBusObjectManagerServerPrivate
+
+gmemorymonitor
+GMemoryMonitor
+GMemoryMonitor
+GMemoryMonitorFlags
+GMemoryMonitorInterface
+GMemoryMonitorWarningLevel
+G_MEMORY_MONITOR_EXTENSION_POINT_NAME
+g_memory_monitor_dup_default
+
+g_memory_monitor_get_type
+G_TYPE_MEMORY_MONITOR
+G_MEMORY_MONITOR
+G_IS_MEMORY_MONITOR
+G_MEMORY_MONITOR_GET_INTERFACE
+
+
gnetworkmonitor
GNetworkMonitor
diff --git a/docs/reference/gio/meson.build b/docs/reference/gio/meson.build
index f8805a57529b8535f67463f3573edec1f7d9c983..a93296de710da522bc427de3d2b7d66c2573ade8 100644
--- a/docs/reference/gio/meson.build
+++ b/docs/reference/gio/meson.build
@@ -50,6 +50,8 @@ if get_option('gtk_doc')
'glocalfilemonitor.h',
'glocalfileoutputstream.h',
'glocalvfs.h',
+ 'gmemorymonitordbus.h',
+ 'gmemorymonitorportal.h',
'gmountprivate.h',
'gnativevolumemonitor.h',
'gnetworkingprivate.h',
diff --git a/gio/gio.h b/gio/gio.h
index 8053768a00be7906e275ea1d33f505a27080ce1e..3532b73bf68d6197d8857f9df26bfedfc1080b66 100644
--- a/gio/gio.h
+++ b/gio/gio.h
@@ -47,15 +47,25 @@
#include
#include
#include
+#include
#include
#include
#include
#include
+#include
+#include
#include
+#include
#include
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
@@ -64,9 +74,9 @@
#include
#include
#include
+#include
#include
#include
-#include
#include
#include
#include
@@ -88,9 +98,15 @@
#include
#include
#include
+#include
+#include
#include
#include
+#include
#include
+#include
+#include
+#include
#include
#include
#include
@@ -98,6 +114,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -108,30 +125,31 @@
#include
#include
#include
+#include
#include
#include
#include
-#include
#include
+#include
#include
#include
#include
#include
#include
-#include
+#include
+#include
#include
+#include
#include
#include
#include
#include
-#include
#include
#include
#include
-#include
-#include
#include
#include
+#include
#include
#include
#include
@@ -144,30 +162,13 @@
#include
#include
#include
-#include
#include
+#include
#include
#include
#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 22fe7005c16392f4eaff4bc6162c3efd5e83fed0..2efd81ed984a56167ab24f37b2d098c15a1ba47c 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -1964,6 +1964,38 @@ typedef enum {
G_POLLABLE_RETURN_WOULD_BLOCK = -G_IO_ERROR_WOULD_BLOCK
} GPollableReturn;
+/**
+ * GMemoryMonitorWarningLevel:
+ * @G_MEMORY_MONITOR_WARNING_LEVEL_LOW: Memory on the device is low, processes
+ * should free up unneeded resources (for example, in-memory caches) so they can
+ * be used elsewhere.
+ * @G_MEMORY_MONITOR_WARNING_LEVEL_MEDIUM: Same as @G_MEMORY_MONITOR_WARNING_LEVEL_LOW
+ * but the device has even less free memory, so processes should try harder to free
+ * up unneeded resources. If your process does not need to stay running, it is a
+ * good time for it to quit.
+ * @G_MEMORY_MONITOR_WARNING_LEVEL_CRITICAL: The system will soon start terminating
+ * processes to reclaim memory, including background processes.
+ *
+ * Memory availability warning levels.
+ *
+ * Note that because new values might be added, it is recommended that applications check
+ * #GMemoryMonitorWarningLevel as ranges, for example:
+ *
+ * Comparing memory warning levels
+ *
+ * if (warning_level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW)
+ * drop_caches ();
+ *
+ *
+ *
+ * Since: 2.64
+ */
+typedef enum {
+ G_MEMORY_MONITOR_WARNING_LEVEL_LOW = 50,
+ G_MEMORY_MONITOR_WARNING_LEVEL_MEDIUM = 100,
+ G_MEMORY_MONITOR_WARNING_LEVEL_CRITICAL = 255
+} GMemoryMonitorWarningLevel;
+
G_END_DECLS
#endif /* __GIO_ENUMS_H__ */
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 1007abdbf3061dbf99025007b739f0ff741a4c77..546913e9acc085587d87bd6461b6b127421963e4 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -42,6 +42,9 @@
#include "gnotificationbackend.h"
#include "ginitable.h"
#include "gnetworkmonitor.h"
+#include "gmemorymonitor.h"
+#include "gmemorymonitorportal.h"
+#include "gmemorymonitordbus.h"
#ifdef G_OS_WIN32
#include "gregistrysettingsbackend.h"
#endif
@@ -1025,6 +1028,9 @@ extern GType _g_network_monitor_netlink_get_type (void);
extern GType _g_network_monitor_nm_get_type (void);
#endif
+extern GType g_memory_monitor_dbus_get_type (void);
+extern GType g_memory_monitor_portal_get_type (void);
+
#ifdef G_OS_UNIX
extern GType g_fdo_notification_backend_get_type (void);
extern GType g_gtk_notification_backend_get_type (void);
@@ -1127,6 +1133,9 @@ _g_io_modules_ensure_extension_points_registered (void)
ep = g_io_extension_point_register (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME);
g_io_extension_point_set_required_type (ep, G_TYPE_NOTIFICATION_BACKEND);
+
+ ep = g_io_extension_point_register (G_MEMORY_MONITOR_EXTENSION_POINT_NAME);
+ g_io_extension_point_set_required_type (ep, G_TYPE_MEMORY_MONITOR);
}
G_UNLOCK (registered_extensions);
@@ -1235,6 +1244,8 @@ _g_io_modules_ensure_loaded (void)
g_type_ensure (g_fdo_notification_backend_get_type ());
g_type_ensure (g_gtk_notification_backend_get_type ());
g_type_ensure (g_portal_notification_backend_get_type ());
+ g_type_ensure (g_memory_monitor_dbus_get_type ());
+ g_type_ensure (g_memory_monitor_portal_get_type ());
g_type_ensure (g_network_monitor_portal_get_type ());
g_type_ensure (g_proxy_resolver_portal_get_type ());
#endif
diff --git a/gio/giotypes.h b/gio/giotypes.h
index c9ad8dd90ea8d8a931b3b9e3f8fc6d4f7a32179c..6f6987ecab1f7907a30a278ee54d100758534463 100644
--- a/gio/giotypes.h
+++ b/gio/giotypes.h
@@ -122,6 +122,7 @@ typedef struct _GLoadableIcon GLoadableIcon; /* Dummy typedef */
typedef struct _GBytesIcon GBytesIcon;
typedef struct _GMemoryInputStream GMemoryInputStream;
typedef struct _GMemoryOutputStream GMemoryOutputStream;
+typedef struct _GMemoryMonitor GMemoryMonitor;
/**
* GMount:
diff --git a/gio/gmemorymonitor.c b/gio/gmemorymonitor.c
new file mode 100644
index 0000000000000000000000000000000000000000..d0c9cfb0d8f06deec559022b22a51501d1437e51
--- /dev/null
+++ b/gio/gmemorymonitor.c
@@ -0,0 +1,127 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#include "config.h"
+#include "glib.h"
+#include "glibintl.h"
+
+#include "gmemorymonitor.h"
+#include "ginetaddress.h"
+#include "ginetsocketaddress.h"
+#include "ginitable.h"
+#include "gioenumtypes.h"
+#include "giomodule-priv.h"
+#include "gtask.h"
+
+/**
+ * SECTION:gmemorymonitor
+ * @title: GMemoryMonitor
+ * @short_description: Memory usage monitor
+ * @include: gio/gio.h
+ *
+ * #GMemoryMonitor will monitor system memory and suggest to the application
+ * when to free memory so as to leave more room for other applications.
+ * It is implemented on Linux using the [Low Memory Monitor](https://gitlab.freedesktop.org/hadess/low-memory-monitor/)
+ * ([API documentation](https://hadess.pages.freedesktop.org/low-memory-monitor/)).
+ *
+ * There is also an implementation for use inside Flatpak sandboxes.
+ *
+ * Possible actions to take when the signal is received are:
+ * - Free caches
+ * - Save files that haven't been looked at in a while to disk, ready to be reopened when needed
+ * - Run a garbage collection cycle
+ * - Try and compress fragmented allocations
+ * - Exit on idle if the process has no reason to stay around
+ *
+ * See #GMemoryMonitorWarningLevel for details on the various warning levels.
+ *
+ * Since: 2.64
+ */
+
+/**
+ * GMemoryMonitor:
+ *
+ * #GMemoryMonitor monitors system memory and indicates when
+ * the system is low on memory.
+ *
+ * Since: 2.64
+ */
+
+/**
+ * GMemoryMonitorInterface:
+ * @g_iface: The parent interface.
+ * @low_memory_warning: the virtual function pointer for the
+ * #GMemoryMonitor::low-memory-warning signal.
+ *
+ * The virtual function table for #GMemoryMonitor.
+ *
+ * Since: 2.64
+ */
+
+G_DEFINE_INTERFACE_WITH_CODE (GMemoryMonitor, g_memory_monitor, G_TYPE_OBJECT,
+ g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE))
+
+enum {
+ LOW_MEMORY_WARNING,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/**
+ * g_memory_monitor_dup_default:
+ *
+ * Gets a reference to the default #GMemoryMonitor for the system.
+ *
+ * Returns: (transfer full): a new reference to the default #GMemoryMonitor
+ *
+ * Since: 2.64
+ */
+GMemoryMonitor *
+g_memory_monitor_dup_default (void)
+{
+ return g_object_ref (_g_io_module_get_default (G_MEMORY_MONITOR_EXTENSION_POINT_NAME,
+ "GIO_USE_MEMORY_MONITOR",
+ NULL));
+}
+
+static void
+g_memory_monitor_default_init (GMemoryMonitorInterface *iface)
+{
+ /**
+ * GMemoryMonitor::low-memory-warning:
+ * @monitor: a #GMemoryMonitor
+ * @level: the #GMemoryMonitorWarningLevel warning level
+ *
+ * Emitted when the system is running low on free memory. The signal
+ * handler should then take the appropriate action depending on the
+ * warning level. See the #GMemoryMonitorWarningLevel documentation for
+ * details.
+ *
+ * Since: 2.64
+ */
+ signals[LOW_MEMORY_WARNING] =
+ g_signal_new (I_("low-memory-warning"),
+ G_TYPE_MEMORY_MONITOR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GMemoryMonitorInterface, low_memory_warning),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 1,
+ G_TYPE_MEMORY_MONITOR_WARNING_LEVEL);
+}
diff --git a/gio/gmemorymonitor.h b/gio/gmemorymonitor.h
new file mode 100644
index 0000000000000000000000000000000000000000..a3ad216c3fd167a8f8558dfba1cf6ea98ededee5
--- /dev/null
+++ b/gio/gmemorymonitor.h
@@ -0,0 +1,62 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#ifndef __G_MEMORY_MONITOR_H__
+#define __G_MEMORY_MONITOR_H__
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only can be included directly."
+#endif
+
+#include
+
+G_BEGIN_DECLS
+
+/**
+ * G_MEMORY_MONITOR_EXTENSION_POINT_NAME:
+ *
+ * Extension point for memory usage monitoring functionality.
+ * See [Extending GIO][extending-gio].
+ *
+ * Since: 2.64
+ */
+#define G_MEMORY_MONITOR_EXTENSION_POINT_NAME "gio-memory-monitor"
+
+#define G_TYPE_MEMORY_MONITOR (g_memory_monitor_get_type ())
+GLIB_AVAILABLE_IN_2_64
+G_DECLARE_INTERFACE(GMemoryMonitor, g_memory_monitor, g, memory_monitor, GObject)
+
+#define G_MEMORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_MEMORY_MONITOR, GMemoryMonitor))
+#define G_IS_MEMORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_MEMORY_MONITOR))
+#define G_MEMORY_MONITOR_GET_INTERFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), G_TYPE_MEMORY_MONITOR, GMemoryMonitorInterface))
+
+struct _GMemoryMonitorInterface {
+ /*< private >*/
+ GTypeInterface g_iface;
+
+ /*< public >*/
+ void (*low_memory_warning) (GMemoryMonitor *monitor,
+ GMemoryMonitorWarningLevel level);
+};
+
+GLIB_AVAILABLE_IN_2_64
+GMemoryMonitor *g_memory_monitor_dup_default (void);
+
+G_END_DECLS
+
+#endif /* __G_MEMORY_MONITOR_H__ */
diff --git a/gio/gmemorymonitordbus.c b/gio/gmemorymonitordbus.c
new file mode 100644
index 0000000000000000000000000000000000000000..a34a58d3ba7feb8bb2443add6ecfff9089e5b298
--- /dev/null
+++ b/gio/gmemorymonitordbus.c
@@ -0,0 +1,171 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#include "config.h"
+
+#include "gmemorymonitor.h"
+#include "gmemorymonitordbus.h"
+#include "gioerror.h"
+#include "ginitable.h"
+#include "giomodule-priv.h"
+#include "glibintl.h"
+#include "glib/gstdio.h"
+#include "gdbusproxy.h"
+#include "gdbusnamewatching.h"
+
+#define G_MEMORY_MONITOR_DBUS_GET_INITABLE_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), G_TYPE_INITABLE, GInitable))
+
+static void g_memory_monitor_dbus_iface_init (GMemoryMonitorInterface *iface);
+static void g_memory_monitor_dbus_initable_iface_init (GInitableIface *iface);
+
+struct _GMemoryMonitorDBus
+{
+ GObject parent_instance;
+
+ guint watch_id;
+ GDBusProxy *proxy;
+ gulong signal_id;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GMemoryMonitorDBus, g_memory_monitor_dbus, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ g_memory_monitor_dbus_initable_iface_init)
+ G_IMPLEMENT_INTERFACE (G_TYPE_MEMORY_MONITOR,
+ g_memory_monitor_dbus_iface_init)
+ _g_io_modules_ensure_extension_points_registered ();
+ g_io_extension_point_implement (G_MEMORY_MONITOR_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "dbus",
+ 30))
+
+static void
+g_memory_monitor_dbus_init (GMemoryMonitorDBus *dbus)
+{
+}
+
+static void
+proxy_signal_cb (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ GMemoryMonitorDBus *dbus)
+{
+ guint8 level;
+
+ if (g_strcmp0 (signal_name, "LowMemoryWarning") != 0)
+ return;
+ if (parameters == NULL)
+ return;
+
+ g_variant_get (parameters, "(y)", &level);
+ g_signal_emit_by_name (dbus, "low-memory-warning", level);
+}
+
+static void
+lmm_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ GMemoryMonitorDBus *dbus = user_data;
+ GDBusProxy *proxy;
+ GError *error = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+ NULL,
+ "org.freedesktop.LowMemoryMonitor",
+ "/org/freedesktop/LowMemoryMonitor",
+ "org.freedesktop.LowMemoryMonitor",
+ NULL,
+ &error);
+
+ if (!proxy)
+ {
+ g_debug ("Failed to create LowMemoryMonitor D-Bus proxy: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ dbus->signal_id = g_signal_connect (G_OBJECT (proxy), "g-signal",
+ G_CALLBACK (proxy_signal_cb), dbus);
+ dbus->proxy = proxy;
+}
+
+static void
+lmm_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ GMemoryMonitorDBus *dbus = user_data;
+
+ if (dbus->proxy != NULL)
+ g_clear_signal_handler (&dbus->signal_id, dbus->proxy);
+ g_clear_object (&dbus->proxy);
+}
+
+static gboolean
+g_memory_monitor_dbus_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (initable);
+
+ dbus->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.LowMemoryMonitor",
+ G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
+ lmm_appeared_cb,
+ lmm_vanished_cb,
+ dbus,
+ NULL);
+
+ return TRUE;
+}
+
+static void
+g_memory_monitor_dbus_finalize (GObject *object)
+{
+ GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (object);
+
+ if (dbus->proxy != NULL)
+ g_clear_signal_handler (&dbus->signal_id, dbus->proxy);
+ g_clear_object (&dbus->proxy);
+ g_clear_handle_id (&dbus->watch_id, g_bus_unwatch_name);
+
+ G_OBJECT_CLASS (g_memory_monitor_dbus_parent_class)->finalize (object);
+}
+
+static void
+g_memory_monitor_dbus_class_init (GMemoryMonitorDBusClass *nl_class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (nl_class);
+
+ gobject_class->finalize = g_memory_monitor_dbus_finalize;
+}
+
+static void
+g_memory_monitor_dbus_iface_init (GMemoryMonitorInterface *monitor_iface)
+{
+}
+
+static void
+g_memory_monitor_dbus_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = g_memory_monitor_dbus_initable_init;
+}
diff --git a/gio/gmemorymonitordbus.h b/gio/gmemorymonitordbus.h
new file mode 100644
index 0000000000000000000000000000000000000000..e48e7557f8277b74111d32225fbde8745d29b4f2
--- /dev/null
+++ b/gio/gmemorymonitordbus.h
@@ -0,0 +1,31 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#ifndef __G_MEMORY_MONITOR_DBUS_H__
+#define __G_MEMORY_MONITOR_DBUS_H__
+
+#include
+
+G_BEGIN_DECLS
+
+#define G_TYPE_MEMORY_MONITOR_DBUS (g_memory_monitor_dbus_get_type ())
+G_DECLARE_FINAL_TYPE (GMemoryMonitorDBus, g_memory_monitor_dbus, G, MEMORY_MONITOR_DBUS, GObject)
+
+G_END_DECLS
+
+#endif /* __G_MEMORY_MONITOR_DBUS_H__ */
diff --git a/gio/gmemorymonitorportal.c b/gio/gmemorymonitorportal.c
new file mode 100644
index 0000000000000000000000000000000000000000..440629f4146aa8b8e6c35b264b122964b06d449d
--- /dev/null
+++ b/gio/gmemorymonitorportal.c
@@ -0,0 +1,152 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#include "config.h"
+
+#include "gmemorymonitor.h"
+#include "gmemorymonitorportal.h"
+#include "ginitable.h"
+#include "giomodule-priv.h"
+#include "xdp-dbus.h"
+#include "gportalsupport.h"
+
+#define G_MEMORY_MONITOR_PORTAL_GET_INITABLE_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), G_TYPE_INITABLE, GInitable))
+
+static void g_memory_monitor_portal_iface_init (GMemoryMonitorInterface *iface);
+static void g_memory_monitor_portal_initable_iface_init (GInitableIface *iface);
+
+struct _GMemoryMonitorPortal
+{
+ GObject parent_instance;
+
+ GDBusProxy *proxy;
+ gulong signal_id;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GMemoryMonitorPortal, g_memory_monitor_portal, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ g_memory_monitor_portal_initable_iface_init)
+ G_IMPLEMENT_INTERFACE (G_TYPE_MEMORY_MONITOR,
+ g_memory_monitor_portal_iface_init)
+ _g_io_modules_ensure_extension_points_registered ();
+ g_io_extension_point_implement (G_MEMORY_MONITOR_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "portal",
+ 40))
+
+static void
+g_memory_monitor_portal_init (GMemoryMonitorPortal *portal)
+{
+}
+
+static void
+proxy_signal (GDBusProxy *proxy,
+ const char *sender,
+ const char *signal,
+ GVariant *parameters,
+ GMemoryMonitorPortal *portal)
+{
+ guint8 level;
+
+ if (strcmp (signal, "LowMemoryWarning") != 0)
+ return;
+ if (!parameters)
+ return;
+
+ g_variant_get (parameters, "(y)", &level);
+ g_signal_emit_by_name (portal, "low-memory-warning", level);
+}
+
+static gboolean
+g_memory_monitor_portal_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GMemoryMonitorPortal *portal = G_MEMORY_MONITOR_PORTAL (initable);
+ GDBusProxy *proxy;
+ gchar *name_owner = NULL;
+
+ if (!glib_should_use_portal ())
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not using portals");
+ return FALSE;
+ }
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.MemoryMonitor",
+ cancellable,
+ error);
+ if (!proxy)
+ return FALSE;
+
+ name_owner = g_dbus_proxy_get_name_owner (proxy);
+
+ if (name_owner == NULL)
+ {
+ g_object_unref (proxy);
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Desktop portal not found");
+ return FALSE;
+ }
+
+ g_free (name_owner);
+
+ portal->signal_id = g_signal_connect (proxy, "g-signal",
+ G_CALLBACK (proxy_signal), portal);
+
+ portal->proxy = proxy;
+
+ return TRUE;
+}
+
+static void
+g_memory_monitor_portal_finalize (GObject *object)
+{
+ GMemoryMonitorPortal *portal = G_MEMORY_MONITOR_PORTAL (object);
+
+ if (portal->proxy != NULL)
+ g_clear_signal_handler (&portal->signal_id, portal->proxy);
+ g_clear_object (&portal->proxy);
+
+ G_OBJECT_CLASS (g_memory_monitor_portal_parent_class)->finalize (object);
+}
+
+static void
+g_memory_monitor_portal_class_init (GMemoryMonitorPortalClass *nl_class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (nl_class);
+
+ gobject_class->finalize = g_memory_monitor_portal_finalize;
+}
+
+static void
+g_memory_monitor_portal_iface_init (GMemoryMonitorInterface *monitor_iface)
+{
+}
+
+static void
+g_memory_monitor_portal_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = g_memory_monitor_portal_initable_init;
+}
diff --git a/gio/gmemorymonitorportal.h b/gio/gmemorymonitorportal.h
new file mode 100644
index 0000000000000000000000000000000000000000..57074b48a7925849dd3b1868b2e7599e4bdc4075
--- /dev/null
+++ b/gio/gmemorymonitorportal.h
@@ -0,0 +1,31 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#ifndef __G_MEMORY_MONITOR_PORTAL_H__
+#define __G_MEMORY_MONITOR_PORTAL_H__
+
+#include
+
+G_BEGIN_DECLS
+
+#define G_TYPE_MEMORY_MONITOR_PORTAL (g_memory_monitor_portal_get_type ())
+G_DECLARE_FINAL_TYPE (GMemoryMonitorPortal, g_memory_monitor_portal, G, MEMORY_MONITOR_PORTAL, GObject)
+
+G_END_DECLS
+
+#endif /* __G_MEMORY_MONITOR_PORTAL_H__ */
diff --git a/gio/meson.build b/gio/meson.build
index 173000f4b88a7880baf2770d9aa5180611cc2fff..5382d6a67bf8dc945e9699d7c43791f6941feb0e 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -393,6 +393,7 @@ if host_system != 'windows'
portal_sources = [files(
'gdocumentportal.c',
'gopenuriportal.c',
+ 'gmemorymonitorportal.c',
'gnetworkmonitorportal.c',
'gproxyresolverportal.c',
'gtrashportal.c',
@@ -528,6 +529,8 @@ gio_sources = files(
'gloadableicon.c',
'gmarshal-internal.c',
'gmount.c',
+ 'gmemorymonitor.c',
+ 'gmemorymonitordbus.c',
'gmemoryinputstream.c',
'gmemoryoutputstream.c',
'gmountoperation.c',
@@ -670,6 +673,7 @@ gio_headers = files(
'gloadableicon.h',
'gmount.h',
'gmemoryinputstream.h',
+ 'gmemorymonitor.h',
'gmemoryoutputstream.h',
'gmountoperation.h',
'gnativesocketaddress.h',
diff --git a/gio/tests/memory-monitor-dbus.py.in b/gio/tests/memory-monitor-dbus.py.in
new file mode 100755
index 0000000000000000000000000000000000000000..b1bae7c40812ec2c084815903461c3327568c780
--- /dev/null
+++ b/gio/tests/memory-monitor-dbus.py.in
@@ -0,0 +1,92 @@
+#!/usr/bin/python3
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option) any
+# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
+# of the license.
+
+__author__ = 'Bastien Nocera'
+__email__ = 'hadess@hadess.net'
+__copyright__ = '(c) 2019 Red Hat Inc.'
+__license__ = 'LGPL 3+'
+
+import unittest
+import sys
+import subprocess
+import dbus
+import dbus.mainloop.glib
+import dbusmock
+import fcntl
+import os
+import time
+
+from gi.repository import GLib
+from gi.repository import Gio
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+# XDG_DESKTOP_PORTAL_PATH = os.path.expanduser("~/.cache/jhbuild/build/xdg-desktop-portal/xdg-desktop-portal")
+XDG_DESKTOP_PORTAL_PATH = "@libexecdir@/xdg-desktop-portal"
+
+class TestLowMemoryMonitor(dbusmock.DBusTestCase):
+ '''Test GMemoryMonitorDBus'''
+
+ @classmethod
+ def setUpClass(klass):
+ klass.start_system_bus()
+ klass.dbus_con = klass.get_dbus(True)
+
+ def setUp(self):
+ (self.p_mock, self.obj_lmm) = self.spawn_server_template(
+ 'low_memory_monitor', {}, stdout=subprocess.PIPE)
+ # set log to nonblocking
+ flags = fcntl.fcntl(self.p_mock.stdout, fcntl.F_GETFL)
+ fcntl.fcntl(self.p_mock.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
+ self.last_warning = -1
+ self.dbusmock = dbus.Interface(self.obj_lmm, dbusmock.MOCK_IFACE)
+ self.memory_monitor = Gio.MemoryMonitor.dup_default()
+ self.memory_monitor.connect("low-memory-warning", self.memory_warning_cb)
+ self.mainloop = GLib.MainLoop()
+ self.main_context = self.mainloop.get_context()
+
+ def tearDown(self):
+ self.p_mock.terminate()
+ self.p_mock.wait()
+
+ def memory_warning_cb(self, monitor, level):
+ self.last_warning = level
+ self.main_context.wakeup()
+
+ def test_low_memory_warning_signal(self):
+ '''LowMemoryWarning signal'''
+
+ # Wait 2 seconds
+ timeout = 2
+ while timeout > 0:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+
+ self.dbusmock.EmitWarning(100)
+ # Wait 2 seconds or until warning
+ timeout = 2
+ while timeout > 0 or self.last_warning != 100:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+ self.assertEqual(self.last_warning, 100)
+
+ self.dbusmock.EmitWarning(255)
+ # Wait 2 seconds or until warning
+ timeout = 2
+ while timeout > 0 or self.last_warning != 255:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+ self.assertEqual(self.last_warning, 255)
+
+
+if __name__ == '__main__':
+ # avoid writing to stderr
+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
diff --git a/gio/tests/memory-monitor-portal.py.in b/gio/tests/memory-monitor-portal.py.in
new file mode 100755
index 0000000000000000000000000000000000000000..35f546212d379ab84012c8d1fb9e9410b1377616
--- /dev/null
+++ b/gio/tests/memory-monitor-portal.py.in
@@ -0,0 +1,104 @@
+#!/usr/bin/python3
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option) any
+# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
+# of the license.
+
+__author__ = 'Bastien Nocera'
+__email__ = 'hadess@hadess.net'
+__copyright__ = '(c) 2019 Red Hat Inc.'
+__license__ = 'LGPL 3+'
+
+import unittest
+import sys
+import subprocess
+import dbus
+import dbus.mainloop.glib
+import dbusmock
+import fcntl
+import os
+import time
+
+from gi.repository import GLib
+from gi.repository import Gio
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+# XDG_DESKTOP_PORTAL_PATH = os.path.expanduser("~/.cache/jhbuild/build/xdg-desktop-portal/xdg-desktop-portal")
+XDG_DESKTOP_PORTAL_PATH = "@libexecdir@/xdg-desktop-portal"
+
+class TestLowMemoryMonitorPortal(dbusmock.DBusTestCase):
+ '''Test GMemoryMonitorPortal'''
+
+ @classmethod
+ def setUpClass(klass):
+ klass.start_system_bus()
+ klass.dbus_con = klass.get_dbus(True)
+ # Start session bus so that xdg-desktop-portal can run on it
+ klass.start_session_bus()
+
+ def setUp(self):
+ (self.p_mock, self.obj_lmm) = self.spawn_server_template(
+ 'low_memory_monitor', {}, stdout=subprocess.PIPE)
+ # set log to nonblocking
+ flags = fcntl.fcntl(self.p_mock.stdout, fcntl.F_GETFL)
+ fcntl.fcntl(self.p_mock.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
+ self.last_warning = -1
+ self.dbusmock = dbus.Interface(self.obj_lmm, dbusmock.MOCK_IFACE)
+ self.xdp = subprocess.Popen([XDG_DESKTOP_PORTAL_PATH])
+ try:
+ self.wait_for_bus_object('org.freedesktop.portal.Desktop',
+ '/org/freedesktop/portal/desktop')
+ except:
+ raise
+ # subprocess.Popen(['gdbus', 'monitor', '--session', '--dest', 'org.freedesktop.portal.Desktop'])
+
+ os.environ['GTK_USE_PORTAL'] = "1"
+ self.memory_monitor = Gio.MemoryMonitor.dup_default()
+ assert("GMemoryMonitorPortal" in str(self.memory_monitor))
+ self.memory_monitor.connect("low-memory-warning", self.portal_memory_warning_cb)
+ self.mainloop = GLib.MainLoop()
+ self.main_context = self.mainloop.get_context()
+
+ def tearDown(self):
+ self.p_mock.terminate()
+ self.p_mock.wait()
+
+ def portal_memory_warning_cb(self, monitor, level):
+ self.last_warning = level
+ self.main_context.wakeup()
+
+ def test_low_memory_warning_portal_signal(self):
+ '''LowMemoryWarning signal'''
+
+ # Wait 2 seconds
+ timeout = 2
+ while timeout > 0:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+
+ self.dbusmock.EmitWarning(100)
+ # Wait 2 seconds or until warning
+ timeout = 2
+ while timeout > 0 or self.last_warning != 100:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+ self.assertEqual(self.last_warning, 100)
+
+ self.dbusmock.EmitWarning(255)
+ # Wait 2 seconds or until warning
+ timeout = 2
+ while timeout > 0 or self.last_warning != 255:
+ time.sleep(0.5)
+ timeout -= 0.5
+ self.main_context.iteration(False)
+ self.assertEqual(self.last_warning, 255)
+
+
+if __name__ == '__main__':
+ # avoid writing to stderr
+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
diff --git a/gio/tests/memory-monitor.c b/gio/tests/memory-monitor.c
new file mode 100644
index 0000000000000000000000000000000000000000..06eabefa24782d47be64e4126bd7ee9eb62db9e9
--- /dev/null
+++ b/gio/tests/memory-monitor.c
@@ -0,0 +1,88 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see .
+ */
+
+#include
+
+static const char *
+get_level_string (GMemoryMonitorWarningLevel level)
+{
+ GEnumClass *eclass;
+ GEnumValue *value;
+
+ eclass = G_ENUM_CLASS (g_type_class_peek (G_TYPE_MEMORY_MONITOR_WARNING_LEVEL));
+ value = g_enum_get_value (eclass, level);
+
+ if (value == NULL)
+ return "unknown";
+
+ return value->value_nick;
+}
+
+static void
+test_dup_default (void)
+{
+ GMemoryMonitor *monitor;
+
+ monitor = g_memory_monitor_dup_default ();
+ g_assert_nonnull (monitor);
+ g_object_unref (monitor);
+}
+
+static void
+warning_cb (GMemoryMonitor *m,
+ GMemoryMonitorWarningLevel level)
+{
+ const char *str;
+
+ str = get_level_string (level);
+ g_debug ("Warning level: %s (%d)", str , level);
+}
+
+static void
+do_watch_memory (void)
+{
+ GMemoryMonitor *m;
+ GMainLoop *loop;
+
+ m = g_memory_monitor_dup_default ();
+ g_signal_connect (G_OBJECT (m), "low-memory-warning",
+ G_CALLBACK (warning_cb), NULL);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+}
+
+int
+main (int argc, char **argv)
+{
+ int ret;
+
+ if (argc == 2 && !strcmp (argv[1], "--watch"))
+ {
+ do_watch_memory ();
+ return 0;
+ }
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/memory-monitor/default", test_dup_default);
+
+ ret = g_test_run ();
+
+ return ret;
+}
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 623daae7523c4734828c31f424f220d4d4dceb17..890f7b74d9408355570a1257b5f6ee70634fb220 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -53,6 +53,7 @@ gio_tests = {
'inet-address' : {},
'io-stream' : {},
'memory-input-stream' : {},
+ 'memory-monitor' : {},
'memory-output-stream' : {},
'mount-operation' : {},
'network-address' : {'extra_sources': ['mock-resolver.c']},
@@ -477,6 +478,31 @@ if installed_tests_enabled
install_data('static-link.py', install_dir : installed_tests_execdir)
endif
+memory_monitor_tests = [
+ 'memory-monitor-dbus',
+ 'memory-monitor-portal',
+]
+
+foreach memory_monitor_test : memory_monitor_tests
+ cdata = configuration_data()
+ cdata.set('installed_tests_dir', installed_tests_execdir)
+ cdata.set('program', memory_monitor_test + '.py')
+ configure_file(
+ input: installed_tests_template,
+ output: memory_monitor_test + '.test',
+ install_dir: installed_tests_metadir,
+ configuration: cdata
+ )
+ cdata = configuration_data()
+ cdata.set('libexecdir', join_paths(glib_prefix, get_option('libexecdir')))
+ configure_file(
+ input: memory_monitor_test + '.py.in',
+ output: memory_monitor_test + '.py',
+ install_dir : installed_tests_execdir,
+ configuration: cdata,
+ )
+endforeach
+
if not meson.is_cross_build() or meson.has_exe_wrapper()
plugin_resources_c = custom_target('plugin-resources.c',
diff --git a/glib/glib-object.h b/glib/glib-object.h
index 9561a652894473754120139050cd60d0d0b2f2e2..fa824f3bb243109c1c1e8088552a8c2ec3a540d1 100644
--- a/glib/glib-object.h
+++ b/glib/glib-object.h
@@ -19,10 +19,10 @@
#define __GLIB_GOBJECT_H_INSIDE__
-/* topmost include file for GObject header files */
#include
#include
#include
+#include
#include
#include
#include
@@ -31,10 +31,9 @@
#include
#include
#include
-#include
#include
+#include
#include
-#include
#include
diff --git a/glib/glib.h b/glib/glib.h
index 5c21b6bf6558b9881d5bcccd98a348c59de671b6..e3b30558e702d55d8b19f0d5813bce3d4bfd308c 100644
--- a/glib/glib.h
+++ b/glib/glib.h
@@ -80,8 +80,8 @@
#include
#include
#include
-#include
#include
+#include
#include
#include
#include
@@ -94,10 +94,11 @@
#include
#include
#include
-#include
#include
+#include
#include
#include
+
#ifdef G_PLATFORM_WIN32
#include
#endif
diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c
index c3652a7e4ae8780a297d046f0d6e0b56ef23a8e7..a6dcc794fe45523c3e5891a0e438e05a59ff48b6 100644
--- a/glib/tests/mainloop.c
+++ b/glib/tests/mainloop.c
@@ -172,6 +172,12 @@ test_timeouts (void)
GMainLoop *loop;
GSource *source;
+ if (!g_test_thorough ())
+ {
+ g_test_skip ("Not running timing heavy test");
+ return;
+ }
+
a = b = c = 0;
ctx = g_main_context_new ();