aboutsummaryrefslogtreecommitdiffstats
path: root/allocate.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-02 12:40:30 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:05:26 -0700
commit3f226e97529ca34d48b350e1b0f814a8e34ad6b5 (patch)
treebd51585ba53dbbe01a3df0e265e8b2b9ad713e16 /allocate.h
parent853d7d9aed2104e7240aae85ccbb97f5408af664 (diff)
downloadsparse-3f226e97529ca34d48b350e1b0f814a8e34ad6b5.tar.gz
sparse-3f226e97529ca34d48b350e1b0f814a8e34ad6b5.tar.xz
sparse-3f226e97529ca34d48b350e1b0f814a8e34ad6b5.zip
Allow anybody to declare their own allocator by making the
helper macros available in the "allocate.h" header file. The declarations stay in "allocate.c" for now, but at least you _can_ make private allocators now if you want to.
Diffstat (limited to 'allocate.h')
-rw-r--r--allocate.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/allocate.h b/allocate.h
index 56abb0c..e75323c 100644
--- a/allocate.h
+++ b/allocate.h
@@ -20,6 +20,7 @@ struct allocator_struct {
extern void drop_all_allocations(struct allocator_struct *desc);
extern void *allocate(struct allocator_struct *desc, unsigned int size);
extern void free_one_entry(struct allocator_struct *desc, void *entry);
+extern void show_allocations(struct allocator_struct *);
#define __DECLARE_ALLOCATOR(type, x) \
extern type *__alloc_##x(int); \
@@ -28,6 +29,30 @@ extern void free_one_entry(struct allocator_struct *desc, void *entry);
extern void clear_##x##_alloc(void);
#define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
+#define __ALLOCATOR(type, objsize, objalign, objname, x) \
+ struct allocator_struct x##_allocator = { \
+ .name = objname, \
+ .alignment = objalign, \
+ .chunking = CHUNK }; \
+ type *__alloc_##x(int extra) \
+ { \
+ return allocate(&x##_allocator, objsize+extra); \
+ } \
+ void __free_##x(type *entry) \
+ { \
+ return free_one_entry(&x##_allocator, entry); \
+ } \
+ void show_##x##_alloc(void) \
+ { \
+ show_allocations(&x##_allocator); \
+ } \
+ void clear_##x##_alloc(void) \
+ { \
+ drop_all_allocations(&x##_allocator); \
+ }
+
+#define ALLOCATOR(x, n) __ALLOCATOR(struct x, sizeof(struct x), __alignof__(struct x), n, x)
+
DECLARE_ALLOCATOR(ident);
DECLARE_ALLOCATOR(token);
DECLARE_ALLOCATOR(symbol);