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>


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 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.
| node | the llist node used to link cache elements (will be empty at call) |
Definition at line 44 of file mrucache.h.
| LumieraMruCache lumiera_mrucache_init | ( | LumieraMruCache | self, | |
| lumiera_cache_destructor_fn | destructor_cb | |||
| ) |
Initialize a cache.
| self | cache to be initialized | |
| destructor_cb | function for destructing a cache node, preparing for reuse. |
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.
| self | cache to be destroyed |
Definition at line 37 of file mrucache.c.
References LLIST_WHILE_TAIL, and lumiera_free().

| 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.
| 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().

| 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.
| 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.
| 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().

| 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.
| self | cache |
Definition at line 151 of file mrucache.h.
Referenced by lumiera_filehandlecache_handle_acquire(), lumiera_mmapcache_mmap_acquire(), and lumiera_mrucache_age().

| int lumiera_mrucache_age | ( | LumieraMruCache | self, | |
| int | nelem | |||
| ) |
Destroy and free the nelem oldest elements.
Used to free up resources and memory.
| self | cache where to free elements. | |
| nelem | number of elements wished to be freed |
Definition at line 52 of file mrucache.c.
References lumiera_free(), and lumiera_mrucache_pop().

1.5.6