aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2014-07-10 22:09:26 +0300
committerEli Zaretskii2014-07-10 22:09:26 +0300
commit644656aa562a78edf384abd6f4ce80bc930d5547 (patch)
treea79082623aa01754bf31555c72031ad6bb24feb4
parent64c333303ce41c4d014d676ff4cbeeb887506c9e (diff)
downloademacs-644656aa562a78edf384abd6f4ce80bc930d5547.tar.gz
emacs-644656aa562a78edf384abd6f4ce80bc930d5547.zip
Implement memory-info for MS-Windows.
src/w32.c (w32_memory_info): New function. src/w32.h (w32_memory_info): Prototype it. src/alloc.c (Fmemory_info) [WINDOWSNT]: Call it.
-rw-r--r--src/ChangeLog7
-rw-r--r--src/alloc.c16
-rw-r--r--src/w32.c29
-rw-r--r--src/w32.h4
4 files changed, 53 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 87a8f1c7814..93ad0ded350 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12014-07-10 Eli Zaretskii <eliz@gnu.org>
2
3 Implement memory-info for MS-Windows.
4 * w32.c (w32_memory_info): New function.
5 * w32.h (w32_memory_info): Prototype it.
6 * alloc.c (Fmemory_info) [WINDOWSNT]: Call it.
7
12014-07-10 Dmitry Antipov <dmantipov@yandex.ru> 82014-07-10 Dmitry Antipov <dmantipov@yandex.ru>
2 9
3 * coding.h (struct coding_system): Remove 'error_positions' (unused) 10 * coding.h (struct coding_system): Remove 'error_positions' (unused)
diff --git a/src/alloc.c b/src/alloc.c
index c535e836397..4a912703c39 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6875,7 +6875,7 @@ All values are in Kbytes. If there is no swap space, last two
6875values are zero. If the system is not supported, return nil. */) 6875values are zero. If the system is not supported, return nil. */)
6876 (void) 6876 (void)
6877{ 6877{
6878#ifdef HAVE_LINUX_SYSINFO 6878#if defined HAVE_LINUX_SYSINFO
6879 struct sysinfo si; 6879 struct sysinfo si;
6880 uintmax_t units; 6880 uintmax_t units;
6881 6881
@@ -6885,12 +6885,22 @@ values are zero. If the system is not supported, return nil. */)
6885 units = si.mem_unit; 6885 units = si.mem_unit;
6886#else 6886#else
6887 units = 1; 6887 units = 1;
6888#endif 6888#endif
6889 return list4i ((uintmax_t) si.totalram * units / 1024, 6889 return list4i ((uintmax_t) si.totalram * units / 1024,
6890 (uintmax_t) si.freeram * units / 1024, 6890 (uintmax_t) si.freeram * units / 1024,
6891 (uintmax_t) si.totalswap * units / 1024, 6891 (uintmax_t) si.totalswap * units / 1024,
6892 (uintmax_t) si.freeswap * units / 1024); 6892 (uintmax_t) si.freeswap * units / 1024);
6893#else /* not HAVE_LINUX_SYSINFO */ 6893#elif defined WINDOWSNT
6894 unsigned long long totalram, freeram, totalswap, freeswap;
6895
6896 if (w32_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
6897 return list4i ((uintmax_t) totalram / 1024,
6898 (uintmax_t) freeram / 1024,
6899 (uintmax_t) totalswap / 1024,
6900 (uintmax_t) freeswap / 1024);
6901 else
6902 return Qnil;
6903#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT */
6894 /* FIXME: add more systems. */ 6904 /* FIXME: add more systems. */
6895 return Qnil; 6905 return Qnil;
6896#endif /* HAVE_LINUX_SYSINFO */ 6906#endif /* HAVE_LINUX_SYSINFO */
diff --git a/src/w32.c b/src/w32.c
index c5d4aa0fe8e..37a01a311a6 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -6955,6 +6955,35 @@ system_process_attributes (Lisp_Object pid)
6955 return attrs; 6955 return attrs;
6956} 6956}
6957 6957
6958int
6959w32_memory_info (unsigned long long *totalram, unsigned long long *freeram,
6960 unsigned long long *totalswap, unsigned long long *freeswap)
6961{
6962 MEMORYSTATUS memst;
6963 MEMORY_STATUS_EX memstex;
6964
6965 /* Use GlobalMemoryStatusEx if available, as it can report more than
6966 2GB of memory. */
6967 if (global_memory_status_ex (&memstex))
6968 {
6969 *totalram = memstex.ullTotalPhys;
6970 *freeram = memstex.ullAvailPhys;
6971 *totalswap = memstex.ullTotalPageFile;
6972 *freeswap = memstex.ullAvailPageFile;
6973 return 0;
6974 }
6975 else if (global_memory_status (&memst))
6976 {
6977 *totalram = memst.dwTotalPhys;
6978 *freeram = memst.dwAvailPhys;
6979 *totalswap = memst.dwTotalPageFile;
6980 *freeswap = memst.dwAvailPageFile;
6981 return 0;
6982 }
6983 else
6984 return -1;
6985}
6986
6958 6987
6959/* Wrappers for winsock functions to map between our file descriptors 6988/* Wrappers for winsock functions to map between our file descriptors
6960 and winsock's handles; also set h_errno for convenience. 6989 and winsock's handles; also set h_errno for convenience.
diff --git a/src/w32.h b/src/w32.h
index 33fd2709a71..94f7a962833 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -206,6 +206,10 @@ extern void register_child (pid_t, int);
206extern void sys_sleep (int); 206extern void sys_sleep (int);
207extern int sys_link (const char *, const char *); 207extern int sys_link (const char *, const char *);
208 208
209/* Return total and free memory info. */
210extern int w32_memory_info (unsigned long long *, unsigned long long *,
211 unsigned long long *, unsigned long long *);
212
209#ifdef HAVE_GNUTLS 213#ifdef HAVE_GNUTLS
210#include <gnutls/gnutls.h> 214#include <gnutls/gnutls.h>
211 215