debuggers.hg

view xen/include/xen/slab.h @ 3690:6e6976c1a545

bitkeeper revision 1.1159.242.1 (4203fb9erjxo9v5Lwlohe2bcTrLYpg)

1. Deleted slab.c, added xmalloc.c. Do not rename header or remove
unnecessary includes (yet).
2. Add explicit align arg, although current implementation
over-aligns.
3. Add list_for_each_entry_safe().
4. Make xmalloc_array use _xmalloc_array, to avoid duplicate eval
of "num" arg.
5. Rearrange slab.h a little to show the exposed functions/macros
first.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: ian.pratt@cl.cam.ac.uk
author iap10@labyrinth.cl.cam.ac.uk
date Fri Feb 04 22:47:58 2005 +0000 (2005-02-04)
parents 07d5c9548534
children 32d29625d39b
line source
1 /*
2 * Written by Mark Hemment, 1996.
3 * (markhe@nextd.demon.co.uk)
4 */
6 #ifndef __SLAB_H__
7 #define __SLAB_H__
9 #include <xen/config.h>
11 #ifdef __ARCH_HAS_SLAB_ALLOCATOR
13 #include <asm/slab.h>
15 #else
17 #include <xen/mm.h>
18 #include <xen/cache.h>
19 #include <xen/types.h>
21 /* Allocate space for typed object. */
22 #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
24 /* Allocate space for array of typed objects. */
25 #define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
27 /* Allocate untyped storage. */
28 #define xmalloc_bytes(_bytes) (_xmalloc(_bytes, SMP_CACHE_BYTES))
30 /* Free any of the above. */
31 extern void xfree(const void *);
33 /* Underlying functions */
34 extern void *_xmalloc(size_t size, size_t align);
35 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
36 {
37 /* Check for overflow. */
38 if (size && num > UINT_MAX / size)
39 return NULL;
40 return _xmalloc(size * num, align);
41 }
43 #endif /* __ARCH_HAS_SLAB_ALLOCATOR */
45 #endif /* __SLAB_H__ */