From 62a72211aa0adf5078365de0b54e336efa472a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 18 Mar 2022 12:50:18 +0100 Subject: [PATCH] Remove isc_pool API Since the last user of the isc_pool API is gone, remove the whole isc_pool API. --- lib/dns/zone.c | 1 - lib/isc/Makefile.am | 2 - lib/isc/include/isc/pool.h | 100 ------------------------- lib/isc/pool.c | 94 ------------------------ lib/isc/tests/Makefile.am | 1 - lib/isc/tests/pool_test.c | 146 ------------------------------------- 6 files changed, 344 deletions(-) delete mode 100644 lib/isc/include/isc/pool.h delete mode 100644 lib/isc/pool.c delete mode 100644 lib/isc/tests/pool_test.c diff --git a/lib/dns/zone.c b/lib/dns/zone.c index e8f5092cbb..a7d3610bb6 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index e2760034f1..c0bb69fa4a 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -63,7 +63,6 @@ libisc_la_HEADERS = \ include/isc/once.h \ include/isc/os.h \ include/isc/parseint.h \ - include/isc/pool.h \ include/isc/portset.h \ include/isc/print.h \ include/isc/quota.h \ @@ -167,7 +166,6 @@ libisc_la_SOURCES = \ os.c \ os_p.h \ parseint.c \ - pool.c \ portset.c \ quota.c \ radix.c \ diff --git a/lib/isc/include/isc/pool.h b/lib/isc/include/isc/pool.h deleted file mode 100644 index a08e1f21a4..0000000000 --- a/lib/isc/include/isc/pool.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * SPDX-License-Identifier: MPL-2.0 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#pragma once - -/***** -***** Module Info -*****/ - -/*! \file isc/pool.h - * \brief An object pool is a mechanism for sharing a small pool of - * fungible objects among a large number of objects that depend on them. - * - * This is useful, for example, when it causes performance problems for - * large number of zones to share a single memory context or task object, - * but it would create a different set of problems for them each to have an - * independent task or memory context. - */ - -/*** - *** Imports. - ***/ - -#include -#include -#include - -ISC_LANG_BEGINDECLS - -/***** -***** Types. -*****/ - -typedef void (*isc_pooldeallocator_t)(void **object); - -typedef isc_result_t (*isc_poolinitializer_t)(void **target, void *arg); - -typedef struct isc_pool isc_pool_t; - -/***** -***** Functions. -*****/ - -isc_result_t -isc_pool_create(isc_mem_t *mctx, unsigned int count, isc_pooldeallocator_t free, - isc_poolinitializer_t init, void *initarg, isc_pool_t **poolp); -/*%< - * Create a pool of "count" object pointers. If 'free' is not NULL, - * it points to a function that will detach the objects. 'init' - * points to a function that will initialize the arguments, and - * 'arg' to an argument to be passed into that function (for example, - * a relevant manager or context object). - * - * Requires: - * - *\li 'mctx' is a valid memory context. - * - *\li init != NULL - * - *\li poolp != NULL && *poolp == NULL - * - * Ensures: - * - *\li On success, '*poolp' points to the new object pool. - * - * Returns: - * - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOMEMORY - *\li #ISC_R_UNEXPECTED - */ - -void * -isc_pool_get(isc_pool_t *pool, unsigned int tid); -/*%< - * Returns a pointer to an object from the pool. Currently the object - * is chosen from the pool at random. - */ - -void -isc_pool_destroy(isc_pool_t **poolp); -/*%< - * Destroy a task pool. The tasks in the pool are detached but not - * shut down. - * - * Requires: - * \li '*poolp' is a valid task pool. - */ - -ISC_LANG_ENDDECLS diff --git a/lib/isc/pool.c b/lib/isc/pool.c deleted file mode 100644 index 66fa09c1fa..0000000000 --- a/lib/isc/pool.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * SPDX-License-Identifier: MPL-2.0 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -/*! \file */ - -#include - -#include -#include -#include -#include - -/*** - *** Types. - ***/ - -struct isc_pool { - isc_mem_t *mctx; - unsigned int count; - isc_pooldeallocator_t free; - isc_poolinitializer_t init; - void *initarg; - void **pool; -}; - -/*** - *** Functions. - ***/ - -isc_result_t -isc_pool_create(isc_mem_t *mctx, unsigned int count, - isc_pooldeallocator_t release, isc_poolinitializer_t init, - void *initarg, isc_pool_t **poolp) { - isc_pool_t *pool = NULL; - isc_result_t result; - unsigned int i; - - INSIST(count > 0); - - /* Allocate the pool structure */ - pool = isc_mem_get(mctx, sizeof(*pool)); - *pool = (isc_pool_t){ - .count = count, - .free = release, - .init = init, - .initarg = initarg, - }; - isc_mem_attach(mctx, &pool->mctx); - pool->pool = isc_mem_get(mctx, count * sizeof(void *)); - memset(pool->pool, 0, count * sizeof(void *)); - - /* Populate the pool */ - for (i = 0; i < count; i++) { - result = init(&pool->pool[i], initarg); - if (result != ISC_R_SUCCESS) { - isc_pool_destroy(&pool); - return (result); - } - } - - *poolp = pool; - return (ISC_R_SUCCESS); -} - -void * -isc_pool_get(isc_pool_t *pool, unsigned int tid) { - REQUIRE(tid < pool->count); - - return (pool->pool[tid]); -} - -void -isc_pool_destroy(isc_pool_t **poolp) { - unsigned int i; - isc_pool_t *pool = *poolp; - *poolp = NULL; - for (i = 0; i < pool->count; i++) { - if (pool->free != NULL && pool->pool[i] != NULL) { - pool->free(&pool->pool[i]); - } - } - isc_mem_put(pool->mctx, pool->pool, pool->count * sizeof(void *)); - isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool)); -} diff --git a/lib/isc/tests/Makefile.am b/lib/isc/tests/Makefile.am index 1aba558ddc..4e93cfa3b5 100644 --- a/lib/isc/tests/Makefile.am +++ b/lib/isc/tests/Makefile.am @@ -30,7 +30,6 @@ check_PROGRAMS = \ netaddr_test \ netmgr_test \ parse_test \ - pool_test \ quota_test \ radix_test \ random_test \ diff --git a/lib/isc/tests/pool_test.c b/lib/isc/tests/pool_test.c deleted file mode 100644 index 3ced1a2932..0000000000 --- a/lib/isc/tests/pool_test.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * SPDX-License-Identifier: MPL-2.0 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#if HAVE_CMOCKA - -#include /* IWYU pragma: keep */ -#include -#include -#include -#include -#include -#include - -#define UNIT_TESTING -#include - -#include -#include -#include - -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} - -static isc_result_t -poolinit(void **target, void *arg) { - isc_result_t result; - - isc_taskmgr_t *mgr = (isc_taskmgr_t *)arg; - isc_task_t *task = NULL; - result = isc_task_create(mgr, 0, &task); - if (result != ISC_R_SUCCESS) { - return (result); - } - - *target = (void *)task; - return (ISC_R_SUCCESS); -} - -static void -poolfree(void **target) { - isc_task_t *task = *(isc_task_t **)target; - isc_task_destroy(&task); - *target = NULL; -} - -/* Create a pool */ -static void -create_pool(void **state) { - isc_result_t result; - isc_pool_t *pool = NULL; - - UNUSED(state); - - result = isc_pool_create(test_mctx, 8, poolfree, poolinit, taskmgr, - &pool); - assert_int_equal(result, ISC_R_SUCCESS); - - isc_pool_destroy(&pool); - assert_null(pool); -} - -/* Get objects */ -static void -get_objects(void **state) { - isc_result_t result; - isc_pool_t *pool = NULL; - void *item; - isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL; - - UNUSED(state); - - result = isc_pool_create(test_mctx, 2, poolfree, poolinit, taskmgr, - &pool); - assert_int_equal(result, ISC_R_SUCCESS); - - item = isc_pool_get(pool, 0); - assert_non_null(item); - isc_task_attach((isc_task_t *)item, &task1); - - item = isc_pool_get(pool, 1); - assert_non_null(item); - isc_task_attach((isc_task_t *)item, &task2); - - item = isc_pool_get(pool, 0); - assert_non_null(item); - isc_task_attach((isc_task_t *)item, &task3); - - isc_task_detach(&task1); - isc_task_detach(&task2); - isc_task_detach(&task3); - - isc_pool_destroy(&pool); - assert_null(pool); -} - -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(create_pool, _setup, _teardown), - cmocka_unit_test_setup_teardown(get_objects, _setup, _teardown), - }; - - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */