mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-23 18:49:54 +00:00
110 lines
2.8 KiB
C
110 lines
2.8 KiB
C
|
/*
|
||
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
|
#include <isc/hp.h>
|
||
|
#include <isc/managers.h>
|
||
|
#include <isc/util.h>
|
||
|
|
||
|
#include "netmgr_p.h"
|
||
|
#include "socket_p.h"
|
||
|
#include "task_p.h"
|
||
|
#include "timer_p.h"
|
||
|
|
||
|
isc_result_t
|
||
|
isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum,
|
||
|
size_t sockets, isc_nm_t **netmgrp,
|
||
|
isc_taskmgr_t **taskmgrp, isc_timermgr_t **timermgrp,
|
||
|
isc_socketmgr_t **socketmgrp) {
|
||
|
isc_result_t result;
|
||
|
isc_nm_t *netmgr = NULL;
|
||
|
isc_socketmgr_t *socketmgr = NULL;
|
||
|
isc_taskmgr_t *taskmgr = NULL;
|
||
|
isc_timermgr_t *timermgr = NULL;
|
||
|
|
||
|
/*
|
||
|
* We have ncpus network threads, ncpus old network threads - make
|
||
|
* it 4x just to be on the safe side.
|
||
|
*/
|
||
|
isc_hp_init(4 * workers);
|
||
|
|
||
|
REQUIRE(netmgrp != NULL && *netmgrp == NULL);
|
||
|
isc__netmgr_create(mctx, workers, &netmgr);
|
||
|
*netmgrp = netmgr;
|
||
|
INSIST(netmgr != NULL);
|
||
|
|
||
|
REQUIRE(taskmgrp == NULL || *taskmgrp == NULL);
|
||
|
if (taskmgrp != NULL) {
|
||
|
result = isc__taskmgr_create(mctx, quantum, netmgr, &taskmgr);
|
||
|
if (result != ISC_R_SUCCESS) {
|
||
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||
|
"isc_taskmgr_create() failed: %s",
|
||
|
isc_result_totext(result));
|
||
|
goto fail;
|
||
|
}
|
||
|
*taskmgrp = taskmgr;
|
||
|
}
|
||
|
|
||
|
REQUIRE(timermgrp == NULL || *timermgrp == NULL);
|
||
|
if (timermgrp != NULL) {
|
||
|
result = isc__timermgr_create(mctx, &timermgr);
|
||
|
if (result != ISC_R_SUCCESS) {
|
||
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||
|
"isc_timermgr_create() failed: %s",
|
||
|
isc_result_totext(result));
|
||
|
goto fail;
|
||
|
}
|
||
|
*timermgrp = timermgr;
|
||
|
}
|
||
|
|
||
|
REQUIRE(socketmgrp == NULL || *socketmgrp == NULL);
|
||
|
if (socketmgrp != NULL) {
|
||
|
result = isc__socketmgr_create(mctx, &socketmgr, sockets,
|
||
|
workers);
|
||
|
if (result != ISC_R_SUCCESS) {
|
||
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||
|
"isc_socketmgr_create() failed: %s",
|
||
|
isc_result_totext(result));
|
||
|
goto fail;
|
||
|
}
|
||
|
*socketmgrp = socketmgr;
|
||
|
}
|
||
|
|
||
|
return (ISC_R_SUCCESS);
|
||
|
fail:
|
||
|
isc_managers_destroy(netmgrp, taskmgrp, timermgrp, socketmgrp);
|
||
|
|
||
|
return (result);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
isc_managers_destroy(isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp,
|
||
|
isc_timermgr_t **timermgrp, isc_socketmgr_t **socketmgrp) {
|
||
|
if (netmgrp != NULL && *netmgrp != NULL) {
|
||
|
isc_nm_closedown(*netmgrp);
|
||
|
}
|
||
|
|
||
|
if (taskmgrp != NULL && *taskmgrp != NULL) {
|
||
|
isc__taskmgr_destroy(taskmgrp);
|
||
|
}
|
||
|
|
||
|
if (netmgrp != NULL && *netmgrp != NULL) {
|
||
|
isc__netmgr_destroy(netmgrp);
|
||
|
}
|
||
|
|
||
|
if (timermgrp != NULL && *timermgrp != NULL) {
|
||
|
isc__timermgr_destroy(timermgrp);
|
||
|
}
|
||
|
|
||
|
if (socketmgrp != NULL && *socketmgrp != NULL) {
|
||
|
isc__socketmgr_destroy(socketmgrp);
|
||
|
}
|
||
|
}
|