xref: /haiku/headers/private/kernel/slab/Slab.h (revision 3be9edf8da228afd9fec0390f408c964766122aa)
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 <KernelExport.h>
12 #include <OS.h>
13 
14 
15 enum {
16 	/* create_object_cache_etc flags */
17 	CACHE_NO_DEPOT			= 1 << 0,
18 	CACHE_UNLOCKED_PAGES	= 1 << 1,
19 	CACHE_LARGE_SLAB		= 1 << 2,
20 
21 	/* object_cache_alloc flags */
22 	CACHE_DONT_SLEEP		= 1 << 8,
23 
24 	/* internal */
25 	CACHE_DURING_BOOT		= 1 << 31
26 };
27 
28 typedef struct object_cache object_cache;
29 
30 typedef status_t (*object_cache_constructor)(void *cookie, void *object);
31 typedef void (*object_cache_destructor)(void *cookie, void *object);
32 typedef void (*object_cache_reclaimer)(void *cookie, int32 level);
33 
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 object_cache *create_object_cache(const char *name, size_t object_size,
40 	size_t alignment, void *cookie, object_cache_constructor constructor,
41 	object_cache_destructor);
42 object_cache *create_object_cache_etc(const char *name, size_t object_size,
43 	size_t alignment, size_t max_byte_usage, uint32 flags, void *cookie,
44 	object_cache_constructor constructor, object_cache_destructor destructor,
45 	object_cache_reclaimer reclaimer);
46 
47 void delete_object_cache(object_cache *cache);
48 
49 status_t object_cache_set_minimum_reserve(object_cache *cache,
50 	size_t objectCount);
51 
52 void *object_cache_alloc(object_cache *cache, uint32 flags);
53 void object_cache_free(object_cache *cache, void *object);
54 
55 status_t object_cache_reserve(object_cache *cache, size_t object_count,
56 	uint32 flags);
57 
58 void object_cache_get_usage(object_cache *cache, size_t *_allocatedMemory);
59 
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif	/* _SLAB_SLAB_H_ */
65