// Inline helpers for Background Refill Bin (lock-free SLL) // This header is textually included from hakmem_tiny.c after the following // symbols are defined: // - g_bg_bin_enable, g_bg_bin_head[] #include "box/tiny_next_ptr_box.h" // Phase E1-CORRECT: Box API for next pointer static inline void* bgbin_pop(int class_idx) { if (!g_bg_bin_enable) return NULL; uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire); while (h != 0) { void* p = (void*)h; // Phase E1-CORRECT: Use Box API for next pointer read uintptr_t next = (uintptr_t)tiny_next_read(class_idx, p); if (atomic_compare_exchange_weak_explicit(&g_bg_bin_head[class_idx], &h, next, memory_order_acq_rel, memory_order_acquire)) { #if HAKMEM_DEBUG_COUNTERS g_bgbin_pops[class_idx]++; #endif return p; } } return NULL; } static inline void bgbin_push_chain(int class_idx, void* chain_head, void* chain_tail) { if (!chain_head) return; uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire); // Phase E1-CORRECT: Use Box API for next pointer write do { tiny_next_write(class_idx, chain_tail, (void*)h); } while (!atomic_compare_exchange_weak_explicit(&g_bg_bin_head[class_idx], &h, (uintptr_t)chain_head, memory_order_acq_rel, memory_order_acquire)); } static inline int bgbin_length_approx(int class_idx, int cap) { uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire); int n = 0; while (h && n < cap) { void* p = (void*)h; // Phase E1-CORRECT: Use Box API for next pointer read h = (uintptr_t)tiny_next_read(class_idx, p); n++; } return n; }