Build: fix parallelism problem. Bug 2566
[exim.git] / src / OS / os.c-GNU
CommitLineData
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.
9GNU/Hurd has approximately the same way to determine the load average as NeXT,
10so a variant of this could also be in the generic os.c file. See the GNU EMacs
11getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs
12is copyrighted by the FSF under the terms of the GPLv2 or any later version.
13Changes 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
20static processor_set_t default_set;
21static int getloadavg_initialized;
22
23int
24os_getloadavg (void)
25{
26host_t host;
27struct processor_set_basic_info info;
28unsigned info_count;
29
30if (!getloadavg_initialized)
31 {
32 if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS)
33 getloadavg_initialized = 1;
34 }
35
36if (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
52return -1;
53}
54#endif /* OS_LOAD_AVERAGE */
55
56/* End of os.c-GNU */