00001
00002 #ifndef CACHE_H
00003 #define CACHE_H
00004 #include <pthread.h>
00005
00006 #ifdef HAVE_UMEM_H
00007 #include <umem.h>
00008 #define cache_t umem_cache_t
00009 #define cache_alloc(a) umem_cache_alloc(a, UMEM_DEFAULT)
00010 #define cache_free(a, b) umem_cache_free(a, b)
00011 #define cache_create(a,b,c,d,e) umem_cache_create((char*)a, b, c, d, e, NULL, NULL, NULL, 0)
00012 #define cache_destroy(a) umem_cache_destroy(a);
00013
00014 #else
00015
00016 #ifndef NDEBUG
00017
00018 extern int cache_error;
00019 #endif
00020
00029 typedef int cache_constructor_t(void* obj, void* notused1, int notused2);
00039 typedef void cache_destructor_t(void* obj, void* notused);
00040
00046 typedef struct {
00048 pthread_mutex_t mutex;
00050 char *name;
00052 void **ptr;
00054 size_t bufsize;
00056 int freetotal;
00058 int freecurr;
00060 cache_constructor_t* constructor;
00062 cache_destructor_t* destructor;
00063 } cache_t;
00064
00083 cache_t* cache_create(const char* name, size_t bufsize, size_t align,
00084 cache_constructor_t* constructor,
00085 cache_destructor_t* destructor);
00095 void cache_destroy(cache_t* handle);
00103 void* cache_alloc(cache_t* handle);
00113 void cache_free(cache_t* handle, void* ptr);
00114 #endif
00115
00116 #endif