summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libtnttk/cache.c20
-rw-r--r--libtnttk/include/tnttk/cache.h5
2 files changed, 25 insertions, 0 deletions
diff --git a/libtnttk/cache.c b/libtnttk/cache.c
index e6e50d9..49fa6f5 100644
--- a/libtnttk/cache.c
+++ b/libtnttk/cache.c
@@ -29,6 +29,7 @@
static long page_size;
static long page_mask;
+static int initialized = 0;
/*
* Page alignment.
@@ -632,8 +633,27 @@ slab_reclaim(void)
}
void
+slab_terminate(void)
+{
+ initialized--;
+
+ if (initialized)
+ return;
+
+ slab_reclaim();
+ cache_lock(cache_cache);
+ assert(list_empty(&cache_cache->slabs));
+ cache_unlock(cache_cache);
+}
+
+void
slab_init(void)
{
+ initialized++;
+
+ if (initialized > 1)
+ return;
+
page_size = sysconf(_SC_PAGESIZE);
page_mask = page_size - 1;
diff --git a/libtnttk/include/tnttk/cache.h b/libtnttk/include/tnttk/cache.h
index 48920dc..3e289cb 100644
--- a/libtnttk/include/tnttk/cache.h
+++ b/libtnttk/include/tnttk/cache.h
@@ -75,6 +75,11 @@ void cache_show_info(cache_t cache);
void slab_reclaim(void);
/*
+ * Terminate the slab allocator.
+ */
+void slab_terminate(void);
+
+/*
* Initialize the slab allocator.
*/
void slab_init(void);