foo
This commit is contained in:
+4
-4
@@ -24,8 +24,6 @@ typedef struct {
|
||||
static struct slab slabs[8] = {0};
|
||||
|
||||
static errno_t slab_new(struct slab* slab, size_t size) {
|
||||
slab->lock = (struct spinlock){0};
|
||||
|
||||
// Allocate a new page for the head.
|
||||
phys_t addr;
|
||||
errno_t status = mem_phys_alloc(1, 0, &addr);
|
||||
@@ -68,8 +66,10 @@ void slab_init(void) {
|
||||
static void* slab_do_alloc(struct slab* slab) {
|
||||
spin_lock(&slab->lock);
|
||||
|
||||
if (__unlikely(slab->head == nullptr))
|
||||
slab_new(slab, slab->ent_size);
|
||||
if (__unlikely(slab->head == nullptr) && slab_new(slab, slab->ent_size) != 0) {
|
||||
spin_unlock(&slab->lock);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void** old_free = slab->head;
|
||||
slab->head = *old_free;
|
||||
|
||||
Reference in New Issue
Block a user