MCPcopy Create free account
hub / github.com/git/git / setup_workers

Function setup_workers

parallel-checkout.c:460–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460static struct pc_worker *setup_workers(struct checkout *state, int num_workers)
461{
462 struct pc_worker *workers;
463 int i, workers_with_one_extra_item;
464 size_t base_batch_size, batch_beginning = 0;
465
466 ALLOC_ARRAY(workers, num_workers);
467
468 for (i = 0; i < num_workers; i++) {
469 struct child_process *cp = &workers[i].cp;
470
471 child_process_init(cp);
472 cp->git_cmd = 1;
473 cp->in = -1;
474 cp->out = -1;
475 cp->clean_on_exit = 1;
476 strvec_push(&cp->args, "checkout--worker");
477 if (state->base_dir_len)
478 strvec_pushf(&cp->args, "--prefix=%s", state->base_dir);
479 if (start_command(cp))
480 die("failed to spawn checkout worker");
481 }
482
483 base_batch_size = parallel_checkout.nr / num_workers;
484 workers_with_one_extra_item = parallel_checkout.nr % num_workers;
485
486 for (i = 0; i < num_workers; i++) {
487 struct pc_worker *worker = &workers[i];
488 size_t batch_size = base_batch_size;
489
490 /* distribute the extra work evenly */
491 if (i < workers_with_one_extra_item)
492 batch_size++;
493
494 send_batch(worker->cp.in, batch_beginning, batch_size);
495 worker->next_item_to_complete = batch_beginning;
496 worker->nr_items_to_complete = batch_size;
497
498 batch_beginning += batch_size;
499 }
500
501 return workers;
502}
503
504static void finish_workers(struct pc_worker *workers, int num_workers)
505{

Callers 1

run_parallel_checkoutFunction · 0.85

Calls 6

child_process_initFunction · 0.85
strvec_pushFunction · 0.85
strvec_pushfFunction · 0.85
start_commandFunction · 0.85
send_batchFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected