| 1338 | } |
| 1339 | |
| 1340 | cbm_proc_poll_t cbm_subprocess_poll(cbm_subprocess_t *process, cbm_proc_result_t *out) { |
| 1341 | if (!process) { |
| 1342 | return CBM_PROC_POLL_ERROR; |
| 1343 | } |
| 1344 | int lifecycle = atomic_load_explicit(&process->lifecycle, memory_order_acquire); |
| 1345 | if (lifecycle == CBM_SUBPROCESS_TERMINAL) { |
| 1346 | if (out) { |
| 1347 | *out = process->result; |
| 1348 | } |
| 1349 | return CBM_PROC_POLL_TERMINAL; |
| 1350 | } |
| 1351 | if (lifecycle == CBM_SUBPROCESS_DRAINING) { |
| 1352 | cbm_tail_result_t tail = cbm_subprocess_poll_log(process, true); |
| 1353 | if (tail.status == CBM_TAIL_MORE) { |
| 1354 | return CBM_PROC_POLL_RUNNING; |
| 1355 | } |
| 1356 | if (tail.status == CBM_TAIL_ERROR) { |
| 1357 | cbm_log_error("subprocess.log_drain_failed", "reason", "io_error"); |
| 1358 | return cbm_subprocess_publish_terminal(process, out, false); |
| 1359 | } |
| 1360 | return cbm_subprocess_publish_terminal(process, out, true); |
| 1361 | } |
| 1362 | /* The one owner-thread tail batch for this public poll. Platform-specific |
| 1363 | * reap paths never tail again, preserving the exact per-poll work cap. */ |
| 1364 | (void)cbm_subprocess_poll_log(process, false); |
| 1365 | #ifdef _WIN32 |
| 1366 | return cbm_subprocess_poll_win(process, out); |
| 1367 | #else |
| 1368 | return cbm_subprocess_poll_posix(process, out); |
| 1369 | #endif |
| 1370 | } |
| 1371 | |
| 1372 | bool cbm_subprocess_request_cancel(cbm_subprocess_t *process) { |
| 1373 | if (!process) { |