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

Function cbm_watcher_run

src/watcher/watcher.c:1795–1824  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1793}
1794
1795int cbm_watcher_run(cbm_watcher_t *w, int base_interval_ms) {
1796 if (!w) {
1797 return CBM_NOT_FOUND;
1798 }
1799 if (base_interval_ms <= 0) {
1800 base_interval_ms = POLL_BASE_MS;
1801 }
1802
1803 atomic_store_explicit(&w->running, true, memory_order_release);
1804 cbm_log_info("watcher.start", "interval_ms", base_interval_ms > 999 ? "multi-sec" : "fast");
1805
1806 while (!atomic_load(&w->stopped)) {
1807 cbm_watcher_poll_once(w);
1808
1809 /* Sleep in small increments to allow responsive shutdown */
1810 int slept = 0;
1811 while (slept < base_interval_ms && !atomic_load(&w->stopped)) {
1812 int chunk = base_interval_ms - slept;
1813 if (chunk > SLEEP_CHUNK_MS) {
1814 chunk = SLEEP_CHUNK_MS;
1815 }
1816 cbm_usleep((unsigned)chunk * CBM_MSEC_PER_SEC);
1817 slept += chunk;
1818 }
1819 }
1820
1821 atomic_store_explicit(&w->running, false, memory_order_release);
1822 cbm_log_info("watcher.stop");
1823 return 0;
1824}
1825
1826#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
1827/* Test seam: expose one project's dirty-state signatures so a failing

Callers 6

host_watcher_threadFunction · 0.85
test_watcher.cFile · 0.85
ui_health_watcher_runFunction · 0.85

Calls 1

cbm_watcher_poll_onceFunction · 0.85

Tested by 4

ui_health_watcher_runFunction · 0.68