Mercurial > libjeffpc
changeset 802:aa6e8f99966f
taskq: use a mem cache to allocate taskq item structs
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 09 Apr 2020 12:15:48 -0400 |
parents | ddeb5fa3ea47 |
children | 32d261e8b47f |
files | taskq.c |
diffstat | 1 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/taskq.c Thu Apr 09 12:15:24 2020 -0400 +++ b/taskq.c Thu Apr 09 12:15:48 2020 -0400 @@ -30,11 +30,15 @@ static LOCK_CLASS(taskq_lc); static struct mem_cache *taskq_cache; +static struct mem_cache *taskq_item_cache; static void __attribute__((constructor)) init_taskq_subsys(void) { taskq_cache = mem_cache_create("taskq-cache", sizeof(struct taskq), 0); ASSERT(!IS_ERR(taskq_cache)); + taskq_item_cache = mem_cache_create("taskq-item-cache", + sizeof(struct taskq_item), 0); + ASSERT(!IS_ERR(taskq_item_cache)); } static void enqueue(struct taskq *tq, struct taskq_item *item) @@ -77,7 +81,7 @@ item->fxn(item->arg); - free(item); + mem_cache_free(taskq_item_cache, item); MXLOCK(&tq->lock); @@ -184,7 +188,7 @@ { struct taskq_item *item; - item = malloc(sizeof(struct taskq_item)); + item = mem_cache_alloc(taskq_item_cache); if (!item) return -ENOMEM;