1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-10-30 11:54:01 -04:00

Use macros in PFA

This commit is contained in:
Alex Kotov 2021-12-14 23:54:47 +05:00
parent fa3f8e1aa0
commit 94e58914fd
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -15,6 +15,13 @@
#define FLAG_MASK_FROM_ADDR(page_addr) \ #define FLAG_MASK_FROM_ADDR(page_addr) \
(FLAG_MASK_FROM_INDEX(PAGE_INDEX(page_addr))) (FLAG_MASK_FROM_INDEX(PAGE_INDEX(page_addr)))
#define GET_FLAG_FROM_INDEX(pfa, page_index) \
(!!((pfa)->flags[FLAG_INDEX_FROM_INDEX(page_index)] & \
FLAG_MASK_FROM_INDEX(page_index)))
#define GET_FLAG_FROM_ADDR(pfa, page_addr) \
(!!((pfa)->flags[FLAG_INDEX_FROM_ADDR(page_addr)] & \
FLAG_MASK_FROM_ADDR(page_addr)))
static void KernAux_PFA_mark( static void KernAux_PFA_mark(
KernAux_PFA pfa, KernAux_PFA pfa,
bool status, bool status,
@ -32,8 +39,7 @@ bool KernAux_PFA_is_available(const KernAux_PFA pfa, const size_t page_addr)
{ {
if (page_addr % KERNAUX_PFA_PAGE_SIZE != 0) return false; if (page_addr % KERNAUX_PFA_PAGE_SIZE != 0) return false;
return pfa->flags[FLAG_INDEX_FROM_ADDR(page_addr)] & return GET_FLAG_FROM_ADDR(pfa, page_addr);
FLAG_MASK_FROM_ADDR(page_addr);
} }
void KernAux_PFA_mark_available( void KernAux_PFA_mark_available(
@ -101,9 +107,7 @@ size_t KernAux_PFA_alloc_pages(const KernAux_PFA pfa, size_t mem_size)
index < KERNAUX_PFA_PAGES_COUNT_MAX; index < KERNAUX_PFA_PAGES_COUNT_MAX;
++index) ++index)
{ {
if (!(pfa->flags[FLAG_INDEX_FROM_INDEX(index)] & if (!GET_FLAG_FROM_INDEX(pfa, index)) {
FLAG_MASK_FROM_INDEX(index)))
{
start = 0; start = 0;
continue; continue;
} }