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.)
parent 22aaffdf
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment