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

Function apply_signed

src/foundation/mem_core.c:114–128  ·  view source on GitHub ↗

live += delta, never wrapping below zero: a mismatched class on free (the * one way a caller can get this wrong) must not turn a small drift into a * colossal bogus number that looks like a leak. Returns the new value. */

Source from the content-addressed store, hash-verified

112 * one way a caller can get this wrong) must not turn a small drift into a
113 * colossal bogus number that looks like a leak. Returns the new value. */
114static size_t apply_signed(atomic_size_t *counter, long delta) {
115 if (delta >= 0) {
116 return atomic_fetch_add_explicit(counter, (size_t)delta, memory_order_relaxed) +
117 (size_t)delta;
118 }
119 size_t sub = (size_t)(-delta);
120 size_t seen = atomic_load_explicit(counter, memory_order_relaxed);
121 while (true) {
122 size_t want = sub > seen ? 0 : seen - sub;
123 if (atomic_compare_exchange_weak_explicit(counter, &seen, want, memory_order_relaxed,
124 memory_order_relaxed)) {
125 return want;
126 }
127 }
128}
129
130static void class_flush_one(cbm_mem_class_t cls) {
131 mem_delta_t *d = &tl_delta[cls];

Callers 1

class_flush_oneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected