Skip to content

Commit

Permalink
Disable getloadavg support by default
Browse files Browse the repository at this point in the history
Many platforms don't have getloadavg or hide it behind platform-specific
defines. Rather than try to work around it with an ifdef maze,
disable it by default. Builders can enable it by adding
`-D HAVE_LOADAVG` to their CFLAGS, along with whatever other defines
are needed for their platform.
  • Loading branch information
michaelforney committed Jun 17, 2023
1 parent 0e98a83 commit c16d450
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ It is feature-complete and supports most of the same options as ninja.

samurai requires various POSIX.1-2008 interfaces.

Scheduling jobs based on load average requires through the non-standard, but
widely available `getloadavg` function. This feature can be disabled by
defining the `NO_GETLOADAVG` macro when calling the C compiler.
Scheduling jobs based on load average requires the non-standard
`getloadavg` function. This feature can be enabled by defining
`HAVE_GETLOADAVG` in your `CFLAGS`, along with any other necessary
definitions for your platform.

## Differences from ninja

Expand Down
9 changes: 3 additions & 6 deletions build.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#ifndef NO_GETLOADAVG
#define _BSD_SOURCE /* for getloadavg */
#endif
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
Expand Down Expand Up @@ -527,9 +524,7 @@ jobwork(struct job *j)
static double
queryload(void)
{
#ifdef NO_GETLOADAVG
return 0;
#else
#ifdef HAVE_GETLOADAVG
double load;

if (getloadavg(&load, 1) == -1) {
Expand All @@ -538,6 +533,8 @@ queryload(void)
}

return load;
#else
return 0;
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions samu.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ debugflag(const char *flag)
static void
loadflag(const char *flag)
{
#ifdef NO_GETLOADAVG
warn("job scheduling based on load average is not implemented");
#else
#ifdef HAVE_GETLOADAVG
double value;
char *end;
errno = 0;
Expand All @@ -64,6 +62,8 @@ loadflag(const char *flag)
if (*end || value < 0 || errno != 0)
fatal("invalid -l parameter");
buildopts.maxload = value;
#else
warn("job scheduling based on load average is not supported");
#endif
}

Expand Down

0 comments on commit c16d450

Please sign in to comment.