Spinlock save cpu flags
This commit is contained in:
@@ -12,13 +12,13 @@
|
||||
|
||||
spin_lock_t _liballoc_lock = SPIN_LOCK_INIT;
|
||||
|
||||
int liballoc_lock (void) {
|
||||
spin_lock (&_liballoc_lock);
|
||||
int liballoc_lock (uint64_t* flags) {
|
||||
spin_lock (&_liballoc_lock, flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int liballoc_unlock (void) {
|
||||
spin_unlock (&_liballoc_lock);
|
||||
int liballoc_unlock (uint64_t flags) {
|
||||
spin_unlock (&_liballoc_lock, flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -242,12 +242,13 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
|
||||
|
||||
void* malloc (size_t size) {
|
||||
size = align_up (size, 16);
|
||||
uint64_t fla;
|
||||
|
||||
int index;
|
||||
void* ptr;
|
||||
struct boundary_tag* tag = NULL;
|
||||
|
||||
liballoc_lock ();
|
||||
liballoc_lock (&fla);
|
||||
|
||||
if (l_initialized == 0) {
|
||||
for (index = 0; index < MAXEXP; index++) {
|
||||
@@ -275,7 +276,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 (fla);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -308,23 +309,24 @@ void* malloc (size_t size) {
|
||||
|
||||
ptr = (void*)((uintptr_t)tag + sizeof (struct boundary_tag));
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (fla);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free (void* ptr) {
|
||||
int index;
|
||||
struct boundary_tag* tag;
|
||||
uint64_t flf;
|
||||
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
liballoc_lock ();
|
||||
liballoc_lock (&flf);
|
||||
|
||||
tag = (struct boundary_tag*)((uintptr_t)ptr - sizeof (struct boundary_tag));
|
||||
|
||||
if (tag->magic != LIBALLOC_MAGIC) {
|
||||
liballoc_unlock (); // release the lock
|
||||
liballoc_unlock (flf); // release the lock
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -357,7 +359,7 @@ void free (void* ptr) {
|
||||
|
||||
liballoc_free (tag, pages);
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (flf);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -368,7 +370,7 @@ void free (void* ptr) {
|
||||
|
||||
insert_tag (tag, index);
|
||||
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (flf);
|
||||
}
|
||||
|
||||
void* calloc (size_t nobj, size_t size) {
|
||||
@@ -388,6 +390,7 @@ void* realloc (void* p, size_t size) {
|
||||
void* ptr;
|
||||
struct boundary_tag* tag;
|
||||
int real_size;
|
||||
uint64_t flr;
|
||||
|
||||
if (size == 0) {
|
||||
free (p);
|
||||
@@ -397,11 +400,11 @@ void* realloc (void* p, size_t size) {
|
||||
return malloc (size);
|
||||
|
||||
if (&liballoc_lock != NULL)
|
||||
liballoc_lock (); // lockit
|
||||
liballoc_lock (&flr); // lockit
|
||||
tag = (struct boundary_tag*)((uintptr_t)p - sizeof (struct boundary_tag));
|
||||
real_size = tag->size;
|
||||
if (&liballoc_unlock != NULL)
|
||||
liballoc_unlock ();
|
||||
liballoc_unlock (flr);
|
||||
|
||||
if ((size_t)real_size > size)
|
||||
real_size = size;
|
||||
|
||||
Reference in New Issue
Block a user