56#if (CH_CFG_USE_OBJ_CACHES == TRUE) || defined(__DOXYGEN__)
63#if !defined(OC_HASH_FUNCTION) || defined(__DOXYGEN__)
64#define OC_HASH_FUNCTION(ocp, group, key) \
65 (((unsigned)(group) + (unsigned)(key)) & ((unsigned)(ocp)->hashn - 1U))
69#define HASH_INSERT(ocp, objp, group, key) { \
70 oc_hash_header_t *hhp; \
71 (hhp) = &(ocp)->hashp[OC_HASH_FUNCTION(ocp, group, key)]; \
72 (objp)->hash_next = (hhp)->hash_next; \
73 (objp)->hash_prev = (oc_object_t *)(hhp); \
74 (hhp)->hash_next->hash_prev = (objp); \
75 (hhp)->hash_next = (objp); \
79#define HASH_REMOVE(objp) { \
80 (objp)->hash_prev->hash_next = (objp)->hash_next; \
81 (objp)->hash_next->hash_prev = (objp)->hash_prev; \
85#define LRU_INSERT_HEAD(ocp, objp) { \
86 (objp)->lru_next = (ocp)->lru.lru_next; \
87 (objp)->lru_prev = (oc_object_t *)&(ocp)->lru; \
88 (ocp)->lru.lru_next->lru_prev = (objp); \
89 (ocp)->lru.lru_next = (objp); \
93#define LRU_INSERT_TAIL(ocp, objp) { \
94 (objp)->lru_prev = (ocp)->lru.lru_prev; \
95 (objp)->lru_next = (oc_object_t *)&(ocp)->lru; \
96 (ocp)->lru.lru_prev->lru_next = (objp); \
97 (ocp)->lru.lru_prev = (objp); \
101#define LRU_REMOVE(objp) { \
102 (objp)->lru_prev->lru_next = (objp)->lru_next; \
103 (objp)->lru_next->lru_prev = (objp)->lru_prev; \
179 "semaphore counter not 1");
210 (void) ocp->
writef(ocp, objp,
true);
249 chDbgCheck((ocp != NULL) && (hashp != NULL) && (objvp != NULL) &&
251 (objn > (
ucnt_t)0) && (hashn >= objn) &&
253 ((objsz & (PORT_NATURAL_ALIGN - 1U)) == 0U));
273 }
while (hashp < &ocp->hashp[ocp->
hashn]);
285 objvp = (
void *)((uint8_t *)objvp + objsz);
287 }
while (objn > (
ucnt_t)0);
385 "invalid object state");
387 "semaphore counter greater than 0");
457 return ocp->
readf(ocp, objp, async);
485 return ocp->
writef(ocp, objp, async);
ChibiOS/RT main include file.
#define chDbgAssert(c, r)
Condition assertion.
#define chDbgCheck(c)
Function parameters check.
bool chCacheReadObject(objects_cache_t *ocp, oc_object_t *objp, bool async)
Reads object data from the storage.
#define OC_FLAG_LAZYWRITE
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.
struct ch_oc_object oc_object_t
Type of a cached object.
bool chCacheWriteObject(objects_cache_t *ocp, oc_object_t *objp, bool async)
Writes the object data back to storage.
struct ch_oc_hash_header oc_hash_header_t
Type of an hash element header.
bool(* oc_readf_t)(objects_cache_t *ocp, oc_object_t *objp, bool async)
Object read function.
oc_object_t * chCacheGetObject(objects_cache_t *ocp, uint32_t group, uint32_t key)
Retrieves an object from the cache.
#define LRU_INSERT_HEAD(ocp, objp)
static oc_object_t * lru_get_last_s(objects_cache_t *ocp)
Gets the least recently used object buffer from the LRU list.
struct ch_objects_cache objects_cache_t
Type of a cache object.
void chCacheReleaseObjectI(objects_cache_t *ocp, oc_object_t *objp)
Releases an object into the cache.
bool(* oc_writef_t)(objects_cache_t *ocp, oc_object_t *objp, bool async)
Object write function.
#define HASH_REMOVE(objp)
#define LRU_INSERT_TAIL(ocp, objp)
#define OC_HASH_FUNCTION(ocp, group, key)
#define HASH_INSERT(ocp, objp, group, key)
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.
static cnt_t chSemGetCounterI(const semaphore_t *sp)
Returns the semaphore counter current value.
void chSemObjectInit(semaphore_t *sp, cnt_t n)
Initializes a semaphore with the specified counter value.
msg_t chSemWaitS(semaphore_t *sp)
Performs a wait operation on a semaphore.
static void chSemFastWaitI(semaphore_t *sp)
Decreases the semaphore counter.
void chSemSignalI(semaphore_t *sp)
Performs a signal operation on a semaphore.
static void chSemFastSignalI(semaphore_t *sp)
Increases the semaphore counter.
static void chSysLock(void)
Enters the kernel lock state.
static void chSysUnlock(void)
Leaves the kernel lock state.
oc_writef_t writef
Writer functions for cached objects.
void * objvp
Pointer to the objects table.
semaphore_t cache_sem
Semaphore for cache access.
ucnt_t objn
Number of elements in the objects table.
oc_hash_header_t * hashp
Pointer to the hash table.
ucnt_t hashn
Number of elements in the hash table.
semaphore_t lru_sem
Semaphore for LRU access.
oc_readf_t readf
Reader functions for cached objects.
oc_lru_header_t lru
LRU list header.
uint32_t obj_key
Object key.
oc_flags_t obj_flags
Object flags.
oc_object_t * hash_next
Next in the collisions list.
semaphore_t obj_sem
Semaphore for object access.
uint32_t obj_group
Object group.