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

Function cbm_subprocess_poll_win

src/foundation/subprocess.c:1206–1259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1204}
1205
1206static cbm_proc_poll_t cbm_subprocess_poll_win(cbm_subprocess_t *process, cbm_proc_result_t *out) {
1207 uint64_t now = cbm_now_ms();
1208
1209 if (!process->root_reaped) {
1210 DWORD waited = WaitForSingleObject(process->process, 0);
1211 if (waited == WAIT_OBJECT_0) {
1212 DWORD code = 1;
1213 (void)GetExitCodeProcess(process->process, &code);
1214 cbm_win_capture_root(process, code);
1215 } else if (waited == WAIT_FAILED) {
1216 DWORD code = STILL_ACTIVE;
1217 if (GetExitCodeProcess(process->process, &code) && code != STILL_ACTIVE) {
1218 cbm_win_capture_root(process, code);
1219 } else {
1220 cbm_win_begin_termination(process, now);
1221 cbm_win_force_tree(process, now);
1222 }
1223 }
1224 }
1225
1226 bool job_known = false;
1227 bool job_active = cbm_win_job_active(process, &job_known);
1228 if (!process->termination_started) {
1229 if (cbm_subprocess_cancellation_requested(process)) {
1230 cbm_win_begin_termination(process, now);
1231 } else if (!process->root_reaped && process->quiet_timeout_ms > 0 &&
1232 now - process->last_activity_ms >= (uint64_t)process->quiet_timeout_ms) {
1233 process->timed_out = true;
1234 cbm_win_begin_termination(process, now);
1235 } else if (process->root_reaped && job_active) {
1236 /* Preserve the root's classification while draining escaped work. */
1237 cbm_win_begin_termination(process, now);
1238 }
1239 }
1240 if (!job_known) {
1241 cbm_win_begin_termination(process, now);
1242 cbm_win_force_tree(process, now);
1243 }
1244 if (process->termination_started && job_active && !process->force_sent &&
1245 now - process->termination_started_ms >= (uint64_t)process->cancel_grace_ms) {
1246 cbm_win_force_tree(process, now);
1247 }
1248 if (process->force_started_ms != 0 &&
1249 now - process->force_started_ms >= CBM_SUBPROCESS_FORCE_SETTLE_MS &&
1250 (!job_known || job_active || !process->root_reaped)) {
1251 cbm_win_capture_job_memory(process);
1252 return cbm_subprocess_finish_failed(process, out);
1253 }
1254 if (process->root_reaped && !job_active) {
1255 cbm_win_capture_job_memory(process);
1256 return cbm_subprocess_finish(process, out);
1257 }
1258 return CBM_PROC_POLL_RUNNING;
1259}
1260
1261#else /* POSIX */
1262

Callers 1

cbm_subprocess_pollFunction · 0.85

Calls 9

cbm_now_msFunction · 0.85
cbm_win_capture_rootFunction · 0.85
cbm_win_force_treeFunction · 0.85
cbm_win_job_activeFunction · 0.85
cbm_subprocess_finishFunction · 0.85

Tested by

no test coverage detected