| 183 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 184 | |
| 185 | void cbm_parallel_for(int count, cbm_parallel_fn fn, void *ctx, cbm_parallel_for_opts_t opts) { |
| 186 | if (count <= 0 || !fn) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | /* Determine worker count */ |
| 191 | int nworkers = opts.max_workers; |
| 192 | if (nworkers <= 0) { |
| 193 | nworkers = cbm_default_worker_count(true); |
| 194 | } |
| 195 | if (nworkers < WP_MIN) { |
| 196 | nworkers = SKIP_ONE; |
| 197 | } |
| 198 | |
| 199 | /* Serial fallback: single worker or trivially small workload */ |
| 200 | if (nworkers <= WP_MIN || count <= WP_MIN) { |
| 201 | run_serial(count, fn, ctx); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | #if defined(CBM_MEMWASTE) && CBM_MEMWASTE |
| 206 | if (cbm_memev_enabled()) { |
| 207 | run_pthreads_counted(count, fn, ctx, nworkers, __builtin_return_address(0)); |
| 208 | return; |
| 209 | } |
| 210 | #endif |
| 211 | run_pthreads(count, fn, ctx, nworkers); |
| 212 | } |
no test coverage detected