"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/event.c" (4 Sep 2020, 2403 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.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 "event.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 /*!
   13  * \file
   14  */
   15 
   16 #include <isc/event.h>
   17 #include <isc/mem.h>
   18 #include <isc/util.h>
   19 
   20 /***
   21  *** Events.
   22  ***/
   23 
   24 static void
   25 destroy(isc_event_t *event) {
   26     isc_mem_t *mctx = event->ev_destroy_arg;
   27 
   28     isc_mem_put(mctx, event, event->ev_size);
   29 }
   30 
   31 isc_event_t *
   32 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
   33            isc_taskaction_t action, void *arg, size_t size) {
   34     isc_event_t *event;
   35 
   36     REQUIRE(size >= sizeof(struct isc_event));
   37     REQUIRE(action != NULL);
   38 
   39     event = isc_mem_get(mctx, size);
   40 
   41     ISC_EVENT_INIT(event, size, 0, NULL, type, action, arg, sender, destroy,
   42                mctx);
   43 
   44     return (event);
   45 }
   46 
   47 isc_event_t *
   48 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
   49             isc_taskaction_t action, const void *arg, size_t size) {
   50     isc_event_t *event;
   51     void *deconst_arg;
   52 
   53     REQUIRE(size >= sizeof(struct isc_event));
   54     REQUIRE(action != NULL);
   55 
   56     event = isc_mem_get(mctx, size);
   57 
   58     /*
   59      * Removing the const attribute from "arg" is the best of two
   60      * evils here.  If the event->ev_arg member is made const, then
   61      * it affects a great many users of the task/event subsystem
   62      * which are not passing in an "arg" which starts its life as
   63      * const.  Changing isc_event_allocate() and isc_task_onshutdown()
   64      * to not have "arg" prototyped as const (which is quite legitimate,
   65      * because neither of those functions modify arg) can cause
   66      * compiler whining anytime someone does want to use a const
   67      * arg that they themselves never modify, such as with
   68      * gcc -Wwrite-strings and using a string "arg".
   69      */
   70     DE_CONST(arg, deconst_arg);
   71 
   72     ISC_EVENT_INIT(event, size, 0, NULL, type, action, deconst_arg, sender,
   73                destroy, mctx);
   74 
   75     return (event);
   76 }
   77 
   78 void
   79 isc_event_free(isc_event_t **eventp) {
   80     isc_event_t *event;
   81 
   82     REQUIRE(eventp != NULL);
   83     event = *eventp;
   84     *eventp = NULL;
   85     REQUIRE(event != NULL);
   86 
   87     REQUIRE(!ISC_LINK_LINKED(event, ev_link));
   88     REQUIRE(!ISC_LINK_LINKED(event, ev_ratelink));
   89 
   90     if (event->ev_destroy != NULL) {
   91         (event->ev_destroy)(event);
   92     }
   93 }