Commit | Line | Data |
---|---|---|
61ec970d PH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
1e1ddfac | 5 | /* Copyright (c) The Exim Maintainers 2020 */ |
61ec970d PH |
6 | /* See the file NOTICE for conditions of use and distribution. */ |
7 | ||
8 | /* GNU-specific code. This is concatenated onto the generic src/os.c file. | |
9 | GNU/Hurd has approximately the same way to determine the load average as NeXT, | |
10 | so a variant of this could also be in the generic os.c file. See the GNU EMacs | |
11 | getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs | |
12 | is copyrighted by the FSF under the terms of the GPLv2 or any later version. | |
13 | Changes are hereby placed under the same license, as requested by the GPL. */ | |
14 | ||
15 | #ifndef OS_LOAD_AVERAGE | |
16 | #define OS_LOAD_AVERAGE | |
17 | ||
18 | #include <mach.h> | |
19 | ||
20 | static processor_set_t default_set; | |
21 | static int getloadavg_initialized; | |
22 | ||
23 | int | |
24 | os_getloadavg (void) | |
25 | { | |
26 | host_t host; | |
27 | struct processor_set_basic_info info; | |
28 | unsigned info_count; | |
29 | ||
30 | if (!getloadavg_initialized) | |
31 | { | |
32 | if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS) | |
33 | getloadavg_initialized = 1; | |
34 | } | |
35 | ||
36 | if (getloadavg_initialized) | |
37 | { | |
38 | info_count = PROCESSOR_SET_BASIC_INFO_COUNT; | |
39 | if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host, | |
40 | (processor_set_info_t)&info, &info_count) != KERN_SUCCESS) | |
41 | getloadavg_initialized = 0; | |
42 | else | |
43 | { | |
44 | #if LOAD_SCALE == 1000 | |
45 | return info.load_average; | |
46 | #else | |
47 | return (int) (((double) info.load_average * 1000) / LOAD_SCALE)); | |
48 | #endif | |
49 | } | |
50 | } | |
51 | ||
52 | return -1; | |
53 | } | |
54 | #endif /* OS_LOAD_AVERAGE */ | |
55 | ||
56 | /* End of os.c-GNU */ |