| 94 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 95 | |
| 96 | void cbm_parallel_for(int count, cbm_parallel_fn fn, void *ctx, cbm_parallel_for_opts_t opts) { |
| 97 | if (count <= 0 || !fn) { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | /* Determine worker count */ |
| 102 | int nworkers = opts.max_workers; |
| 103 | if (nworkers <= 0) { |
| 104 | nworkers = cbm_default_worker_count(true); |
| 105 | } |
| 106 | if (nworkers < WP_MIN) { |
| 107 | nworkers = SKIP_ONE; |
| 108 | } |
| 109 | |
| 110 | /* Serial fallback: single worker or trivially small workload */ |
| 111 | if (nworkers <= WP_MIN || count <= WP_MIN) { |
| 112 | run_serial(count, fn, ctx); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | run_pthreads(count, fn, ctx, nworkers); |
| 117 | } |
no test coverage detected