feat: closedir(2)
[lunaix-os.git] / lunaix-os / kernel / mm / cake.c
index 5aa9bef0d97a4e259c9f666431fa71c12a5065fb..5e03d347706c8943b08c9f2792aecb9d7765aad7 100644 (file)
@@ -120,6 +120,12 @@ cake_new_pile(char* name,
     return pile;
 }
 
+void
+cake_set_constructor(struct cake_pile* pile, pile_cb ctor)
+{
+    pile->ctor = ctor;
+}
+
 void*
 cake_grab(struct cake_pile* pile)
 {
@@ -147,8 +153,14 @@ cake_grab(struct cake_pile* pile)
         llist_append(&pile->partial, &pos->cakes);
     }
 
-    return (void*)((uintptr_t)pos->first_piece +
-                   found_index * pile->piece_size);
+    void* ptr =
+      (void*)((uintptr_t)pos->first_piece + found_index * pile->piece_size);
+
+    if (pile->ctor) {
+        pile->ctor(pile, ptr);
+    }
+
+    return ptr;
 }
 
 int
@@ -188,4 +200,10 @@ found:
     }
 
     return 1;
+}
+
+void
+cake_ctor_zeroing(struct cake_pile* pile, void* piece)
+{
+    memset(piece, 0, pile->piece_size);
 }
\ No newline at end of file