00001 00011 #ifndef _ALLOCATOR_H_ 00012 #define _ALLOCATOR_H_ 00013 00014 #define ALLOCATOR_MUTEX 00015 00016 #ifdef ALLOCATOR_SEM 00017 # include <kos/sem.h> 00018 #elif defined ALLOCATOR_MUTEX 00019 # include "mutex.h" 00020 #else 00021 # include <arch/spinlock.h> 00022 #endif 00023 00047 typedef struct _allocator_elt_s { 00048 struct _allocator_elt_s * next; 00049 struct _allocator_elt_s * prev; 00050 int align[2]; 00051 } allocator_elt_t; 00052 00067 typedef struct { 00068 void * realaddress; 00069 allocator_elt_t * used; 00070 allocator_elt_t * free; 00071 const char *name; 00072 #ifdef ALLOCATOR_SEM 00073 semaphore_t *sem; 00074 #elif defined ALLOCATOR_MUTEX 00075 mutex_t mutex; 00076 #else 00077 spinlock_t mutex; 00078 #endif 00079 unsigned int elt_size; 00080 unsigned int elements; 00081 char * bufend; 00082 char buffer[16]; 00083 } allocator_t; 00084 00099 allocator_t * allocator_create(int nmemb, int size, const char *name); 00100 00110 void allocator_destroy(allocator_t * a); 00111 00135 void * allocator_alloc(allocator_t * a, unsigned int size); 00136 00150 void * allocator_alloc_inside(allocator_t * a); 00151 00165 int allocator_is_inside(const allocator_t * a, const void * data); 00166 00175 int allocator_index(const allocator_t * a, const void * data); 00176 00194 void allocator_free(allocator_t * a, void * data); 00195 00200 int allocator_count_used(allocator_t * a); 00201 00206 int allocator_count_free(allocator_t * a); 00207 00222 void * allocator_match(allocator_t * a, const void * data, 00223 int (*cmp)(const void *, const void *)); 00224 00228 void allocator_dump(allocator_t * a); 00229 00245 void allocator_lock(allocator_t * a); 00246 00251 void allocator_unlock(allocator_t * a); 00252 00255 #endif /* #define _ALLOCATOR_H_ */
| dcplaya documentation version 1.2 | Generated on January 2004 by doxygen 1.3.5 |