2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 04:58:04 +00:00
bind/lib/isc/managers.c
Ondřej Surý b8d00e2e18
Change the loopmgr to be singleton
All the applications built on top of the loop manager were required to
create just a single instance of the loop manager.  Refactor the loop
manager to not expose this instance to the callers and keep the loop
manager object internal to the isc_loop compilation unit.

This significantly simplifies a number of data structures and calls to
the isc_loop API.
2025-07-23 22:44:16 +02:00

48 lines
1.2 KiB
C

/*
* 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.
*/
#include <isc/loop.h>
#include <isc/managers.h>
#include <isc/rwlock.h>
#include <isc/util.h>
#include <isc/uv.h>
void
isc_managers_create(isc_mem_t **mctxp, uint32_t workers, isc_nm_t **netmgrp) {
REQUIRE(mctxp != NULL && *mctxp == NULL);
isc_mem_create("managers", mctxp);
INSIST(*mctxp != NULL);
isc_loopmgr_create(*mctxp, workers);
REQUIRE(netmgrp != NULL && *netmgrp == NULL);
isc_netmgr_create(*mctxp, netmgrp);
INSIST(*netmgrp != NULL);
isc_rwlock_setworkers(workers);
}
void
isc_managers_destroy(isc_mem_t **mctxp, isc_nm_t **netmgrp) {
REQUIRE(mctxp != NULL && *mctxp != NULL);
REQUIRE(netmgrp != NULL && *netmgrp != NULL);
/*
* The sequence of operations here is important:
*/
isc_nm_detach(netmgrp);
isc_loopmgr_destroy();
isc_mem_detach(mctxp);
}