"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/ns/lib.c" (4 Sep 2020, 1655 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lib.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file */
   13 
   14 #include <stdbool.h>
   15 #include <stddef.h>
   16 
   17 #include <isc/mem.h>
   18 #include <isc/mutex.h>
   19 #include <isc/once.h>
   20 #include <isc/refcount.h>
   21 #include <isc/util.h>
   22 
   23 #include <dns/name.h>
   24 
   25 #include <ns/lib.h>
   26 
   27 /***
   28  *** Globals
   29  ***/
   30 
   31 LIBNS_EXTERNAL_DATA unsigned int ns_pps = 0U;
   32 
   33 /***
   34  *** Private
   35  ***/
   36 
   37 static isc_once_t init_once = ISC_ONCE_INIT;
   38 static isc_mem_t *ns_g_mctx = NULL;
   39 static bool initialize_done = false;
   40 static isc_refcount_t references;
   41 
   42 static void
   43 initialize(void) {
   44     REQUIRE(!initialize_done);
   45 
   46     isc_mem_create(&ns_g_mctx);
   47 
   48     isc_refcount_init(&references, 0);
   49     initialize_done = true;
   50     return;
   51 }
   52 
   53 isc_result_t
   54 ns_lib_init(void) {
   55     isc_result_t result;
   56 
   57     /*
   58      * Since this routine is expected to be used by a normal application,
   59      * it should be better to return an error, instead of an emergency
   60      * abort, on any failure.
   61      */
   62     result = isc_once_do(&init_once, initialize);
   63     if (result != ISC_R_SUCCESS) {
   64         return (result);
   65     }
   66 
   67     if (!initialize_done) {
   68         return (ISC_R_FAILURE);
   69     }
   70 
   71     isc_refcount_increment0(&references);
   72 
   73     return (ISC_R_SUCCESS);
   74 }
   75 
   76 void
   77 ns_lib_shutdown(void) {
   78     if (isc_refcount_decrement(&references) == 1) {
   79         isc_refcount_destroy(&references);
   80         if (ns_g_mctx != NULL) {
   81             isc_mem_detach(&ns_g_mctx);
   82         }
   83     }
   84 }