Commit | Line | Data |
---|---|---|
61ec970d PH |
1 | /* $Cambridge: exim/src/OS/os.c-GNU,v 1.1 2004/10/06 15:07:39 ph10 Exp $ */ |
2 | ||
3 | /************************************************* | |
4 | * Exim - an Internet mail transport agent * | |
5 | *************************************************/ | |
6 | ||
7 | /* See the file NOTICE for conditions of use and distribution. */ | |
8 | ||
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. */ | |
15 | ||
16 | #ifndef OS_LOAD_AVERAGE | |
17 | #define OS_LOAD_AVERAGE | |
18 | ||
19 | #include <mach.h> | |
20 | ||
21 | static processor_set_t default_set; | |
22 | static int getloadavg_initialized; | |
23 | ||
24 | int | |
25 | os_getloadavg (void) | |
26 | { | |
27 | host_t host; | |
28 | struct processor_set_basic_info info; | |
29 | unsigned info_count; | |
30 | ||
31 | if (!getloadavg_initialized) | |
32 | { | |
33 | if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS) | |
34 | getloadavg_initialized = 1; | |
35 | } | |
36 | ||
37 | if (getloadavg_initialized) | |
38 | { | |
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; | |
43 | else | |
44 | { | |
45 | #if LOAD_SCALE == 1000 | |
46 | return info.load_average; | |
47 | #else | |
48 | return (int) (((double) info.load_average * 1000) / LOAD_SCALE)); | |
49 | #endif | |
50 | } | |
51 | } | |
52 | ||
53 | return -1; | |
54 | } | |
55 | #endif /* OS_LOAD_AVERAGE */ | |
56 | ||
57 | /* End of os.c-GNU */ |