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

Function cbm_cursor_acquire

internal/cbm/cbm.c:977–998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

975enum { CURSOR_LIVE = 1, CURSOR_BUSY = 2 };
976
977TSTreeCursor *cbm_cursor_acquire(cbm_cursor_lease_t *lease, int depth, TSNode node) {
978 if (!tl_cursor_pool) {
979 tl_cursor_pool = cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(cursor_pool_t));
980 }
981 cursor_pool_t *pool = tl_cursor_pool;
982 if (pool && depth >= 0 && depth < CURSOR_POOL_DEPTH && !(pool->state[depth] & CURSOR_BUSY)) {
983 if (pool->state[depth] & CURSOR_LIVE) {
984 ts_tree_cursor_reset(&pool->cursors[depth], node);
985 } else {
986 pool->cursors[depth] = ts_tree_cursor_new(node);
987 }
988 pool->state[depth] = CURSOR_LIVE | CURSOR_BUSY;
989 lease->slot = depth;
990 lease->cursor = &pool->cursors[depth];
991 return lease->cursor;
992 }
993 /* No pool (or the slot is taken): a private cursor is always correct. */
994 lease->private_cursor = ts_tree_cursor_new(node);
995 lease->slot = -1;
996 lease->cursor = &lease->private_cursor;
997 return lease->cursor;
998}
999
1000void cbm_cursor_release(cbm_cursor_lease_t *lease) {
1001 if (lease->slot < 0) {

Callers 2

test_mem.cFile · 0.85

Calls 1

cbm_callocFunction · 0.85

Tested by

no test coverage detected