1 /* $Cambridge: exim/src/OS/os.c-GNU,v 1.1 2004/10/06 15:07:39 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* See the file NOTICE for conditions of use and distribution. */
9 /* GNU-specific code. This is concatenated onto the generic src/os.c file.
10 GNU/Hurd has approximately the same way to determine the load average as NeXT,
11 so a variant of this could also be in the generic os.c file. See the GNU EMacs
12 getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs
13 is copyrighted by the FSF under the terms of the GPLv2 or any later version.
14 Changes are hereby placed under the same license, as requested by the GPL. */
16 #ifndef OS_LOAD_AVERAGE
17 #define OS_LOAD_AVERAGE
21 static processor_set_t default_set;
22 static int getloadavg_initialized;
28 struct processor_set_basic_info info;
31 if (!getloadavg_initialized)
33 if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS)
34 getloadavg_initialized = 1;
37 if (getloadavg_initialized)
39 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
40 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host,
41 (processor_set_info_t)&info, &info_count) != KERN_SUCCESS)
42 getloadavg_initialized = 0;
45 #if LOAD_SCALE == 1000
46 return info.load_average;
48 return (int) (((double) info.load_average * 1000) / LOAD_SCALE));
55 #endif /* OS_LOAD_AVERAGE */