From 05e8794bcbffa1d839f5d5374f8583e664e9ed7c Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 14 Dec 2021 04:03:13 +0500 Subject: [PATCH] Use typedef in PFA --- include/kernaux/pfa.h | 20 +++++++------------- src/pfa.c | 14 +++++++------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/kernaux/pfa.h b/include/kernaux/pfa.h index 2adff00..9bd7fad 100644 --- a/include/kernaux/pfa.h +++ b/include/kernaux/pfa.h @@ -11,31 +11,25 @@ extern "C" { #define KERNAUX_PFA_PAGE_SIZE (4 * 1024) #define KERNAUX_PFA_PAGES_COUNT_MAX (1024 * 1024) +typedef struct KernAux_PFA *KernAux_PFA; + struct KernAux_PFA { bool pages[KERNAUX_PFA_PAGES_COUNT_MAX]; }; -void KernAux_PFA_initialize(struct KernAux_PFA *pfa) +void KernAux_PFA_initialize(KernAux_PFA pfa) __attribute__((nonnull)); -void KernAux_PFA_mark_available( - struct KernAux_PFA *pfa, - size_t start, - size_t end -) +void KernAux_PFA_mark_available(KernAux_PFA pfa, size_t start, size_t end) __attribute__((nonnull)); -void KernAux_PFA_mark_unavailable( - struct KernAux_PFA *pfa, - size_t start, - size_t end -) +void KernAux_PFA_mark_unavailable(KernAux_PFA pfa, size_t start, size_t end) __attribute__((nonnull)); -size_t KernAux_PFA_alloc_page(struct KernAux_PFA *pfa) +size_t KernAux_PFA_alloc_page(KernAux_PFA pfa) __attribute__((nonnull)); -void KernAux_PFA_free_page(struct KernAux_PFA *pfa, size_t page_addr) +void KernAux_PFA_free_page(KernAux_PFA pfa, size_t page_addr) __attribute__((nonnull)); #ifdef __cplusplus diff --git a/src/pfa.c b/src/pfa.c index 0114641..be61c0e 100644 --- a/src/pfa.c +++ b/src/pfa.c @@ -6,20 +6,20 @@ #include static void KernAux_PFA_mark( - struct KernAux_PFA *pfa, + KernAux_PFA pfa, bool status, size_t start, size_t end ) __attribute__((nonnull)); -void KernAux_PFA_initialize(struct KernAux_PFA *const pfa) +void KernAux_PFA_initialize(const KernAux_PFA pfa) { kernaux_memset(pfa->pages, false, sizeof(pfa->pages)); } void KernAux_PFA_mark_available( - struct KernAux_PFA *const pfa, + const KernAux_PFA pfa, const size_t start, const size_t end ) { @@ -27,7 +27,7 @@ void KernAux_PFA_mark_available( } void KernAux_PFA_mark_unavailable( - struct KernAux_PFA *const pfa, + const KernAux_PFA pfa, const size_t start, const size_t end ) { @@ -35,7 +35,7 @@ void KernAux_PFA_mark_unavailable( } void KernAux_PFA_mark( - struct KernAux_PFA *const pfa, + const KernAux_PFA pfa, const bool status, size_t start, size_t end @@ -61,7 +61,7 @@ void KernAux_PFA_mark( } } -size_t KernAux_PFA_alloc_page(struct KernAux_PFA *const pfa) +size_t KernAux_PFA_alloc_page(const KernAux_PFA pfa) { // We start from 1 because 0 indicates failure. // It is not very usefull to alloc page at address 0; @@ -76,7 +76,7 @@ size_t KernAux_PFA_alloc_page(struct KernAux_PFA *const pfa) return 0; } -void KernAux_PFA_free_page(struct KernAux_PFA *const pfa, size_t page_addr) +void KernAux_PFA_free_page(const KernAux_PFA pfa, size_t page_addr) { if (page_addr % KERNAUX_PFA_PAGE_SIZE != 0) return;