| 1511 | } |
| 1512 | |
| 1513 | static void *application_job_thread(void *opaque) { |
| 1514 | cbm_daemon_application_job_t *job = opaque; |
| 1515 | application_job_execution_t execution; |
| 1516 | application_job_execution_init(&execution); |
| 1517 | /* Deterministic-interleaving seam: a held gate parks this thread before |
| 1518 | * its first pre-start cancel check, so tests can force the |
| 1519 | * cancel-wins-before-worker-start ordering that otherwise needs a |
| 1520 | * descheduled thread on a loaded runner (CI is never a lottery: the |
| 1521 | * interleaving must be reproducible by construction). */ |
| 1522 | while ( |
| 1523 | atomic_load_explicit(&g_application_hold_job_before_start_for_test, memory_order_acquire)) { |
| 1524 | cbm_usleep(1000); |
| 1525 | } |
| 1526 | |
| 1527 | /* The linked non-terminal job is the daemon-internal reservation: it |
| 1528 | * coalesces identical requests and blocks same-project daemon mutations. |
| 1529 | * The physical worker is the sole owner of the cross-process project lock, |
| 1530 | * so the daemon must not pre-acquire that same native lease here. */ |
| 1531 | if (!application_job_wait_for_mutations(job)) { |
| 1532 | application_job_execution_cancel(&execution); |
| 1533 | } else { |
| 1534 | application_attempt_t attempt; |
| 1535 | application_attempt_status_t status = |
| 1536 | application_job_run_attempt(job, NULL, NULL, &attempt); |
| 1537 | if (status == APPLICATION_ATTEMPT_CANCELLED) { |
| 1538 | application_job_execution_cancel(&execution); |
| 1539 | } else if (status == APPLICATION_ATTEMPT_TERMINAL) { |
| 1540 | cbm_proc_outcome_t failure_outcome = CBM_PROC_SPAWN_FAILED; |
| 1541 | application_attempt_decision_t decision = |
| 1542 | application_consume_attempt(job, &attempt, &execution, &failure_outcome); |
| 1543 | if (decision == APPLICATION_ATTEMPT_DECISION_RECOVERABLE) { |
| 1544 | application_job_recover(job, &execution); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | application_job_publish(job, &execution); |
| 1549 | return NULL; |
| 1550 | } |
| 1551 | |
| 1552 | static cbm_daemon_application_job_t *application_find_job_locked( |
| 1553 | cbm_daemon_application_t *application, const char *project_key) { |
nothing calls this directly
no test coverage detected