]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
worker: safer code around the mempool freelist
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 19 Sep 2018 17:39:26 +0000 (19:39 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 12 Oct 2018 15:36:44 +0000 (17:36 +0200)
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
daemon/worker.h

index 90004649b426a958d4c12d8e9663310db7ad2c10..b6eb5939ff9fb590ac4f77b961eef126acb76e1e 100644 (file)
@@ -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);
index 5814a4bd37f56b035b3cfb3ad793691627a7bac5..dd98476728eed04e5ef4fc555def29893d9389e1 100644 (file)
@@ -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;