managers.c revision 1.5 1 /* $NetBSD: managers.c,v 1.5 2025/01/26 16:25:37 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16 #include <isc/managers.h>
17 #include <isc/rwlock.h>
18 #include <isc/util.h>
19 #include <isc/uv.h>
20
21 void
22 isc_managers_create(isc_mem_t **mctxp, uint32_t workers,
23 isc_loopmgr_t **loopmgrp, isc_nm_t **netmgrp) {
24 REQUIRE(mctxp != NULL && *mctxp == NULL);
25 isc_mem_create(mctxp);
26 INSIST(*mctxp != NULL);
27
28 REQUIRE(loopmgrp != NULL && *loopmgrp == NULL);
29 isc_loopmgr_create(*mctxp, workers, loopmgrp);
30 INSIST(*loopmgrp != NULL);
31
32 REQUIRE(netmgrp != NULL && *netmgrp == NULL);
33 isc_netmgr_create(*mctxp, *loopmgrp, netmgrp);
34 INSIST(*netmgrp != NULL);
35
36 isc_rwlock_setworkers(workers);
37 }
38
39 void
40 isc_managers_destroy(isc_mem_t **mctxp, isc_loopmgr_t **loopmgrp,
41 isc_nm_t **netmgrp) {
42 REQUIRE(mctxp != NULL && *mctxp != NULL);
43 REQUIRE(loopmgrp != NULL && *loopmgrp != NULL);
44 REQUIRE(netmgrp != NULL && *netmgrp != NULL);
45
46 /*
47 * The sequence of operations here is important:
48 */
49
50 isc_netmgr_destroy(netmgrp);
51 isc_loopmgr_destroy(loopmgrp);
52 isc_mem_destroy(mctxp);
53 }
54