From b350d38ddedf1e2376c32fd1011b5ce60e50ae45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 19 Sep 2018 19:39:26 +0200 Subject: [PATCH] worker: safer code around the mempool freelist I did NOT remove this one, as in a quick profile that would be increase in roughly 0.5% time in malloc, so that's possibly justifiable. (And this one is much less obstructing to splitting the worker code.) --- daemon/worker.c | 18 ++++++++++-------- daemon/worker.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/daemon/worker.c b/daemon/worker.c index 90004649b..b6eb5939f 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1797,17 +1797,19 @@ static int worker_reserve(struct worker_ctx *worker, size_t ring_maxlen) return kr_ok(); } -#define reclaim_freelist(list, type, cb) \ - for (unsigned i = 0; i < list.len; ++i) { \ - void *elm = list.at[i]; \ - kr_asan_unpoison(elm, sizeof(type)); \ - cb(elm); \ - } \ - array_clear(list) +static inline void reclaim_mp_freelist(mp_freelist_t *list) +{ + for (unsigned i = 0; i < list->len; ++i) { + struct mempool *e = list->at[i]; + kr_asan_unpoison(e, sizeof(*e)); + mp_delete(e); + } + array_clear(*list); +} void worker_reclaim(struct worker_ctx *worker) { - reclaim_freelist(worker->pool_mp, struct mempool, mp_delete); + reclaim_mp_freelist(&worker->pool_mp); mp_delete(worker->pkt_pool.ctx); worker->pkt_pool.ctx = NULL; trie_free(worker->subreq_out); diff --git a/daemon/worker.h b/daemon/worker.h index 5814a4bd3..dd9847672 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -109,7 +109,7 @@ void worker_request_set_source_session(struct request_ctx *, struct session *ses #define MAX_TCP_INACTIVITY (KR_RESOLVE_TIME_LIMIT + KR_CONN_RTT_MAX) /** Freelist of available mempools. */ -typedef array_t(void *) mp_freelist_t; +typedef array_t(struct mempool *) mp_freelist_t; /** List of query resolution tasks. */ typedef array_t(struct qr_task *) qr_tasklist_t; -- 2.47.2