From ecf881967da29c03cedeae2da6b63a0d4f1875dd Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sun, 12 Feb 2023 19:56:30 +0100 Subject: [PATCH] feature (kernel): Implemented 'bitmap_init' --- .wiki/Kernel-documentation.md | 4 ++-- kernel/src/utils/bitmap.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.wiki/Kernel-documentation.md b/.wiki/Kernel-documentation.md index f2c36b7..3033063 100644 --- a/.wiki/Kernel-documentation.md +++ b/.wiki/Kernel-documentation.md @@ -499,10 +499,10 @@ The size is the size of the buffer in bytes, to get the amount of storable bits #### `bitmap_init_from_buffer(buffer, size)` - function (bitmap_T) Creates a bitmap object from a given buffer and size -#### `bitmap_init(size)` - function (bitmap_T) [NOT IMPLEMENTED YET] +#### `bitmap_init(size)` - function (bitmap_T) Allocates memory to hold a bitmap in the given size and returns a `bitmap_T` with that buffer and size. -#### `bitmap_destruct(bitmap*)` - function (void) [NOT IMPLEMENTED YET] +#### `bitmap_destruct(bitmap*)` - function (void) Frees the memory of the given bitmap created with `bitmap_init`. #### `bitmap_set(bitmap*, index, value)` - function (bool) diff --git a/kernel/src/utils/bitmap.c b/kernel/src/utils/bitmap.c index 76342b4..122c36f 100644 --- a/kernel/src/utils/bitmap.c +++ b/kernel/src/utils/bitmap.c @@ -14,6 +14,7 @@ */ #include "utils/bitmap.h" +#include "utils/memory.h" bitmap_T bitmap_init_from_buffer(void* buffer, uint32_t size) { bitmap_T bitmap; @@ -23,11 +24,14 @@ bitmap_T bitmap_init_from_buffer(void* buffer, uint32_t size) { } bitmap_T bitmap_init(uint32_t size) { - // TODO: implement bitmap malloc constructor + bitmap_T bitmap; + bitmap.size = size / 8 + 1; + bitmap.buffer = memory_allocate(bitmap.size); + return bitmap; } void bitmap_destruct(bitmap_T* bitmap) { - + memory_free(bitmap->buffer); } bool bitmap_set(bitmap_T* bitmap, uint32_t index, bool value) {