1 /* 2 * Copyright 2008, Axel Dörfler. All Rights Reserved. 3 * Copyright 2007, Hugo Santos. All Rights Reserved. 4 * 5 * Distributed under the terms of the MIT License. 6 */ 7 #ifndef _SLAB_SLAB_H_ 8 #define _SLAB_SLAB_H_ 9 10 11 #include <heap.h> 12 13 14 enum { 15 /* object_cache_{alloc,free}() flags */ 16 CACHE_DONT_WAIT_FOR_MEMORY = HEAP_DONT_WAIT_FOR_MEMORY, 17 CACHE_DONT_LOCK_KERNEL_SPACE = HEAP_DONT_LOCK_KERNEL_SPACE, 18 CACHE_PRIORITY_VIP = HEAP_PRIORITY_VIP, 19 CACHE_ALLOC_FLAGS = CACHE_DONT_WAIT_FOR_MEMORY 20 | CACHE_DONT_LOCK_KERNEL_SPACE 21 | CACHE_PRIORITY_VIP, 22 23 /* create_object_cache_etc flags */ 24 CACHE_NO_DEPOT = 0x08000000, 25 CACHE_UNLOCKED_PAGES = 0x10000000, // unsupported 26 CACHE_LARGE_SLAB = 0x20000000, 27 28 /* internal */ 29 CACHE_ALIGN_ON_SIZE = 0x40000000, 30 CACHE_DURING_BOOT = 0x80000000 31 }; 32 33 struct ObjectCache; 34 typedef struct ObjectCache object_cache; 35 36 typedef status_t (*object_cache_constructor)(void* cookie, void* object); 37 typedef void (*object_cache_destructor)(void* cookie, void* object); 38 typedef void (*object_cache_reclaimer)(void* cookie, int32 level); 39 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 object_cache* create_object_cache(const char* name, size_t object_size, 46 size_t alignment, void* cookie, object_cache_constructor constructor, 47 object_cache_destructor); 48 object_cache* create_object_cache_etc(const char* name, size_t object_size, 49 size_t alignment, size_t max_byte_usage, uint32 flags, void* cookie, 50 object_cache_constructor constructor, object_cache_destructor destructor, 51 object_cache_reclaimer reclaimer); 52 53 void delete_object_cache(object_cache* cache); 54 55 status_t object_cache_set_minimum_reserve(object_cache* cache, 56 size_t objectCount); 57 58 void* object_cache_alloc(object_cache* cache, uint32 flags); 59 void object_cache_free(object_cache* cache, void* object, uint32 flags); 60 61 status_t object_cache_reserve(object_cache* cache, size_t object_count, 62 uint32 flags); 63 64 void object_cache_get_usage(object_cache* cache, size_t* _allocatedMemory); 65 66 #ifdef __cplusplus 67 } 68 #endif 69 70 #endif /* _SLAB_SLAB_H_ */ 71