MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cache.h
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 #ifndef CACHE_H
3 #define CACHE_H
4 #include <pthread.h>
5 
6 #ifdef HAVE_UMEM_H
7 #include <umem.h>
8 #define cache_t umem_cache_t
9 #define cache_alloc(a) umem_cache_alloc(a, UMEM_DEFAULT)
10 #define cache_free(a, b) umem_cache_free(a, b)
11 #define cache_create(a,b,c,d,e) umem_cache_create((char*)a, b, c, d, e, NULL, NULL, NULL, 0)
12 #define cache_destroy(a) umem_cache_destroy(a);
13 
14 #else
15 
16 #ifndef NDEBUG
17 /* may be used for debug purposes */
18 extern int cache_error;
19 #endif
20 
29 typedef int cache_constructor_t(void* obj, void* notused1, int notused2);
39 typedef void cache_destructor_t(void* obj, void* notused);
40 
46 typedef struct {
48  pthread_mutex_t mutex;
50  char *name;
52  void **ptr;
54  size_t bufsize;
56  int freetotal;
58  int freecurr;
60  cache_constructor_t* constructor;
62  cache_destructor_t* destructor;
63 } cache_t;
64 
83 cache_t* cache_create(const char* name, size_t bufsize, size_t align,
84  cache_constructor_t* constructor,
85  cache_destructor_t* destructor);
95 void cache_destroy(cache_t* handle);
103 void* cache_alloc(cache_t* handle);
113 void cache_free(cache_t* handle, void* ptr);
114 #endif
115 
116 #endif