// carve_push_box.h - Box Carve-And-Push // Priority 2 Box: Atomic Block Carving and TLS SLL Push // // Purpose: // - Prevent rollback bugs (root cause of 20-carved-but-16-pushed issue) // - Atomic operation: carve + header + push (all-or-nothing) // - Eliminate partial failures that leave orphaned blocks // // Design: // - Wraps trc_linear_carve() + tls_sll_push() // - Rollback on any failure // - Active counter management built-in // - Clear error reporting #ifndef HAKMEM_BOX_CARVE_PUSH_H #define HAKMEM_BOX_CARVE_PUSH_H #include #include // ============================================================================ // Box Carve-Push API // ============================================================================ // Carve N blocks from current TLS slab and atomically push to TLS SLL // // Guarantees: // - All-or-nothing: either all N blocks are pushed, or none // - No orphaned blocks (carved but not pushed) // - Headers written correctly before push // - Active counters updated atomically // // Returns: actual count pushed // - On success: want (all blocks pushed) // - On failure: 0 (rolled back, no blocks pushed) // // Failure cases: // - No SuperSlab available // - Slab exhausted (capacity reached) // - TLS SLL capacity exceeded // - Invalid class_idx // // Thread-safe: uses TLS uint32_t box_carve_and_push(int class_idx, uint32_t want); // Variant: carve and push with freelist fallback // If slab is exhausted, tries to pop from freelist first // Same guarantees as box_carve_and_push() uint32_t box_carve_and_push_with_freelist(int class_idx, uint32_t want); #endif // HAKMEM_BOX_CARVE_PUSH_H