| 1455 | } |
| 1456 | |
| 1457 | static void *application_job_thread(void *opaque) { |
| 1458 | cbm_daemon_application_job_t *job = opaque; |
| 1459 | application_job_execution_t execution; |
| 1460 | application_job_execution_init(&execution); |
| 1461 | /* Deterministic-interleaving seam: a held gate parks this thread before |
| 1462 | * its first pre-start cancel check, so tests can force the |
| 1463 | * cancel-wins-before-worker-start ordering that otherwise needs a |
| 1464 | * descheduled thread on a loaded runner (CI is never a lottery: the |
| 1465 | * interleaving must be reproducible by construction). */ |
| 1466 | while ( |
| 1467 | atomic_load_explicit(&g_application_hold_job_before_start_for_test, memory_order_acquire)) { |
| 1468 | cbm_usleep(1000); |
| 1469 | } |
| 1470 | |
| 1471 | /* The linked non-terminal job is the daemon-internal reservation: it |
| 1472 | * coalesces identical requests and blocks same-project daemon mutations. |
| 1473 | * The physical worker is the sole owner of the cross-process project lock, |
| 1474 | * so the daemon must not pre-acquire that same native lease here. */ |
| 1475 | if (!application_job_wait_for_mutations(job)) { |
| 1476 | application_job_execution_cancel(&execution); |
| 1477 | } else { |
| 1478 | application_attempt_t attempt; |
| 1479 | application_attempt_status_t status = |
| 1480 | application_job_run_attempt(job, NULL, NULL, &attempt); |
| 1481 | if (status == APPLICATION_ATTEMPT_CANCELLED) { |
| 1482 | application_job_execution_cancel(&execution); |
| 1483 | } else if (status == APPLICATION_ATTEMPT_TERMINAL) { |
| 1484 | cbm_proc_outcome_t failure_outcome = CBM_PROC_SPAWN_FAILED; |
| 1485 | application_attempt_decision_t decision = |
| 1486 | application_consume_attempt(job, &attempt, &execution, &failure_outcome); |
| 1487 | if (decision == APPLICATION_ATTEMPT_DECISION_RECOVERABLE) { |
| 1488 | application_job_recover(job, &execution); |
| 1489 | } |
| 1490 | } |
| 1491 | } |
| 1492 | application_job_publish(job, &execution); |
| 1493 | return NULL; |
| 1494 | } |
| 1495 | |
| 1496 | static cbm_daemon_application_job_t *application_find_job_locked( |
| 1497 | cbm_daemon_application_t *application, const char *project_key) { |
nothing calls this directly
no test coverage detected