/* The tool calls of one reply, run at the same time (Pi's toolExecution * "parallel"). Each call runs in a child process forked from pic, which * runs the tool as pic would and asks pic, over a socket, for everything * that touches the journal or the terminal: started(), fetch(), partial(), * and what `pic ps` records. pic alone ever uses its database connections, * so nothing SQLite is shared across processes or threads. * * Why forked children and not threads: pic already supervises bash in * forked processes that report over a pipe and never touch the database * (tools.c), so the tools run unchanged, with no locking added to them, to * the side channel or to the user database; a call that dies takes nothing * of pic's with it; and pic stays single-threaded around fork(). A build * whose executor is not the host's (pic_executor, the no-OS seam) has no * processes to fork: it runs the calls in order instead (loop.c checks). */ #ifndef PIC_TOOLPAR_H #define PIC_TOOLPAR_H #include #include "pic.h" typedef struct { const char *tool; const pic_tool_args *args; /* pic's side of the hooks: started, fetch and partial are called in * pic for the child; output and image are filled before done. */ const pic_tool_hooks *hooks; /* The file the call touches (pic_tool_path_key), or NULL, and whether it * changes it: a call waits for every earlier call of the batch on the * same file while either of the two changes it. */ const char *key; int mutates; /* Called in pic once the call ends, in the order calls finish: its * result (malloc'd, the callee's) and is_error, as pic_toolset_run * returns them; NULL when its outcome is lost or it never started. A * call that never started because of an abort gets no done at all. */ void (*done)(void *ctx, char *result, int is_error); void *ctx; } pic_par_call; /* Runs the calls at once, each as soon as no earlier call on its file is * unfinished; serves the side channel meanwhile. Once pic_interrupted is * set, every running call is told to abort (a command is killed and * reported, as a lone call's is) and calls not yet started are left. Returns * when every started call has ended. */ void pic_par_run(const char *workspace, pic_par_call *calls, size_t n); #endif