mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-06 19:13:19 +01:00
gio: add fallback implementation of g_memory_monitor_base_query_mem_ratio
Fallback for non-Linux systems that support the _SC_PHYS_PAGES and _SC_AVPHYS_PAGES sysconf selectors, such as Solaris & OpenBSD. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
committed by
Philip Withnall
parent
80b1e3843f
commit
db165063f0
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#ifdef HAVE_SYSINFO
|
#ifdef HAVE_SYSINFO
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
#elif defined(HAVE_UNISTD_H)
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,6 +81,15 @@ g_memory_monitor_base_query_mem_ratio (void)
|
|||||||
return -1.0;
|
return -1.0;
|
||||||
|
|
||||||
return (gdouble) ((gdouble) info.freeram / (gdouble) info.totalram);
|
return (gdouble) ((gdouble) info.freeram / (gdouble) info.totalram);
|
||||||
|
#elif defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
|
||||||
|
/* Implementation for Solaris, where sysinfo() does not return RAM usage information */
|
||||||
|
long totalram = sysconf (_SC_PHYS_PAGES);
|
||||||
|
long freeram = sysconf (_SC_AVPHYS_PAGES);
|
||||||
|
|
||||||
|
if (totalram <= 0 || freeram < 0)
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
return (gdouble) ((gdouble) freeram / (gdouble) totalram);
|
||||||
#else
|
#else
|
||||||
return -1.0;
|
return -1.0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user