1 /* 2 * Copyright 2007, Hugo Santos. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hugo Santos, hugosantos@gmail.com 7 */ 8 #ifndef SLAB_PRIVATE_H 9 #define SLAB_PRIVATE_H 10 11 12 #include <stddef.h> 13 14 #include <slab/Slab.h> 15 16 17 //#define TRACE_SLAB 18 #ifdef TRACE_SLAB 19 #define TRACE_CACHE(cache, format, args...) \ 20 dprintf("Cache[%p, %s] " format "\n", cache, cache->name , ##args) 21 #else 22 #define TRACE_CACHE(cache, format, bananas...) do { } while (0) 23 #endif 24 25 26 #define COMPONENT_PARANOIA_LEVEL OBJECT_CACHE_PARANOIA 27 #include <debug_paranoia.h> 28 29 struct ObjectCache; 30 struct object_depot; 31 32 33 void request_memory_manager_maintenance(); 34 35 void* block_alloc(size_t size, size_t alignment, uint32 flags); 36 void* block_alloc_early(size_t size); 37 void block_free(void* block, uint32 flags); 38 void block_allocator_init_boot(); 39 void block_allocator_init_rest(); 40 41 void dump_object_depot(object_depot* depot); 42 int dump_object_depot(int argCount, char** args); 43 int dump_depot_magazine(int argCount, char** args); 44 45 46 template<typename Type> 47 static inline Type* 48 _pop(Type*& head) 49 { 50 Type* oldHead = head; 51 head = head->next; 52 return oldHead; 53 } 54 55 56 template<typename Type> 57 static inline void 58 _push(Type*& head, Type* object) 59 { 60 object->next = head; 61 head = object; 62 } 63 64 65 static inline void* 66 slab_internal_alloc(size_t size, uint32 flags) 67 { 68 if (flags & CACHE_DURING_BOOT) 69 return block_alloc_early(size); 70 71 return block_alloc(size, 0, flags); 72 } 73 74 75 static inline void 76 slab_internal_free(void* buffer, uint32 flags) 77 { 78 block_free(buffer, flags); 79 } 80 81 82 #endif // SLAB_PRIVATE_H 83