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

Function cbm_watcher_poll_once

src/watcher/watcher.c:1727–1767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1725}
1726
1727int cbm_watcher_poll_once(cbm_watcher_t *w) {
1728 if (!w) {
1729 return 0;
1730 }
1731
1732 /* Snapshot project pointers under lock, then poll without holding it.
1733 * This keeps the critical section small — poll_project does git I/O
1734 * and may invoke index_fn which runs the full pipeline. */
1735 cbm_mutex_lock(&w->projects_lock);
1736
1737 /* Free deferred entries from the previous cycle. */
1738 for (int i = 0; i < w->pending_free_count; i++) {
1739 state_free(w->pending_free[i]);
1740 }
1741 w->pending_free_count = 0;
1742
1743 int n = cbm_ht_count(w->projects);
1744 if (n == 0) {
1745 cbm_mutex_unlock(&w->projects_lock);
1746 return 0;
1747 }
1748 project_state_t **snap = malloc(n * sizeof(project_state_t *));
1749 if (!snap) {
1750 cbm_mutex_unlock(&w->projects_lock);
1751 return 0;
1752 }
1753 snapshot_ctx_t sc = {.items = snap, .count = 0, .cap = n};
1754 cbm_ht_foreach(w->projects, snapshot_project, &sc);
1755 cbm_mutex_unlock(&w->projects_lock);
1756
1757 poll_ctx_t ctx = {
1758 .w = w,
1759 .now = now_ns(),
1760 .reindexed = 0,
1761 };
1762 for (int i = 0; i < sc.count; i++) {
1763 poll_project(NULL, snap[i], &ctx);
1764 }
1765 free(snap);
1766 return ctx.reindexed;
1767}
1768
1769/* ── Blocking run loop ──────────────────────────────────────────── */
1770

Callers 5

cbm_watcher_runFunction · 0.85
test_watcher.cFile · 0.85
wt_poll_until_countFunction · 0.85
nongit_pollFunction · 0.85

Calls 7

cbm_mutex_lockFunction · 0.85
state_freeFunction · 0.85
cbm_ht_countFunction · 0.85
cbm_mutex_unlockFunction · 0.85
cbm_ht_foreachFunction · 0.85
poll_projectFunction · 0.85
now_nsFunction · 0.70

Tested by 2

wt_poll_until_countFunction · 0.68
nongit_pollFunction · 0.68