]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
contrib/mempattern: add mm_ctx_delete()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Oct 2021 07:53:34 +0000 (09:53 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 3 Nov 2021 14:42:48 +0000 (15:42 +0100)
It was a bit weird that the API had mempool creation but no deletion.

contrib/mempattern.h
tests/unit/meson.build

index 0b9957b1dd35421c7a30efcdb4df123d868d4156..a0cd9a62d29bd3a30cedbe607e1ac14e0e031381 100644 (file)
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <libknot/mm_ctx.h>
+#include "contrib/ucw/mempool.h"
 #include "lib/defines.h"
 #include <assert.h>
 #include <stdint.h>
@@ -55,6 +56,17 @@ void mm_ctx_mempool(knot_mm_t *mm, size_t chunk_size);
 
 /* API in addition to Knot's mempattern. */
 
+/*! \brief New memory pool context, allocated on itself. */
+KR_EXPORT knot_mm_t * mm_ctx_mempool2(size_t chunk_size);
+
+/*! \brief Delete a memory pool.  OK to call on a non-pool. */
+static inline void mm_ctx_delete(knot_mm_t *mm)
+{
+       /* The mp_alloc comparison bears a risk of missing the private symbol from knot. */
+       if (mm && mm->ctx && mm->alloc == (knot_mm_alloc_t)mp_alloc)
+               mp_delete(mm->ctx);
+}
+
 /*! \brief Readability: avoid const-casts in code. */
 static inline void free_const(const void *what)
 {
@@ -78,6 +90,3 @@ static inline void mm_ctx_init_aligned(knot_mm_t *mm, size_t alignment)
        }
 }
 
-/*! \brief New memory pool context, allocated on itself. */
-KR_EXPORT knot_mm_t * mm_ctx_mempool2(size_t chunk_size);
-
index a133e618031d26232a356669f5f0248779de2bbd..b10789cc2a8448788e1a762fd787e5f4cdb5bfae 100644 (file)
@@ -11,7 +11,7 @@ mock_cmodule_mod = shared_module(
   mock_cmodule_src,
   name_prefix: '',
   dependencies: libknot,
-  include_directories: include_directories('../../'),
+  include_directories: mod_inc_dir,
 )
 
 # executables with tests