1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* See the file NOTICE for conditions of use and distribution. */
7 /* GNU-specific code. This is concatenated onto the generic src/os.c file.
8 GNU/Hurd has approximately the same way to determine the load average as NeXT,
9 so a variant of this could also be in the generic os.c file. See the GNU EMacs
10 getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs
11 is copyrighted by the FSF under the terms of the GPLv2 or any later version.
12 Changes are hereby placed under the same license, as requested by the GPL. */
14 #ifndef OS_LOAD_AVERAGE
15 #define OS_LOAD_AVERAGE
19 static processor_set_t default_set;
20 static int getloadavg_initialized;
26 struct processor_set_basic_info info;
29 if (!getloadavg_initialized)
31 if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS)
32 getloadavg_initialized = 1;
35 if (getloadavg_initialized)
37 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
38 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host,
39 (processor_set_info_t)&info, &info_count) != KERN_SUCCESS)
40 getloadavg_initialized = 0;
43 #if LOAD_SCALE == 1000
44 return info.load_average;
46 return (int) (((double) info.load_average * 1000) / LOAD_SCALE));
53 #endif /* OS_LOAD_AVERAGE */
57 os_pipe_read(int fd, void * buf, size_t count)
60 for (int retries = 10; retries > 0; retries--)
62 if ((rc = read(fd, buf, count)) >= 0) break;
63 if (rc != -1 || errno != EINTR) break;
70 os_pipe_write(int fd, void * buf, size_t count)
73 for (int retries = 10; retries > 0; retries--)
75 if ((rc = write(fd, buf, count)) >= 0) break;
76 if (rc != -1 || errno != EINTR) break;
82 os_pipe_writev(int fd, const struct iovec * iov, int iovcnt)
85 for (int retries = 10; retries > 0; retries--)
87 if ((rc = writev(fd, iov, iovcnt)) >= 0) break;
88 if (rc != -1 || errno != EINTR) break;