libjobserver – v0.2.0 Handle parallel jobs in a build automation application compatible with GNU Make code.malloc.fr

NAME

jobserver_connect, jobserver_create, jobserver_create_n, jobserver_close - connect to or create and then quit a jobserver

SYNOPSIS

#include <jobserver.h>

int jobserver_connect(struct jobserver * js);

int jobserver_create (struct jobserver * js, char const * tokens);
int jobserver_create_n(struct jobserver * js, size_t size, char token);

int jobserver_close(struct jobserver * js);

DESCRIPTION

The jobserver_connect() function tries to connect to an environment-defined jobserver js.

The jobserver_create() and jobserver_create_n() functions create a new jobserver js and publish it to the environment. The jobserver is initialized with either a null-terminated word of tokens or with size tokens as additional job slots to the free token.
To create a jobserver that spawns one child after the other, no additional token need be passed. In general, if the jobserver is created after a -j X option, size or strlen(tokens) should be X-1.

The jobserver_close() function closes jobserver js if there are no remaining jobs. Note that it does not modify the environment variable, use jobserver_unsetenv(3) to achieve this.

RETURN VALUE

On success, the jobserver_open() and jobserver_close() functions return 0.

On success, the jobserver_create() and jobserver_create_n() functions return the number of possible parallel jobs, that is the number tokens available in the jobserver pipe plus one (size + 1 or strlen(tokens) + 1).

On error, -1 is returned and errno is set accordingly.

ERROR

0

(Linux only) The signalfd file descriptor could not be created.

jobserver_connect()

EACCES

The jobserver pipe is closed because the current process was spawned by Make without the ’+’ prefix, see section 13.1 of the GNU Make documentation.

EBADF

Either one of the jobserver file descriptors is invalid.

ENODEV

No jobserver found.

EPROTO

Error while parsing the environment.

jobserver_create() and jobserver_create_n()

EINVAL

The number of tokens in the pipe exceeds PIPE_BUF.

EMFILE

Too many file descriptors for the process.

ENFILE

Too many file descriptors for the system.

ENOMEM

Not enough memory to set the environment variable.

jobserver_close()

EAGAIN

Cannot count tokens, call jobserver_wait(3) and try again.

EBUSY

Not all jobs have been waited for yet, call jobserver_collect(3) and try again.

EIDRM

No jobs remain but some tokens have not been given back. You might want to inform the user.

SEE ALSO

jobserver(7), jobserver_clear(3), jobserver_collect(3), jobserver_launch_job(3), jobserver_print(3), jobserver_getenv(3), jobserver_setenv(3), jobserver_terminate_job(3), jobserver_unsetenv(3), jobserver_wait(3)