voron

experimental ARM OS
git clone git://git.2f30.org/voron.git
Log | Files | Refs | LICENSE

commit 4965eb05948f3bd624b854b4656765a9959c33f2
parent 2033c875fcbcd0c21d1adf3f92d2d1d42a2ceeb6
Author: sin <sin@2f30.org>
Date:   Tue Jul 16 22:41:13 +0100

Use a spinlock around the arenas functions

Diffstat:
kernel/arenas.c | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/kernel/arenas.c b/kernel/arenas.c @@ -1,6 +1,7 @@ #include <kernel.h> #include <mmu.h> #include <alloc.h> +#include <spinlock.h> #include <arenas.h> struct arena { @@ -16,6 +17,7 @@ struct arenas { }; static int ndebug = 0; +static spinlock_t arenas_lock = SPINLOCK_INIT; struct arenas * arenas_init(void) @@ -36,12 +38,14 @@ arenas_free(struct arenas *arenas) struct arena *arena; size_t i; + spinlock_lock(&arenas_lock); for (i = 0; i < arenas->siz; i++) { arena = &arenas->arena[i]; kfree(arena->mem); } kfree(arenas->arena); kfree(arenas); + spinlock_unlock(&arenas_lock); } void * @@ -51,6 +55,7 @@ arena_alloc(struct arenas *arenas, size_t n, arena_id id) struct arena *arena; size_t i; + spinlock_lock(&arenas_lock); for (i = 0; i < arenas->siz; i++) { arena = &arenas->arena[i]; if (arena->id == id) { @@ -61,6 +66,7 @@ arena_alloc(struct arenas *arenas, size_t n, arena_id id) kprintf("Found unused arena:%d of size %zu bytes\n", arena->id, arena->siz); arena->used = 1; + spinlock_unlock(&arenas_lock); return arena->mem; } } @@ -81,6 +87,7 @@ arena_alloc(struct arenas *arenas, size_t n, arena_id id) panic("out of memory"); arena->siz = n; arenas->siz++; + spinlock_unlock(&arenas_lock); return arena->mem; } @@ -90,9 +97,11 @@ arena_free(struct arenas *arenas, arena_id id) struct arena *arena; size_t i; + spinlock_lock(&arenas_lock); for (i = 0; i < arenas->siz; i++) { arena = &arenas->arena[i]; if (arena->id == id) arena->used = 0; } + spinlock_unlock(&arenas_lock); }