2007-11-01 22:29:48 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2007-11-01 22:29:48 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-11-01 22:29:48 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-11-01 22:29:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2007-11-17 02:36:13 +08:00
|
|
|
#define _WIN32_WINNT 0x0500
|
2007-11-01 22:29:48 +08:00
|
|
|
#include <windows.h>
|
2008-02-07 21:19:15 +08:00
|
|
|
#include <process.h>
|
2007-11-01 22:29:48 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "base-utils.h"
|
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
|
2007-11-01 22:29:48 +08:00
|
|
|
#define NUM_PROCESSORS_DEFAULT 1
|
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
|
2007-11-01 22:29:48 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2008-09-05 01:54:06 +08:00
|
|
|
gint
|
2008-02-07 21:19:15 +08:00
|
|
|
get_pid (void)
|
|
|
|
{
|
2008-09-05 01:54:06 +08:00
|
|
|
return (gint) getpid ();
|
2008-02-07 21:19:15 +08:00
|
|
|
}
|
|
|
|
|
2007-11-01 22:29:48 +08:00
|
|
|
gint
|
|
|
|
get_number_of_processors (void)
|
|
|
|
{
|
|
|
|
gint retval = NUM_PROCESSORS_DEFAULT;
|
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
#if defined(HAVE_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
|
|
|
|
retval = sysconf (_SC_NPROCESSORS_ONLN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
SYSTEM_INFO system_info;
|
|
|
|
|
|
|
|
GetSystemInfo (&system_info);
|
|
|
|
|
|
|
|
retval = system_info.dwNumberOfProcessors;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2007-11-17 02:36:13 +08:00
|
|
|
|
2007-11-17 21:13:11 +08:00
|
|
|
guint64
|
|
|
|
get_physical_memory_size (void)
|
2007-11-17 02:36:13 +08:00
|
|
|
{
|
|
|
|
#ifdef G_OS_UNIX
|
2007-11-17 21:13:11 +08:00
|
|
|
#if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE)
|
2007-11-17 21:51:18 +08:00
|
|
|
return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE);
|
2007-11-17 21:13:11 +08:00
|
|
|
#endif
|
2007-11-17 02:36:13 +08:00
|
|
|
#endif
|
2007-11-17 21:13:11 +08:00
|
|
|
|
2007-11-17 02:36:13 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2007-12-09 22:19:02 +08:00
|
|
|
# if defined(_MSC_VER) && (_MSC_VER <= 1200)
|
|
|
|
MEMORYSTATUS memory_status;
|
|
|
|
memory_status.dwLength = sizeof (memory_status);
|
|
|
|
|
|
|
|
GlobalMemoryStatus (&memory_status);
|
|
|
|
return memory_status.dwTotalPhys;
|
|
|
|
# else
|
|
|
|
/* requires w2k and newer SDK than provided with msvc6 */
|
2007-11-17 02:36:13 +08:00
|
|
|
MEMORYSTATUSEX memory_status;
|
|
|
|
|
|
|
|
memory_status.dwLength = sizeof (memory_status);
|
2007-11-17 21:13:11 +08:00
|
|
|
|
2007-11-17 02:36:13 +08:00
|
|
|
if (GlobalMemoryStatusEx (&memory_status))
|
2007-11-17 21:13:11 +08:00
|
|
|
return memory_status.ullTotalPhys;
|
2007-12-09 22:19:02 +08:00
|
|
|
# endif
|
2007-11-17 02:36:13 +08:00
|
|
|
#endif
|
|
|
|
|
2007-11-17 21:13:11 +08:00
|
|
|
return 0;
|
2007-11-17 02:36:13 +08:00
|
|
|
}
|