| 1811 | } |
| 1812 | |
| 1813 | static void *application_job_thread(void *opaque) { |
| 1814 | cbm_daemon_application_job_t *job = opaque; |
| 1815 | application_job_execution_t execution; |
| 1816 | application_job_execution_init(&execution); |
| 1817 | /* Deterministic-interleaving seam: a held gate parks this thread before |
| 1818 | * its first pre-start cancel check, so tests can force the |
| 1819 | * cancel-wins-before-worker-start ordering that otherwise needs a |
| 1820 | * descheduled thread on a loaded runner (CI is never a lottery: the |
| 1821 | * interleaving must be reproducible by construction). */ |
| 1822 | while ( |
| 1823 | atomic_load_explicit(&g_application_hold_job_before_start_for_test, memory_order_acquire)) { |
| 1824 | cbm_usleep(1000); |
| 1825 | } |
| 1826 | |
| 1827 | /* The linked non-terminal job is the daemon-internal reservation: it |
| 1828 | * coalesces identical requests and blocks same-project daemon mutations. |
| 1829 | * The physical worker is the sole owner of the cross-process project lock, |
| 1830 | * so the daemon must not pre-acquire that same native lease here. */ |
| 1831 | if (!application_job_wait_for_mutations(job)) { |
| 1832 | application_job_execution_cancel(&execution); |
| 1833 | } else { |
| 1834 | application_attempt_t attempt; |
| 1835 | application_attempt_status_t status = |
| 1836 | application_job_run_attempt(job, NULL, NULL, &attempt); |
| 1837 | if (status == APPLICATION_ATTEMPT_CANCELLED) { |
| 1838 | application_job_execution_cancel(&execution); |
| 1839 | } else if (status == APPLICATION_ATTEMPT_TERMINAL) { |
| 1840 | cbm_proc_outcome_t failure_outcome = CBM_PROC_SPAWN_FAILED; |
| 1841 | application_attempt_decision_t decision = |
| 1842 | application_consume_attempt(job, &attempt, &execution, &failure_outcome); |
| 1843 | if (decision == APPLICATION_ATTEMPT_DECISION_RECOVERABLE) { |
| 1844 | application_job_recover(job, &execution); |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | application_job_publish(job, &execution); |
| 1849 | return NULL; |
| 1850 | } |
| 1851 | |
| 1852 | static cbm_daemon_application_job_t *application_find_job_locked( |
| 1853 | cbm_daemon_application_t *application, const char *project_key) { |
nothing calls this directly
no test coverage detected