ChibiOS  21.6.0
chobjcaches.c File Reference

Objects Caches code. More...

#include "ch.h"

Go to the source code of this file.

Functions

static oc_object_thash_get_s (objects_cache_t *ocp, uint32_t group, uint32_t key)
 Returns an object pointer from the cache, if present. More...
 
static oc_object_tlru_get_last_s (objects_cache_t *ocp)
 Gets the least recently used object buffer from the LRU list. More...
 
void chCacheObjectInit (objects_cache_t *ocp, ucnt_t hashn, oc_hash_header_t *hashp, ucnt_t objn, size_t objsz, void *objvp, oc_readf_t readf, oc_writef_t writef)
 Initializes a objects_cache_t object. More...
 
oc_object_tchCacheGetObject (objects_cache_t *ocp, uint32_t group, uint32_t key)
 Retrieves an object from the cache. More...
 
void chCacheReleaseObjectI (objects_cache_t *ocp, oc_object_t *objp)
 Releases an object into the cache. More...
 
bool chCacheReadObject (objects_cache_t *ocp, oc_object_t *objp, bool async)
 Reads object data from the storage. More...
 
bool chCacheWriteObject (objects_cache_t *ocp, oc_object_t *objp, bool async)
 Writes the object data back to storage. More...
 

Detailed Description

Objects Caches code.

Objects caches.

Operation mode

An object cache allows to retrieve and release objects from a slow media, for example a disk or flash.
The most recently used objects are kept in a series of RAM buffers making access faster. Objects are identified by a pair <group, key> which could be mapped, for example, to a disk drive identifier and sector identifier.
Read and write operations are performed using externally-supplied functions, the cache is device-agnostic.
The cache uses internally an hash table, the size of the table should be dimensioned to minimize the risk of hash collisions, a factor of two is usually acceptable, it depends on the specific application requirements.
Operations defined for caches:

  • Get Object: Retrieves an object from cache, if not present then an empty buffer is returned.
  • Read Object: Retrieves an object from cache, if not present a buffer is allocated and the object is read from the media.
  • Release Object: Releases an object to the cache handling the media update, if required.
Precondition
In order to use the pipes APIs the CH_CFG_USE_OBJ_CACHES option must be enabled in chconf.h.
Note
Compatible with RT and NIL.

Definition in file chobjcaches.c.