diff options
author | Richard Braun <syn@sceen.net> | 2007-07-09 23:17:31 +0000 |
---|---|---|
committer | Richard Braun <syn@sceen.net> | 2007-07-09 23:17:31 +0000 |
commit | 5c50fe6384f5e9f29312e3b9afef5c2b58000c40 (patch) | |
tree | ccf4079902fe8ce0bd27a955d5258d7f259983e1 | |
parent | 0f49d977b0a24164949ccc22a30c6514842ffb9b (diff) |
Improved initialization and termination of the slab allocator.
-rw-r--r-- | libtnttk/cache.c | 20 | ||||
-rw-r--r-- | libtnttk/include/tnttk/cache.h | 5 |
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); |