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 static const size_t kMinObjectAlignment = 8;
18
19
20 void request_memory_manager_maintenance();
21
22 void* block_alloc_early(size_t size);
23 void block_allocator_init_boot();
24 void block_allocator_init_rest();
25
26
27 template<typename Type>
28 static inline Type*
_pop(Type * & head)29 _pop(Type*& head)
30 {
31 Type* oldHead = head;
32 head = head->next;
33 return oldHead;
34 }
35
36
37 template<typename Type>
38 static inline void
_push(Type * & head,Type * object)39 _push(Type*& head, Type* object)
40 {
41 object->next = head;
42 head = object;
43 }
44
45
46 static inline void*
slab_internal_alloc(size_t size,uint32 flags)47 slab_internal_alloc(size_t size, uint32 flags)
48 {
49 if (flags & CACHE_DURING_BOOT)
50 return block_alloc_early(size);
51
52 return malloc_etc(size, flags);
53 }
54
55
56 static inline void
slab_internal_free(void * buffer,uint32 flags)57 slab_internal_free(void* buffer, uint32 flags)
58 {
59 free_etc(buffer, flags);
60 }
61
62
63 #endif // SLAB_PRIVATE_H
64