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

NAME

jobserver_launch_job, jobserver_clear - spawn a job or clear the jobserver

SYNOPSIS

#include <jobserver.h>

typedef int (*jobserver_callback_t)(void * data);
typedef void (*jobserver_callback_return_t) (void * data, int status);

int jobserver_launch_job(struct jobserver * js, int wait, bool shared, void * data, jobserver_callback_t func, jobserver_callback_return_t done);
int jobserver_clear(struct jobserver * js);

DESCRIPTION

The jobserver_launch_job() function adds a new job to jobserver js using the callback function func as the main function of the new process.

The callback done is called when the job terminates its execution and is later collected by jobserver_terminate_job(3), jobserver_wait(3), jobserver_collect(3), or jobserver_clear().

Because the jobserver might not have any tokens left to start a new job, the function might wait for a token to become available (see poll(2) for the different types of value it may take).

Jobserver js could be shared with the new process such that it would be possible to use jobserver_connect(3) and access jobserver js in the new process.

The data argument is passed to the func and done callbacks. The done callback receives the exit status of the spwaned process as specified in wait(2).

The jobserver_clear() function kills all remaining jobs of jobserver js.

RETURN VALUE

On success, jobserver_launch_job() and jobserver_clear() return 0. On error, -1 is returned and errno is set accordingly.

ERROR

EAGAIN

No token could be obtained.

EBADF

The reading end of the jobserver pipe is not open for reading. The jobserver should be closed.

ECHILD

A child that was not a job exited (see section Handling forks in jobserver(7)).

EINTR

The function was interupted by a signal that was not SIGCHLD.

ENOMEM

No enough memory.

SEE ALSO

jobserver(7), jobserver_collect(3), jobserver_connect(3), jobserver_close(3), jobserver_create(3), jobserver_create_n(3), jobserver_print(3), jobserver_getenv(3), jobserver_setenv(3), jobserver_terminate_job(3), jobserver_unsetenv(3), jobserver_wait(3)