summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/resource.h1
-rw-r--r--lib/slab.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/resource.h b/lib/resource.h
index ad17d9ed..b56bcff5 100644
--- a/lib/resource.h
+++ b/lib/resource.h
@@ -83,6 +83,7 @@ typedef struct slab slab;
slab *sl_new(pool *, unsigned size);
void *sl_alloc(slab *);
+void *sl_allocz(slab *);
void sl_free(slab *, void *);
/*
diff --git a/lib/slab.c b/lib/slab.c
index c3035b45..f31355e0 100644
--- a/lib/slab.c
+++ b/lib/slab.c
@@ -88,6 +88,14 @@ sl_alloc(slab *s)
return o->data;
}
+void *
+sl_allocz(slab *s)
+{
+ void *obj = sl_alloc(s);
+ memset(obj, 0, s->size);
+ return obj;
+}
+
void
sl_free(slab *s, void *oo)
{
@@ -279,6 +287,22 @@ no_partial:
}
/**
+ * sl_allocz - allocate an object from Slab and zero it
+ * @s: slab
+ *
+ * sl_allocz() allocates space for a single object from the
+ * Slab and returns a pointer to the object after zeroing out
+ * the object memory.
+ */
+void *
+sl_allocz(slab *s)
+{
+ void *obj = sl_alloc(s);
+ memset(obj, 0, s->data_size);
+ return obj;
+}
+
+/**
* sl_free - return a free object back to a Slab
* @s: slab
* @oo: object returned by sl_alloc()