lib/mrucache.h File Reference


Detailed Description

Most recent used cache Elements (addressed by a LList node) are either checked in the cache and thereby subject of aging or checked out under control of the user.

Most operations require that the cache is locked. This locking must be done from elsewhere.

Definition in file mrucache.h.

#include "lib/llist.h"
#include <nobug.h>

Include dependency graph for mrucache.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lumiera_mrucache_struct

Typedefs

typedef void *(* lumiera_cache_destructor_fn )(LList node)
 Callback function used to destruct/cleanup aged elements.
typedef struct
lumiera_mrucache_struct 
lumiera_mrucache
typedef lumiera_mrucache * LumieraMruCache

Functions

int lumiera_mrucache_age (LumieraMruCache self, int nelem)
 Destroy and free the nelem oldest elements.
static void lumiera_mrucache_checkin (LumieraMruCache self, LList node)
 Add an element to a mrucache.
static void lumiera_mrucache_checkout (LumieraMruCache self, LList node)
 Checkout an element from a cache.
LumieraMruCache lumiera_mrucache_destroy (LumieraMruCache self)
 Destroy a cache.
static void lumiera_mrucache_drop (LumieraMruCache self, LList node)
 Schedule an element for fast aging.
LumieraMruCache lumiera_mrucache_init (LumieraMruCache self, lumiera_cache_destructor_fn destructor_cb)
 Initialize a cache.
static void * lumiera_mrucache_pop (LumieraMruCache self)
 Destroy the oldest element from the cache and return it.


Typedef Documentation

typedef void*(* lumiera_cache_destructor_fn)(LList node)

Callback function used to destruct/cleanup aged elements.

shall clean the element sufficiently up to be ready for being freed or reused, this callback function must be reentrant and prepared to be called twice.

Parameters:
node the llist node used to link cache elements (will be empty at call)
Returns:
pointer to the begin of the element.

Definition at line 44 of file mrucache.h.


Function Documentation

LumieraMruCache lumiera_mrucache_init ( LumieraMruCache  self,
lumiera_cache_destructor_fn  destructor_cb 
)

Initialize a cache.

Parameters:
self cache to be initialized
destructor_cb function for destructing a cache node, preparing for reuse.
Returns:
self

Definition at line 27 of file mrucache.c.

LumieraMruCache lumiera_mrucache_destroy ( LumieraMruCache  self  ) 

Destroy a cache.

calls the registered destructor and frees all checked in items.

Parameters:
self cache to be destroyed
Returns:
self

Definition at line 37 of file mrucache.c.

References LLIST_WHILE_TAIL, and lumiera_free().

Here is the call graph for this function:

static void lumiera_mrucache_checkin ( LumieraMruCache  self,
LList  node 
) [inline, static]

Add an element to a mrucache.

When added the element is subject of aging and must not be accessed anymore. To acces elements they have to be checked out again. Checkin and checkout operations must be protected by a lock over the cache.

Parameters:
self cache where to checkin
node a llist member in the cached data which is used as queue in the cache

Definition at line 83 of file mrucache.h.

Referenced by lumiera_filehandlecache_checkin(), and lumiera_mmapcache_checkin().

Here is the caller graph for this function:

static void lumiera_mrucache_drop ( LumieraMruCache  self,
LList  node 
) [inline, static]

Schedule an element for fast aging.

When an element is not longer needed it can be placed at the end of the chache aging queue and thus become the first one to be reused when a new element is queried. This can be done on a checked out element as well as on an element which is in the cache. The cache must be locked for this operation.

Parameters:
self cache
node a llist member in the cached data which is used as queue in the cache

Definition at line 102 of file mrucache.h.

static void lumiera_mrucache_checkout ( LumieraMruCache  self,
LList  node 
) [inline, static]

Checkout an element from a cache.

A checked out element is not under cache control anymore until is gets checked in again. The code which checked the element out takes ownership of the element. The cache must be locked for this operation.

Parameters:
self cache
node a llist member in the cached data which is used as queue in the cache

Definition at line 133 of file mrucache.h.

Referenced by lumiera_filehandlecache_checkout(), and lumiera_mmapcache_checkout().

Here is the caller graph for this function:

static void* lumiera_mrucache_pop ( LumieraMruCache  self  )  [inline, static]

Destroy the oldest element from the cache and return it.

This function is used to get a new element by deleting the oldest least used one from the cache. The cache must be locked for this operation.

Parameters:
self cache
Returns:
pointer to the uninitialized memory ready for being reused or NULL when no element was available

Definition at line 151 of file mrucache.h.

Referenced by lumiera_filehandlecache_handle_acquire(), lumiera_mmapcache_mmap_acquire(), and lumiera_mrucache_age().

Here is the caller graph for this function:

int lumiera_mrucache_age ( LumieraMruCache  self,
int  nelem 
)

Destroy and free the nelem oldest elements.

Used to free up resources and memory.

Parameters:
self cache where to free elements.
nelem number of elements wished to be freed
Returns:
nelem-(numer of elements which got freed), that is 0 if all requested elements got freed

Definition at line 52 of file mrucache.c.

References lumiera_free(), and lumiera_mrucache_pop().

Here is the call graph for this function:


Generated on Tue Jan 6 17:20:49 2009 for Lumiera by  doxygen 1.5.6