Implement lock IRQ nesting via stack variables/contexts
All checks were successful
Build documentation / build-and-deploy (push) Successful in 21s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 21s
This commit is contained in:
@@ -11,13 +11,13 @@
|
||||
|
||||
spin_lock_t _liballoc_lock = SPIN_LOCK_INIT;
|
||||
|
||||
int liballoc_lock (void) {
|
||||
spin_lock (&_liballoc_lock);
|
||||
int liballoc_lock (void* ctx) {
|
||||
spin_lock (&_liballoc_lock, (spin_lock_ctx_t*)ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int liballoc_unlock (void) {
|
||||
spin_unlock (&_liballoc_lock);
|
||||
int liballoc_unlock (void* ctx) {
|
||||
spin_unlock (&_liballoc_lock, (spin_lock_ctx_t*)ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -243,8 +243,9 @@ void* malloc (size_t size) {
|
||||
int index;
|
||||
void* ptr;
|
||||
struct boundary_tag* tag = NULL;
|
||||
spin_lock_ctx_t ctxliba;
|
||||
|
||||
liballoc_lock ();
|
||||
liballoc_lock (&ctxliba);
|
||||
|
||||
if (l_initialized == 0) {
|
||||
for (index = 0; index < MAXEXP; index++) {
|
||||
@@ -272,7 +273,7 @@ void* malloc (size_t size) {
|
||||
// No page found. Make one.
|
||||
if (tag == NULL) {
|
||||
if ((tag = allocate_new_tag (size)) == NULL) {
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (&ctxliba);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -305,23 +306,24 @@ void* malloc (size_t size) {
|
||||
|
||||
ptr = (void*)((uintptr_t)tag + sizeof (struct boundary_tag));
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (&ctxliba);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free (void* ptr) {
|
||||
int index;
|
||||
struct boundary_tag* tag;
|
||||
spin_lock_ctx_t ctxliba;
|
||||
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
liballoc_lock ();
|
||||
liballoc_lock (&ctxliba);
|
||||
|
||||
tag = (struct boundary_tag*)((uintptr_t)ptr - sizeof (struct boundary_tag));
|
||||
|
||||
if (tag->magic != LIBALLOC_MAGIC) {
|
||||
liballoc_unlock (); // release the lock
|
||||
liballoc_unlock (&ctxliba); // release the lock
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -354,7 +356,7 @@ void free (void* ptr) {
|
||||
|
||||
liballoc_free (tag, pages);
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (&ctxliba);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -365,7 +367,7 @@ void free (void* ptr) {
|
||||
|
||||
insert_tag (tag, index);
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (&ctxliba);
|
||||
}
|
||||
|
||||
void* calloc (size_t nobj, size_t size) {
|
||||
@@ -385,6 +387,7 @@ void* realloc (void* p, size_t size) {
|
||||
void* ptr;
|
||||
struct boundary_tag* tag;
|
||||
int real_size;
|
||||
spin_lock_ctx_t ctxliba;
|
||||
|
||||
if (size == 0) {
|
||||
free (p);
|
||||
@@ -394,11 +397,11 @@ void* realloc (void* p, size_t size) {
|
||||
return malloc (size);
|
||||
|
||||
if (&liballoc_lock != NULL)
|
||||
liballoc_lock (); // lockit
|
||||
liballoc_lock (&ctxliba); // lockit
|
||||
tag = (struct boundary_tag*)((uintptr_t)p - sizeof (struct boundary_tag));
|
||||
real_size = tag->size;
|
||||
if (&liballoc_unlock != NULL)
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (&ctxliba);
|
||||
|
||||
if ((size_t)real_size > size)
|
||||
real_size = size;
|
||||
|
||||
Reference in New Issue
Block a user