ChibiOS
21.6.0
|
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_t * | hash_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_t * | lru_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_t * | chCacheGetObject (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 uint32_t oc_flags_t |
Flags of cached objects.
Definition at line 64 of file chobjcaches.h.
typedef struct ch_oc_hash_header oc_hash_header_t |
Type of an hash element header.
Definition at line 69 of file chobjcaches.h.
typedef struct ch_oc_lru_header oc_lru_header_t |
Type of an LRU element header.
Definition at line 74 of file chobjcaches.h.
typedef struct ch_oc_object oc_object_t |
Type of a cached object.
Definition at line 79 of file chobjcaches.h.
typedef struct ch_objects_cache objects_cache_t |
Type of a cache object.
Definition at line 84 of file chobjcaches.h.
typedef bool(* oc_readf_t) (objects_cache_t *ocp, oc_object_t *objp, bool async) |
Object read function.
[in] | ocp | pointer to the objects_cache_t structure |
[in] | async | requests an asynchronous operation if supported, the function is then responsible for releasing the object |
Definition at line 94 of file chobjcaches.h.
typedef bool(* oc_writef_t) (objects_cache_t *ocp, oc_object_t *objp, bool async) |
Object write function.
[in] | ocp | pointer to the objects_cache_t structure |
[in] | async | requests an asynchronous operation if supported, the function is then responsible for releasing the object |
Definition at line 106 of file chobjcaches.h.
|
static |
Returns an object pointer from the cache, if present.
[out] | ocp | pointer to the objects_cache_t structure to be |
[in] | group | object group identifier |
[in] | key | object identifier within the group initialized |
NULL | if the object is not in cache. |
Definition at line 134 of file chobjcaches.c.
References ch_objects_cache::hashp.
Referenced by chCacheGetObject().
|
static |
Gets the least recently used object buffer from the LRU list.
[out] | ocp | pointer to the objects_cache_t structure to be |
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.
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.
[out] | ocp | pointer to the objects_cache_t structure to be initialized |
[in] | hashn | number of elements in the hash table array, must be a power of two and not lower than objn |
[in] | hashp | pointer to the hash table as an array of oc_hash_header_t |
[in] | objn | number of elements in the objects table array |
[in] | objsz | size of elements in the objects table array, the minimum value is sizeof (oc_object_t) . |
[in] | objvp | pointer to the hash objects as an array of structures starting with an oc_object_t |
[in] | readf | pointer to an object reader function |
[in] | writef | pointer to an object writer function |
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.
oc_object_t * chCacheGetObject | ( | objects_cache_t * | ocp, |
uint32_t | group, | ||
uint32_t | key | ||
) |
Retrieves an object from the cache.
OC_FLAG_NOTSYNC
meaning that its data contains garbage and must be initialized.[in] | ocp | pointer to the objects_cache_t structure |
[in] | group | object group identifier |
[in] | key | object identifier within the group |
Definition at line 304 of file chobjcaches.c.
References chDbgAssert, chSysLock, hash_get_s(), and ch_oc_object::obj_flags.
void chCacheReleaseObjectI | ( | objects_cache_t * | ocp, |
oc_object_t * | objp | ||
) |
Releases an object into the cache.
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).[in] | ocp | pointer to the objects_cache_t structure |
[in] | objp | pointer to the oc_object_t structure |
Definition at line 379 of file chobjcaches.c.
References chDbgAssert, and ch_oc_object::obj_flags.
Referenced by chCacheReleaseObject().
bool chCacheReadObject | ( | objects_cache_t * | ocp, |
oc_object_t * | objp, | ||
bool | async | ||
) |
Reads object data from the storage.
[in] | ocp | pointer to the objects_cache_t structure |
[in] | objp | pointer to the oc_object_t structure |
[in] | async | requests an asynchronous operation if supported, the function is then responsible for releasing the object |
false
is always returned. false | if the operation succeeded. |
true | if the synchronous read operation failed. |
Definition at line 449 of file chobjcaches.c.
References ch_oc_object::obj_flags.
bool chCacheWriteObject | ( | objects_cache_t * | ocp, |
oc_object_t * | objp, | ||
bool | async | ||
) |
Writes the object data back to storage.
[in] | ocp | pointer to the objects_cache_t structure |
[in] | objp | pointer to the oc_object_t structure |
[in] | async | requests an asynchronous operation if supported, the function is then responsible for releasing the object |
false
is always returned. false | if the operation succeeded. |
true | if the synchronous write operation failed. |
Definition at line 478 of file chobjcaches.c.
References ch_oc_object::obj_flags.
|
inlinestatic |
Releases an object into the cache.
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).[in] | ocp | pointer to the objects_cache_t structure |
[in] | objp | pointer to the oc_object_t structure |
Definition at line 291 of file chobjcaches.h.
References chCacheReleaseObjectI(), chSchRescheduleS(), chSysLock, and chSysUnlock.