diff options
author | neal <neal> | 2005-06-22 10:18:09 +0000 |
---|---|---|
committer | neal <neal> | 2005-06-22 10:18:09 +0000 |
commit | 7591b1a5af58f5e051260df7684c7300d8417a16 (patch) | |
tree | 5de2b7c92681529c4c88242845c7da59bf7b080a /libhurd-slab | |
parent | 0acc3da2883a9f05552a3f67ff107deae3e1b8e4 (diff) |
libhurd-slab/
2005-06-22 Neal H. Walfield <neal@gnu.org>
* slab.h: Clean up comments.
(SLAB_CLASS): New macro.
physmem/
2005-06-22 Neal H. Walfield <neal@gnu.org>
* priv.h (frame_entry_init): Declare.
(frame_init): Declare.
* physmem.c (main): Call frame_entry_init and frame_init.
* frame-entry.c: Create a frame_entry slab class. Don't use
HURD_SLAB_SPACE_INITIALIZER to initialize frame_entry_space. Do
it ...
(frame_entry_init): ... here with hurd_frame_entry_slab_init.
(frame_entry_constructor): Update argument type given stronger
type checking.
(frame_entry_alloc): Call hurd_frame_entry_slab_alloc, not
hurd_slab_alloc.
(frame_entry_free): Call hurd_frame_entry_slab_dealloc, not
hurd_slab_dealloc.
* frame.c: Create a frame slab class. Don't use
HURD_SLAB_SPACE_INITIALIZER to initialize frame_space. Do it ...
(frame_init): ... here with hurd_frame_slab_init.
(frame_constructor): Update argument type given stronger type
checking.
(frame_alloc): Call hurd_frame_slab_alloc, not hurd_slab_alloc.
(frame_free): Call hurd_frame_slab_dealloc, not hurd_slab_dealloc.
Diffstat (limited to 'libhurd-slab')
-rw-r--r-- | libhurd-slab/ChangeLog | 5 | ||||
-rw-r--r-- | libhurd-slab/slab.h | 171 |
2 files changed, 170 insertions, 6 deletions
diff --git a/libhurd-slab/ChangeLog b/libhurd-slab/ChangeLog index 378834f..059255f 100644 --- a/libhurd-slab/ChangeLog +++ b/libhurd-slab/ChangeLog @@ -1,3 +1,8 @@ +2005-06-22 Neal H. Walfield <neal@gnu.org> + + * slab.h: Clean up comments. + (SLAB_CLASS): New macro. + 2005-01-06 Neal H. Walfield <neal@gnu.org> * slab.h (hurd_slab_allocate_buffer_t): New type. diff --git a/libhurd-slab/slab.h b/libhurd-slab/slab.h index 3fa854c..8ac30d6 100644 --- a/libhurd-slab/slab.h +++ b/libhurd-slab/slab.h @@ -150,6 +150,12 @@ error_t hurd_slab_create (size_t size, size_t alignment, void *hook, hurd_slab_space_t *space); +/* Destroy all objects and the slab space SPACE. If there were no + outstanding allocations free the slab space. Returns EBUSY if + there are still allocated objects in the slab space. The dual of + hurd_slab_create. */ +error_t hurd_slab_free (hurd_slab_space_t space); + /* Like hurd_slab_create, but does not allocate storage for the slab. */ error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, hurd_slab_allocate_buffer_t allocate_buffer, @@ -159,7 +165,8 @@ error_t hurd_slab_init (hurd_slab_space_t space, size_t size, size_t alignment, void *hook); /* Destroy all objects and the slab space SPACE. Returns EBUSY if - there are still allocated objects in the slab. */ + there are still allocated objects in the slab. The dual of + hurd_slab_init. */ error_t hurd_slab_destroy (hurd_slab_space_t space); /* Allocate a new object from the slab space SPACE. */ @@ -167,10 +174,162 @@ error_t hurd_slab_alloc (hurd_slab_space_t space, void **buffer); /* Deallocate the object BUFFER from the slab space SPACE. */ void hurd_slab_dealloc (hurd_slab_space_t space, void *buffer); - -/* Destroy all objects and the slab space SPACE. If there were no - outstanding allocations free the slab space. Returns EBUSY if - there are still allocated objects in the slab space. */ -error_t hurd_slab_free (hurd_slab_space_t space); + +/* Create a more strongly typed slab interface a la a C++ template. + + NAME is the name of the new slab class. NAME is used to synthesize + names for the class types and methods using the following rule: the + hurd_ namespace will prefix all method names followed by NAME + followed by an underscore and finally the method name. The + following are thus exposed: + + Types: + struct hurd_NAME_slab_space + hurd_NAME_slab_space_t + + error_t (*hurd_NAME_slab_constructor_t) (void *hook, element_type *buffer) + void (*hurd_NAME_slab_destructor_t) (void *hook, element_type *buffer) + + Functions: + error_t hurd_NAME_slab_create (hurd_slab_allocate_buffer_t + allocate_buffer, + hurd_slab_deallocate_buffer_t + deallocate_buffer, + hurd_NAME_slab_constructor_t constructor, + hurd_NAME_slab_destructor_t destructor, + void *hook, + hurd_NAME_slab_space_t *space); + error_t hurd_NAME_slab_free (hurd_NAME_slab_space_t space); + + error_t hurd_NAME_slab_init (hurd_NAME_slab_space_t space, + hurd_slab_allocate_buffer_t allocate_buffer, + hurd_slab_deallocate_buffer_t + deallocate_buffer, + hurd_NAME_slab_constructor_t constructor, + hurd_NAME_slab_destructor_t destructor, + void *hook); + error_t hurd_NAME_slab_destroy (hurd_NAME_slab_space_t space); + + error_t hurd_NAME_slab_alloc (hurd_NAME_slab_space_t space, + element_type **buffer); + void hurd_NAME_slab_dealloc (hurd_NAME_slab_space_t space, + element_type *buffer); + + ELEMENT_TYPE is the type of elements to store in the slab. If you + want the slab to contain struct foo, pass `struct foo' as the + ELEMENT_TYPE (not `struct foo *'!!!). + +*/ +#define SLAB_CLASS(name, element_type) \ +struct hurd_##name##_slab_space \ +{ \ + struct hurd_slab_space space; \ +}; \ +typedef struct hurd_##name##_slab_space *hurd_##name##_slab_space_t; \ + \ +typedef error_t (*hurd_##name##_slab_constructor_t) (void *hook, \ + element_type *buffer); \ + \ +typedef void (*hurd_##name##_slab_destructor_t) (void *hook, \ + element_type *buffer); \ + \ +static inline error_t \ +hurd_##name##_slab_create (hurd_slab_allocate_buffer_t allocate_buffer, \ + hurd_slab_deallocate_buffer_t deallocate_buffer, \ + hurd_##name##_slab_constructor_t constructor, \ + hurd_##name##_slab_destructor_t destructor, \ + void *hook, \ + hurd_##name##_slab_space_t *space) \ +{ \ + union \ + { \ + hurd_##name##_slab_constructor_t t; \ + hurd_slab_constructor_t u; \ + } con; \ + union \ + { \ + hurd_##name##_slab_destructor_t t; \ + hurd_slab_destructor_t u; \ + } des; \ + union \ + { \ + hurd_##name##_slab_space_t *t; \ + hurd_slab_space_t *u; \ + } foo; \ + con.t = constructor; \ + des.t = destructor; \ + foo.t = space; \ + \ + return hurd_slab_create(sizeof (element_type), __alignof__ (element_type), \ + allocate_buffer, deallocate_buffer, \ + con.u, des.u, hook, foo.u); \ +} \ + \ +static inline error_t \ +hurd_##name##_slab_free (hurd_##name##_slab_space_t space) \ +{ \ + return hurd_slab_free (&space->space); \ +} \ + \ +static inline error_t \ +hurd_##name##_slab_init (hurd_##name##_slab_space_t space, \ + hurd_slab_allocate_buffer_t allocate_buffer, \ + hurd_slab_deallocate_buffer_t deallocate_buffer, \ + hurd_##name##_slab_constructor_t constructor, \ + hurd_##name##_slab_destructor_t destructor, \ + void *hook) \ +{ \ + union \ + { \ + hurd_##name##_slab_constructor_t t; \ + hurd_slab_constructor_t u; \ + } con; \ + union \ + { \ + hurd_##name##_slab_destructor_t t; \ + hurd_slab_destructor_t u; \ + } des; \ + con.t = constructor; \ + des.t = destructor; \ + \ + return hurd_slab_init (&space->space, \ + sizeof (element_type), __alignof__ (element_type), \ + allocate_buffer, deallocate_buffer, \ + con.u, des.u, hook); \ +} \ + \ +static inline error_t \ +hurd_##name##_slab_destroy (hurd_##name##_slab_space_t space) \ +{ \ + return hurd_slab_destroy (&space->space); \ +} \ + \ +static inline error_t \ +hurd_##name##_slab_alloc (hurd_##name##_slab_space_t space, \ + element_type **buffer) \ +{ \ + union \ + { \ + element_type **e; \ + void **v; \ + } foo; \ + foo.e = buffer; \ + \ + return hurd_slab_alloc (&space->space, foo.v); \ +} \ + \ +static inline void \ +hurd_##name##_slab_dealloc (hurd_##name##_slab_space_t space, \ + element_type *buffer) \ +{ \ + union \ + { \ + element_type *e; \ + void *v; \ + } foo; \ + foo.e = buffer; \ + \ + hurd_slab_dealloc (&space->space, foo.v); \ +} #endif /* _HURD_SLAB_H */ |