40 slab->bufctl[i] = i + 1;
49 if (slab->cache->dtor !=
NULL)
51 for (
uint32_t i = 0; i < slab->cache->layout.amount; i++)
53 slab->cache->dtor((
void*)((
uintptr_t)slab->objects + (i * slab->cache->layout.step)));
61 if (slab->freeCount == 0)
66 void*
object = (
void*)((
uintptr_t)slab->objects + (slab->firstFree * slab->cache->layout.step));
67 slab->firstFree = slab->bufctl[slab->firstFree];
77 slab->bufctl[index] = slab->firstFree;
78 slab->firstFree = index;
134 if (
active->freeCount > 0)
167 slab->owner =
SELF->id;
181 slab->owner =
SELF->id;
197 slab->owner =
SELF->id;
216 bool wasFull = (slab->freeCount == 0);
221 if (wasFull || isEmpty)
#define assert(expression)
static void * cache_slab_alloc(cache_slab_t *slab)
static cache_slab_t * cache_slab_new(cache_t *cache)
static void cache_slab_free(cache_slab_t *slab, void *ptr)
static void cache_slab_destroy(cache_slab_t *slab)
static void cache_precalc_layout(cache_t *cache)
#define CLI_SCOPE()
Macro to increment CLI depth for the duration of the current scope.
#define SELF
Macro to access data in the current cpu.
#define CPU_ID_INVALID
Invalid CPU ID.
#define LOG_DEBUG(format,...)
void cache_free(void *ptr)
Free an object back to its cache.
uint16_t cache_bufctl_t
Buffer control type.
#define CACHE_LINE
Cache line size in bytes.
#define CACHE_BUFCTL_END
End of buffer control list marker.
void * cache_alloc(cache_t *cache)
Allocate an object from the cache.
#define CACHE_CREATE(_cache, _name, _size, _alignment, _ctor, _dtor)
Macro to create a cache initializer.
#define CACHE_LIMIT
Maximum number of free slabs in a cache.
#define CACHE_SLAB_PAGES
Number of pages in a slab.
void * vmm_alloc(space_t *space, void *virtAddr, size_t length, size_t alignment, pml_flags_t pmlFlags, vmm_alloc_flags_t allocFlags)
Allocates and maps virtual memory in a given address space.
void * vmm_unmap(space_t *space, void *virtAddr, size_t length)
Unmaps virtual memory from a given address space.
@ VMM_ALLOC_FAIL_IF_MAPPED
If set and any page is already mapped, fail and set errno to EEXIST.
static void lock_init(lock_t *lock)
Initializes a lock.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define TEST_DEFINE(_name)
Define a test function to be run by TEST_ALL().
#define TEST_ASSERT(cond)
Assert a condition in a test.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static void list_remove(list_entry_t *entry)
Removes a list entry from its current list.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static list_entry_t * list_pop_front(list_t *list)
Pops the first entry from the list.
uint64_t next_pow2(uint64_t n)
#define ROUND_DOWN(number, multiple)
#define ROUND_UP(number, multiple)
#define NULL
Pointer error value.
#define PAGE_SIZE
The size of a memory page in bytes.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
__UINTPTR_TYPE__ uintptr_t
cache_cpu_t cpus[CPU_MAX]
cache_slab_layout_t layout