mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
slab: fix linked list
This commit is contained in:
+23
-15
@@ -70,6 +70,9 @@ static bool growcache(scache_t *cache) {
|
|||||||
|
|
||||||
|
|
||||||
slab->next = cache->empty;
|
slab->next = cache->empty;
|
||||||
|
slab->prev = NULL;
|
||||||
|
if (slab->next)
|
||||||
|
slab->next->prev = slab;
|
||||||
cache->empty = slab;
|
cache->empty = slab;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -159,25 +162,24 @@ void *slab_allocate(scache_t *cache) {
|
|||||||
|
|
||||||
if (slab == cache->empty) {
|
if (slab == cache->empty) {
|
||||||
cache->empty = slab->next;
|
cache->empty = slab->next;
|
||||||
if (slab->prev)
|
|
||||||
slab->prev->next = slab->next;
|
|
||||||
if (slab->next)
|
if (slab->next)
|
||||||
slab->next->prev = slab->prev;
|
slab->next->prev = NULL;
|
||||||
|
|
||||||
if (cache->partial)
|
if (cache->partial)
|
||||||
cache->partial->prev = slab;
|
cache->partial->prev = slab;
|
||||||
|
|
||||||
slab->next = cache->partial;
|
slab->next = cache->partial;
|
||||||
slab->prev = NULL;
|
slab->prev = NULL;
|
||||||
cache->partial = slab;
|
cache->partial = slab;
|
||||||
}
|
} else if (slab->used == cache->slabobjcount) {
|
||||||
|
|
||||||
if (slab->used == cache->slabobjcount) {
|
|
||||||
cache->partial = slab->next;
|
cache->partial = slab->next;
|
||||||
if (slab->prev)
|
|
||||||
slab->prev->next = slab->next;
|
|
||||||
if (slab->next)
|
if (slab->next)
|
||||||
slab->next->prev = slab->prev;
|
slab->next->prev = NULL;
|
||||||
|
|
||||||
if (cache->full)
|
if (cache->full)
|
||||||
cache->full->prev = slab;
|
cache->full->prev = slab;
|
||||||
|
|
||||||
slab->next = cache->full;
|
slab->next = cache->full;
|
||||||
slab->prev = NULL;
|
slab->prev = NULL;
|
||||||
cache->full = slab;
|
cache->full = slab;
|
||||||
@@ -195,28 +197,34 @@ void slab_free(scache_t *cache, void *addr) {
|
|||||||
__assert(slab);
|
__assert(slab);
|
||||||
|
|
||||||
if (slab->used == 0) {
|
if (slab->used == 0) {
|
||||||
|
if (slab->prev == NULL)
|
||||||
cache->partial = slab->next;
|
cache->partial = slab->next;
|
||||||
if (slab->prev)
|
else
|
||||||
slab->prev->next = slab->next;
|
slab->prev->next = slab->next;
|
||||||
|
|
||||||
if (slab->next)
|
if (slab->next)
|
||||||
slab->next->prev = slab->prev;
|
slab->next->prev = slab->prev;
|
||||||
if (cache->empty)
|
|
||||||
cache->empty->prev = slab;
|
|
||||||
slab->next = cache->empty;
|
slab->next = cache->empty;
|
||||||
slab->prev = NULL;
|
slab->prev = NULL;
|
||||||
|
if (slab->next)
|
||||||
|
slab->next->prev = slab;
|
||||||
cache->empty = slab;
|
cache->empty = slab;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slab->used == cache->slabobjcount - 1) {
|
if (slab->used == cache->slabobjcount - 1) {
|
||||||
|
if (slab->prev == NULL)
|
||||||
cache->full = slab->next;
|
cache->full = slab->next;
|
||||||
if (slab->prev)
|
else
|
||||||
slab->prev->next = slab->next;
|
slab->prev->next = slab->next;
|
||||||
|
|
||||||
if (slab->next)
|
if (slab->next)
|
||||||
slab->next->prev = slab->prev;
|
slab->next->prev = slab->prev;
|
||||||
if (cache->partial)
|
|
||||||
cache->partial->prev = slab;
|
|
||||||
slab->next = cache->partial;
|
slab->next = cache->partial;
|
||||||
slab->prev = NULL;
|
slab->prev = NULL;
|
||||||
|
if (slab->next)
|
||||||
|
slab->next->prev = slab;
|
||||||
cache->partial = slab;
|
cache->partial = slab;
|
||||||
}
|
}
|
||||||
spinlock_release(&cache->lock);
|
spinlock_release(&cache->lock);
|
||||||
|
|||||||
Reference in New Issue
Block a user