ChibiOS  21.6.0
Objects Caches
Collaboration diagram for Objects Caches:

Detailed Description

Cached objects flags

#define OC_FLAG_INLRU   0x00000001U
 
#define OC_FLAG_INHASH   0x00000002U
 
#define OC_FLAG_SHARED   0x00000004U
 
#define OC_FLAG_NOTSYNC   0x00000008U
 
#define OC_FLAG_LAZYWRITE   0x00000010U
 
#define OC_FLAG_FORGET   0x00000020U
 

Typedefs

typedef uint32_t oc_flags_t
 Flags of cached objects. More...
 
typedef struct ch_oc_hash_header oc_hash_header_t
 Type of an hash element header. More...
 
typedef struct ch_oc_lru_header oc_lru_header_t
 Type of an LRU element header. More...
 
typedef struct ch_oc_object oc_object_t
 Type of a cached object. More...
 
typedef struct ch_objects_cache objects_cache_t
 Type of a cache object. More...
 
typedef bool(* oc_readf_t) (objects_cache_t *ocp, oc_object_t *objp, bool async)
 Object read function. More...
 
typedef bool(* oc_writef_t) (objects_cache_t *ocp, oc_object_t *objp, bool async)
 Object write function. More...
 

Data Structures

struct  ch_oc_hash_header
 Structure representing an hash table element. More...
 
struct  ch_oc_lru_header
 Structure representing an hash table element. More...
 
struct  ch_oc_object
 Structure representing a cached object. More...
 
struct  ch_objects_cache
 Structure representing a cache object. More...
 

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...
 
static void chCacheReleaseObject (objects_cache_t *ocp, oc_object_t *objp)
 Releases an object into the cache. More...
 

Typedef Documentation

◆ oc_flags_t

typedef uint32_t oc_flags_t

Flags of cached objects.

Definition at line 64 of file chobjcaches.h.

◆ oc_hash_header_t

Type of an hash element header.

Definition at line 69 of file chobjcaches.h.

◆ oc_lru_header_t

Type of an LRU element header.

Definition at line 74 of file chobjcaches.h.

◆ oc_object_t

typedef struct ch_oc_object oc_object_t

Type of a cached object.

Definition at line 79 of file chobjcaches.h.

◆ objects_cache_t

Type of a cache object.

Definition at line 84 of file chobjcaches.h.

◆ oc_readf_t

typedef bool(* oc_readf_t) (objects_cache_t *ocp, oc_object_t *objp, bool async)

Object read function.

Parameters
[in]ocppointer to the objects_cache_t structure
[in]asyncrequests an asynchronous operation if supported, the function is then responsible for releasing the object

Definition at line 94 of file chobjcaches.h.

◆ oc_writef_t

typedef bool(* oc_writef_t) (objects_cache_t *ocp, oc_object_t *objp, bool async)

Object write function.

Parameters
[in]ocppointer to the objects_cache_t structure
[in]asyncrequests an asynchronous operation if supported, the function is then responsible for releasing the object

Definition at line 106 of file chobjcaches.h.

Function Documentation

◆ hash_get_s()

static oc_object_t* hash_get_s ( objects_cache_t ocp,
uint32_t  group,
uint32_t  key 
)
static

Returns an object pointer from the cache, if present.

Parameters
[out]ocppointer to the objects_cache_t structure to be
[in]groupobject group identifier
[in]keyobject identifier within the group initialized
Returns
The pointer to the retrieved object.
Return values
NULLif the object is not in cache.
Function Class:
Not an API, this function is for internal use only.

Definition at line 134 of file chobjcaches.c.

References ch_objects_cache::hashp.

Referenced by chCacheGetObject().

◆ lru_get_last_s()

static oc_object_t* lru_get_last_s ( objects_cache_t ocp)
static

Gets the least recently used object buffer from the LRU list.

Parameters
[out]ocppointer to the objects_cache_t structure to be
Returns
The pointer to the retrieved object.
Function Class:
Not an API, this function is for internal use only.

Definition at line 165 of file chobjcaches.c.

References chDbgAssert, chSemWaitS(), ch_objects_cache::lru, ch_oc_lru_header::lru_prev, ch_objects_cache::lru_sem, and ch_oc_object::obj_flags.

Here is the call graph for this function:

◆ chCacheObjectInit()

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.

Parameters
[out]ocppointer to the objects_cache_t structure to be initialized
[in]hashnnumber of elements in the hash table array, must be a power of two and not lower than objn
[in]hashppointer to the hash table as an array of oc_hash_header_t
[in]objnnumber of elements in the objects table array
[in]objszsize of elements in the objects table array, the minimum value is sizeof (oc_object_t).
[in]objvppointer to the hash objects as an array of structures starting with an oc_object_t
[in]readfpointer to an object reader function
[in]writefpointer to an object writer function
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 241 of file chobjcaches.c.

References ch_objects_cache::cache_sem, chDbgCheck, chSemObjectInit(), ch_oc_hash_header::hash_next, ch_oc_lru_header::hash_next, ch_oc_hash_header::hash_prev, ch_oc_lru_header::hash_prev, ch_objects_cache::hashn, ch_objects_cache::hashp, ch_objects_cache::lru, ch_oc_lru_header::lru_next, ch_oc_lru_header::lru_prev, ch_objects_cache::lru_sem, ch_oc_object::obj_sem, ch_objects_cache::objn, ch_objects_cache::objvp, PORT_NATURAL_ALIGN, ch_objects_cache::readf, and ch_objects_cache::writef.

Here is the call graph for this function:

◆ chCacheGetObject()

oc_object_t * chCacheGetObject ( objects_cache_t ocp,
uint32_t  group,
uint32_t  key 
)

Retrieves an object from the cache.

Note
If the object is not in cache then the returned object is marked as OC_FLAG_NOTSYNC meaning that its data contains garbage and must be initialized.
Parameters
[in]ocppointer to the objects_cache_t structure
[in]groupobject group identifier
[in]keyobject identifier within the group
Returns
The pointer to the retrieved object.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 304 of file chobjcaches.c.

References chDbgAssert, chSysLock, hash_get_s(), and ch_oc_object::obj_flags.

Here is the call graph for this function:

◆ chCacheReleaseObjectI()

void chCacheReleaseObjectI ( objects_cache_t ocp,
oc_object_t objp 
)

Releases an object into the cache.

Note
This function gives a meaning to the following flags:
  • OC_FLAG_INLRU must be cleared.
  • OC_FLAG_INHASH must be set.
  • OC_FLAG_SHARED must be cleared.
  • OC_FLAG_NOTSYNC invalidates the object and queues it on the LRU tail.
  • OC_FLAG_LAZYWRITE is ignored and kept, a write will occur when the object is removed from the LRU list (lazy write).
Parameters
[in]ocppointer to the objects_cache_t structure
[in]objppointer to the oc_object_t structure
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 379 of file chobjcaches.c.

References chDbgAssert, and ch_oc_object::obj_flags.

Referenced by chCacheReleaseObject().

◆ chCacheReadObject()

bool chCacheReadObject ( objects_cache_t ocp,
oc_object_t objp,
bool  async 
)

Reads object data from the storage.

Note
In case of asynchronous operation an error condition is not reported by this function.
Parameters
[in]ocppointer to the objects_cache_t structure
[in]objppointer to the oc_object_t structure
[in]asyncrequests an asynchronous operation if supported, the function is then responsible for releasing the object
Returns
The operation status. In case of asynchronous operation false is always returned.
Return values
falseif the operation succeeded.
trueif the synchronous read operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 449 of file chobjcaches.c.

References ch_oc_object::obj_flags.

◆ chCacheWriteObject()

bool chCacheWriteObject ( objects_cache_t ocp,
oc_object_t objp,
bool  async 
)

Writes the object data back to storage.

Note
In case of asynchronous operation an error condition is not reported by this function.
Parameters
[in]ocppointer to the objects_cache_t structure
[in]objppointer to the oc_object_t structure
[in]asyncrequests an asynchronous operation if supported, the function is then responsible for releasing the object
Returns
The operation status. In case of asynchronous operation false is always returned.
Return values
falseif the operation succeeded.
trueif the synchronous write operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 478 of file chobjcaches.c.

References ch_oc_object::obj_flags.

◆ chCacheReleaseObject()

static void chCacheReleaseObject ( objects_cache_t ocp,
oc_object_t objp 
)
inlinestatic

Releases an object into the cache.

Note
This function gives a meaning to the following flags:
  • OC_FLAG_INLRU must be cleared.
  • OC_FLAG_INHASH must be set.
  • OC_FLAG_SHARED must be cleared.
  • OC_FLAG_NOTSYNC invalidates the object and queues it on the LRU tail.
  • OC_FLAG_LAZYWRITE is ignored and kept, a write will occur when the object is removed from the LRU list (lazy write).
Parameters
[in]ocppointer to the objects_cache_t structure
[in]objppointer to the oc_object_t structure
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 291 of file chobjcaches.h.

References chCacheReleaseObjectI(), chSchRescheduleS(), chSysLock, and chSysUnlock.

Here is the call graph for this function: