| 1240 | } |
| 1241 | |
| 1242 | cbm_proc_poll_t cbm_subprocess_poll(cbm_subprocess_t *process, cbm_proc_result_t *out) { |
| 1243 | if (!process) { |
| 1244 | return CBM_PROC_POLL_ERROR; |
| 1245 | } |
| 1246 | int lifecycle = atomic_load_explicit(&process->lifecycle, memory_order_acquire); |
| 1247 | if (lifecycle == CBM_SUBPROCESS_TERMINAL) { |
| 1248 | if (out) { |
| 1249 | *out = process->result; |
| 1250 | } |
| 1251 | return CBM_PROC_POLL_TERMINAL; |
| 1252 | } |
| 1253 | if (lifecycle == CBM_SUBPROCESS_DRAINING) { |
| 1254 | cbm_tail_result_t tail = cbm_subprocess_poll_log(process, true); |
| 1255 | if (tail.status == CBM_TAIL_MORE) { |
| 1256 | return CBM_PROC_POLL_RUNNING; |
| 1257 | } |
| 1258 | if (tail.status == CBM_TAIL_ERROR) { |
| 1259 | cbm_log_error("subprocess.log_drain_failed", "reason", "io_error"); |
| 1260 | return cbm_subprocess_publish_terminal(process, out, false); |
| 1261 | } |
| 1262 | return cbm_subprocess_publish_terminal(process, out, true); |
| 1263 | } |
| 1264 | /* The one owner-thread tail batch for this public poll. Platform-specific |
| 1265 | * reap paths never tail again, preserving the exact per-poll work cap. */ |
| 1266 | (void)cbm_subprocess_poll_log(process, false); |
| 1267 | #ifdef _WIN32 |
| 1268 | return cbm_subprocess_poll_win(process, out); |
| 1269 | #else |
| 1270 | return cbm_subprocess_poll_posix(process, out); |
| 1271 | #endif |
| 1272 | } |
| 1273 | |
| 1274 | bool cbm_subprocess_request_cancel(cbm_subprocess_t *process) { |
| 1275 | if (!process) { |