MySQL  8.0.18
Source Code Documentation
cache.h File Reference
#include <pthread.h>

Go to the source code of this file.

Classes

struct  cache_t
 Definition of the structure to keep track of the internal details of the cache allocator. More...
 

Typedefs

typedef int cache_constructor_t(void *obj, void *notused1, int notused2)
 Constructor used to initialize allocated objects. More...
 
typedef void cache_destructor_t(void *obj, void *notused)
 Destructor used to clean up allocated objects before they are returned to the operating system. More...
 

Functions

cache_tcache_create (const char *name, size_t bufsize, size_t align, cache_constructor_t *constructor, cache_destructor_t *destructor)
 Create an object cache. More...
 
void cache_destroy (cache_t *handle)
 Destroy an object cache. More...
 
void * cache_alloc (cache_t *handle)
 Allocate an object from the cache. More...
 
void cache_free (cache_t *handle, void *ptr)
 Return an object back to the cache. More...
 

Variables

int cache_error
 

Typedef Documentation

◆ cache_constructor_t

typedef int cache_constructor_t(void *obj, void *notused1, int notused2)

Constructor used to initialize allocated objects.

Parameters
objpointer to the object to initialized.
notused1This parameter is currently not used.
notused2This parameter is currently not used.
Returns
you should return 0, but currently this is not checked

◆ cache_destructor_t

typedef void cache_destructor_t(void *obj, void *notused)

Destructor used to clean up allocated objects before they are returned to the operating system.

Parameters
objpointer to the object to initialized.
notused1This parameter is currently not used.
notused2This parameter is currently not used.
Returns
you should return 0, but currently this is not checked

Function Documentation

◆ cache_alloc()

void* cache_alloc ( cache_t handle)

Allocate an object from the cache.

Parameters
handlethe handle to the object cache to allocate from
Returns
a pointer to an initialized object from the cache, or NULL if the allocation cannot be satisfied.

◆ cache_create()

cache_t* cache_create ( const char *  name,
size_t  bufsize,
size_t  align,
cache_constructor_t constructor,
cache_destructor_t destructor 
)

Create an object cache.

The object cache will let you allocate objects of the same size. It is fully MT safe, so you may allocate objects from multiple threads without having to do any syncrhonization in the application code.

Parameters
namethe name of the object cache. This name may be used for debug purposes and may help you track down what kind of object you have problems with (buffer overruns, leakage etc)
bufsizethe size of each object in the cache
alignthe alignment requirements of the objects in the cache.
constructorthe function to be called to initialize memory when we need to allocate more memory from the os.
destructorthe function to be called before we release the memory back to the os.
Returns
a handle to an object cache if successful, NULL otherwise.

◆ cache_destroy()

void cache_destroy ( cache_t handle)

Destroy an object cache.

Destroy and invalidate an object cache. You should return all buffers allocated with cache_alloc by using cache_free before calling this function. Not doing so results in undefined behavior (the buffers may or may not be invalidated)

Parameters
handlethe handle to the object cache to destroy.

◆ cache_free()

void cache_free ( cache_t handle,
void *  ptr 
)

Return an object back to the cache.

The caller should return the object in an initialized state so that the object may be returned in an expected state from cache_alloc.

Parameters
handlehandle to the object cache to return the object to
ptrpointer to the object to return.

Variable Documentation

◆ cache_error

int cache_error