MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_parallel_resolve

Function cbm_parallel_resolve

src/pipeline/pass_parallel.c:3165–3348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3163}
3164
3165int cbm_parallel_resolve(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files, int file_count,
3166 CBMFileResult **result_cache, _Atomic int64_t *shared_ids,
3167 int worker_count, CBMLSPDef *all_defs, int def_count,
3168 char *const *def_modules, struct CBMModuleDefIndex *module_def_index,
3169 void *cross_registries_v) {
3170 /* See header: typed as void* across the TU boundary; cast back here. */
3171 CBMCrossLspRegistries *cross_registries = (CBMCrossLspRegistries *)cross_registries_v;
3172 if (file_count == 0) {
3173 return 0;
3174 }
3175
3176 cbm_log_info("parallel.resolve.start", "files", itoa_log(file_count), "workers",
3177 itoa_log(worker_count));
3178
3179 resolve_worker_state_t *workers = NULL;
3180 if (cbm_aligned_alloc((void **)&workers, CBM_CACHE_LINE,
3181 (size_t)worker_count * sizeof(resolve_worker_state_t)) != 0) {
3182 return CBM_NOT_FOUND;
3183 }
3184 memset(workers, 0, (size_t)worker_count * sizeof(resolve_worker_state_t));
3185
3186 resolve_ctx_t rc = {
3187 .files = files,
3188 .file_count = file_count,
3189 .project_name = ctx->project_name,
3190 .repo_path = ctx->repo_path,
3191 .workers = workers,
3192 .max_workers = worker_count,
3193 .result_cache = result_cache,
3194 .main_gbuf = ctx->gbuf,
3195 .registry = ctx->registry,
3196 .shared_ids = shared_ids,
3197 .cancelled = ctx->cancelled,
3198 .all_defs = all_defs,
3199 .def_count = def_count,
3200 .def_modules = def_modules,
3201 .module_def_index = module_def_index,
3202 .cross_registries = cross_registries,
3203 };
3204 atomic_init(&rc.next_file_idx, 0);
3205 atomic_init(&rc.lsp_cross_processed, 0);
3206 atomic_init(&rc.lsp_cross_skipped_no_source, 0);
3207 /* F4 lazy shared Rust registry: mutex up before workers spawn. */
3208 atomic_init(&rc.rust_shared_reg, NULL);
3209 cbm_mutex_init(&rc.rust_shared_mu);
3210 rc.rust_shared_arena_live = false;
3211
3212 /* Sub-phase: Dispatch resolve workers (per-file call/usage resolution, PARALLEL) */
3213 CBM_PROF_START(t_resolve_dispatch);
3214 cbm_parallel_for_opts_t opts = {.max_workers = worker_count, .force_pthreads = false};
3215 cbm_parallel_for(worker_count, resolve_worker, &rc, opts);
3216 CBM_PROF_END_N("parallel_resolve", "1_dispatch_workers_parallel", t_resolve_dispatch,
3217 file_count);
3218 /* Workers joined: the shared Rust registry (if built) is no longer read.
3219 * Free its dedicated arena + the lock (registry was self-contained: it strdup'd
3220 * all QNs, so freeing all_defs afterward is safe). */
3221 if (rc.rust_shared_arena_live) {
3222 cbm_arena_destroy(&rc.rust_shared_arena);

Callers 3

run_extract_resolveFunction · 0.85
run_parallel_pipelineFunction · 0.85

Calls 11

cbm_aligned_allocFunction · 0.85
cbm_mutex_initFunction · 0.85
cbm_parallel_forFunction · 0.85
cbm_mutex_destroyFunction · 0.85
cbm_gbuf_mergeFunction · 0.85
cbm_gbuf_freeFunction · 0.85
cbm_aligned_freeFunction · 0.85
itoa_logFunction · 0.70
cbm_arena_destroyFunction · 0.50