1 |
/* slab.h - The GNU Hurd slab allocator interface. |
/* slab.h - The GNU Hurd slab allocator interface. |
2 |
Copyright (C) 2003 Free Software Foundation, Inc. |
Copyright (C) 2003, 2005 Free Software Foundation, Inc. |
3 |
Written by Marcus Brinkmann <marcus@gnu.org> |
Written by Marcus Brinkmann <marcus@gnu.org> |
4 |
|
|
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
27 |
#include <pthread.h> |
#include <pthread.h> |
28 |
|
|
29 |
|
|
30 |
|
/* Allocate a buffer in *PTR of size SIZE which must be a power of 2 |
31 |
|
and self aligned (i.e. aligned on a SIZE byte boundary). HOOK is |
32 |
|
as provided to hurd_slab_create. Return 0 on success, an error |
33 |
|
code on failure. */ |
34 |
|
typedef error_t (*hurd_slab_allocate_buffer_t) (void *hook, size_t size, |
35 |
|
void **ptr); |
36 |
|
|
37 |
|
/* Deallocate buffer BUFFER of size SIZE. HOOK is as provided to |
38 |
|
hurd_slab_create. */ |
39 |
|
typedef error_t (*hurd_slab_deallocate_buffer_t) (void *hook, void *buffer, |
40 |
|
size_t size); |
41 |
|
|
42 |
/* Initialize the slab object pointed to by BUFFER. HOOK is as |
/* Initialize the slab object pointed to by BUFFER. HOOK is as |
43 |
provided to hurd_slab_create. */ |
provided to hurd_slab_create. */ |
44 |
typedef error_t (*hurd_slab_constructor_t) (void *hook, void *buffer); |
typedef error_t (*hurd_slab_constructor_t) (void *hook, void *buffer); |
75 |
size_t requested_size; |
size_t requested_size; |
76 |
size_t requested_align; |
size_t requested_align; |
77 |
|
|
78 |
|
/* The buffer allocator. */ |
79 |
|
hurd_slab_allocate_buffer_t allocate_buffer; |
80 |
|
|
81 |
|
/* The buffer deallocator. */ |
82 |
|
hurd_slab_deallocate_buffer_t deallocate_buffer; |
83 |
|
|
84 |
/* The constructor. */ |
/* The constructor. */ |
85 |
hurd_slab_constructor_t constructor; |
hurd_slab_constructor_t constructor; |
86 |
|
|
112 |
|
|
113 |
|
|
114 |
/* Static initializer. TYPE is used to get size and alignment of |
/* Static initializer. TYPE is used to get size and alignment of |
115 |
objects the slab space will be used to allocate. CTOR and DTOR is |
objects the slab space will be used to allocate. ALLOCATE_BUFFER |
116 |
constructor and destructor, respectivly. HOOK is passed as user |
may be NULL in which case mmap is called. DEALLOCATE_BUFFER may be |
117 |
data to the constructor and destructor. */ |
NULL in which case munmap is called. CTOR and DTOR are the slab's |
118 |
#define HURD_SLAB_SPACE_INITIALIZER(TYPE, CTOR, DTOR, HOOK) \ |
object constructor and destructor, respectivly and may be NULL if |
119 |
|
not required. HOOK is passed as user data to the constructor and |
120 |
|
destructor. */ |
121 |
|
#define HURD_SLAB_SPACE_INITIALIZER(TYPE, ALLOC, DEALLOC, CTOR, \ |
122 |
|
DTOR, HOOK) \ |
123 |
{ \ |
{ \ |
124 |
false, \ |
false, \ |
125 |
PTHREAD_MUTEX_INITIALIZER, \ |
PTHREAD_MUTEX_INITIALIZER, \ |
126 |
sizeof (TYPE), \ |
sizeof (TYPE), \ |
127 |
__alignof__ (TYPE), \ |
__alignof__ (TYPE), \ |
128 |
|
ALLOC, \ |
129 |
|
DEALLOC, \ |
130 |
CTOR, \ |
CTOR, \ |
131 |
DTOR, \ |
DTOR, \ |
132 |
HOOK \ |
HOOK \ |
136 |
|
|
137 |
|
|
138 |
/* Create a new slab space with the given object size, alignment, |
/* Create a new slab space with the given object size, alignment, |
139 |
constructor and destructor. ALIGNMENT can be zero. HOOK is passed |
constructor and destructor. ALIGNMENT can be zero. |
140 |
as the first argument to the constructor and destructor. */ |
ALLOCATE_BUFFER may be NULL in which case mmap is called. |
141 |
|
DEALLOCATE_BUFFER may be NULL in which case munmap is called. CTOR |
142 |
|
and DTOR are the slabs object constructor and destructor, |
143 |
|
respectivly and may be NULL if not required. HOOK is passed as the |
144 |
|
first argument to the constructor and destructor. */ |
145 |
error_t hurd_slab_create (size_t size, size_t alignment, |
error_t hurd_slab_create (size_t size, size_t alignment, |
146 |
|
hurd_slab_allocate_buffer_t allocate_buffer, |
147 |
|
hurd_slab_deallocate_buffer_t deallocate_buffer, |
148 |
hurd_slab_constructor_t constructor, |
hurd_slab_constructor_t constructor, |
149 |
hurd_slab_destructor_t destructor, |
hurd_slab_destructor_t destructor, |
150 |
void *hook, |
void *hook, |
152 |
|
|
153 |
/* Like hurd_slab_create, but does not allocate storage for the slab. */ |
/* Like hurd_slab_create, but does not allocate storage for the slab. */ |
154 |
error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, |
error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, |
155 |
|
hurd_slab_allocate_buffer_t allocate_buffer, |
156 |
|
hurd_slab_deallocate_buffer_t deallocate_buffer, |
157 |
hurd_slab_constructor_t constructor, |
hurd_slab_constructor_t constructor, |
158 |
hurd_slab_destructor_t destructor, |
hurd_slab_destructor_t destructor, |
159 |
void *hook); |
void *hook); |