run-command API: have run_process_parallel() take an "opts" struct
As noted infd3aaf53f7
(run-command: add an "ungroup" option to run_process_parallel(), 2022-06-07) which added the "ungroup" passing it to "run_process_parallel()" via the global "run_processes_parallel_ungroup" variable was a compromise to get the smallest possible regression fix for "maint" at the time. This follow-up to that is a start at passing that parameter and others via a new "struct run_process_parallel_opts", as the earlier version[1] of what becamefd3aaf53f7
did. Since we need to change all of the occurrences of "n" to "opt->SOMETHING" let's take the opportunity and rename the terse "n" to "processes". We could also have picked "max_processes", "jobs", "threads" etc., but as the API is named "run_processes_parallel()" let's go with "processes". Since the new "run_processes_parallel()" function is able to take an optional "tr2_category" and "tr2_label" via the struct we can at this point migrate all of the users of "run_processes_parallel_tr2()" over to it. But let's not migrate all the API users yet, only the two users that passed the "ungroup" parameter via the "run_processes_parallel_ungroup" global 1. https://lore.kernel.org/git/cover-v2-0.8-00000000000-20220518T195858Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
c333e6f3a8
commit
6e5ba0bae4
@ -459,17 +459,64 @@ typedef int (*task_finished_fn)(int result,
|
||||
void *pp_task_cb);
|
||||
|
||||
/**
|
||||
* Runs up to n processes at the same time. Whenever a process can be
|
||||
* started, the callback get_next_task_fn is called to obtain the data
|
||||
* Option used by run_processes_parallel(), { 0 }-initialized means no
|
||||
* options.
|
||||
*/
|
||||
struct run_process_parallel_opts
|
||||
{
|
||||
/**
|
||||
* tr2_category & tr2_label: sets the trace2 category and label for
|
||||
* logging. These must either be unset, or both of them must be set.
|
||||
*/
|
||||
const char *tr2_category;
|
||||
const char *tr2_label;
|
||||
|
||||
/**
|
||||
* processes: see 'processes' in run_processes_parallel() below.
|
||||
*/
|
||||
size_t processes;
|
||||
|
||||
/**
|
||||
* ungroup: see 'ungroup' in run_processes_parallel() below.
|
||||
*/
|
||||
unsigned int ungroup:1;
|
||||
|
||||
/**
|
||||
* get_next_task: See get_next_task_fn() above. This must be
|
||||
* specified.
|
||||
*/
|
||||
get_next_task_fn get_next_task;
|
||||
|
||||
/**
|
||||
* start_failure: See start_failure_fn() above. This can be
|
||||
* NULL to omit any special handling.
|
||||
*/
|
||||
start_failure_fn start_failure;
|
||||
|
||||
/**
|
||||
* task_finished: See task_finished_fn() above. This can be
|
||||
* NULL to omit any special handling.
|
||||
*/
|
||||
task_finished_fn task_finished;
|
||||
|
||||
/**
|
||||
* data: user data, will be passed as "pp_cb" to the callback
|
||||
* parameters.
|
||||
*/
|
||||
void *data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options are passed via the "struct run_process_parallel_opts" above.
|
||||
*
|
||||
* Runs N 'processes' at the same time. Whenever a process can be
|
||||
* started, the callback opts.get_next_task is called to obtain the data
|
||||
* required to start another child process.
|
||||
*
|
||||
* The children started via this function run in parallel. Their output
|
||||
* (both stdout and stderr) is routed to stderr in a manner that output
|
||||
* from different tasks does not interleave (but see "ungroup" below).
|
||||
*
|
||||
* start_failure_fn and task_finished_fn can be NULL to omit any
|
||||
* special handling.
|
||||
*
|
||||
* If the "ungroup" option isn't specified, the API will set the
|
||||
* "stdout_to_stderr" parameter in "struct child_process" and provide
|
||||
* the callbacks with a "struct strbuf *out" parameter to write output
|
||||
@ -479,19 +526,10 @@ typedef int (*task_finished_fn)(int result,
|
||||
* NULL "struct strbuf *out" parameter, and are responsible for
|
||||
* emitting their own output, including dealing with any race
|
||||
* conditions due to writing in parallel to stdout and stderr.
|
||||
* The "ungroup" option can be enabled by setting the global
|
||||
* "run_processes_parallel_ungroup" to "1" before invoking
|
||||
* run_processes_parallel(), it will be set back to "0" as soon as the
|
||||
* API reads that setting.
|
||||
*/
|
||||
extern int run_processes_parallel_ungroup;
|
||||
void run_processes_parallel(size_t n,
|
||||
get_next_task_fn,
|
||||
start_failure_fn,
|
||||
task_finished_fn,
|
||||
void *pp_cb);
|
||||
void run_processes_parallel_tr2(size_t n, get_next_task_fn, start_failure_fn,
|
||||
task_finished_fn, void *pp_cb,
|
||||
void run_processes_parallel(const struct run_process_parallel_opts *opts);
|
||||
void run_processes_parallel_tr2(size_t processes, get_next_task_fn,
|
||||
start_failure_fn, task_finished_fn, void *pp_cb,
|
||||
const char *tr2_category, const char *tr2_label);
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user