Remove isc_pool API

Since the last user of the isc_pool API is gone, remove the whole
isc_pool API.
This commit is contained in:
Ondřej Surý 2022-03-18 12:50:18 +01:00
parent 2bc7303af2
commit 62a72211aa
6 changed files with 0 additions and 344 deletions

View file

@ -23,7 +23,6 @@
#include <isc/hex.h>
#include <isc/md.h>
#include <isc/mutex.h>
#include <isc/pool.h>
#include <isc/print.h>
#include <isc/random.h>
#include <isc/ratelimiter.h>

View file

@ -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 \

View file

@ -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 <isc/lang.h>
#include <isc/mem.h>
#include <isc/types.h>
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

View file

@ -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 <string.h>
#include <isc/mem.h>
#include <isc/pool.h>
#include <isc/random.h>
#include <isc/util.h>
/***
*** 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));
}

View file

@ -30,7 +30,6 @@ check_PROGRAMS = \
netaddr_test \
netmgr_test \
parse_test \
pool_test \
quota_test \
radix_test \
random_test \

View file

@ -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 <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/mem.h>
#include <isc/pool.h>
#include <isc/util.h>
#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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */