event.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: event.c,v 1.21 2007/06/19 23:47:17 tbox Exp $ */
00019 
00020 /*!
00021  * \file
00022  * \author Principal Author: Bob Halley
00023  */
00024 
00025 #include <config.h>
00026 
00027 #include <isc/event.h>
00028 #include <isc/mem.h>
00029 #include <isc/util.h>
00030 
00031 /***
00032  *** Events.
00033  ***/
00034 
00035 static void
00036 destroy(isc_event_t *event) {
00037         isc_mem_t *mctx = event->ev_destroy_arg;
00038 
00039         isc_mem_put(mctx, event, event->ev_size);
00040 }
00041 
00042 isc_event_t *
00043 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
00044                    isc_taskaction_t action, void *arg, size_t size)
00045 {
00046         isc_event_t *event;
00047 
00048         REQUIRE(size >= sizeof(struct isc_event));
00049         REQUIRE(action != NULL);
00050 
00051         event = isc_mem_get(mctx, size);
00052         if (event == NULL)
00053                 return (NULL);
00054 
00055         ISC_EVENT_INIT(event, size, 0, NULL, type, action, arg,
00056                        sender, destroy, mctx);
00057 
00058         return (event);
00059 }
00060 
00061 isc_event_t *
00062 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
00063                         isc_taskaction_t action, const void *arg, size_t size)
00064 {
00065         isc_event_t *event;
00066         void *deconst_arg;
00067 
00068         REQUIRE(size >= sizeof(struct isc_event));
00069         REQUIRE(action != NULL);
00070 
00071         event = isc_mem_get(mctx, size);
00072         if (event == NULL)
00073                 return (NULL);
00074 
00075         /*
00076          * Removing the const attribute from "arg" is the best of two
00077          * evils here.  If the event->ev_arg member is made const, then
00078          * it affects a great many users of the task/event subsystem
00079          * which are not passing in an "arg" which starts its life as
00080          * const.  Changing isc_event_allocate() and isc_task_onshutdown()
00081          * to not have "arg" prototyped as const (which is quite legitimate,
00082          * because neither of those functions modify arg) can cause
00083          * compiler whining anytime someone does want to use a const
00084          * arg that they themselves never modify, such as with
00085          * gcc -Wwrite-strings and using a string "arg".
00086          */
00087         DE_CONST(arg, deconst_arg);
00088 
00089         ISC_EVENT_INIT(event, size, 0, NULL, type, action, deconst_arg,
00090                        sender, destroy, mctx);
00091 
00092         return (event);
00093 }
00094 
00095 void
00096 isc_event_free(isc_event_t **eventp) {
00097         isc_event_t *event;
00098 
00099         REQUIRE(eventp != NULL);
00100         event = *eventp;
00101         REQUIRE(event != NULL);
00102 
00103         if (event->ev_destroy != NULL)
00104                 (event->ev_destroy)(event);
00105 
00106         *eventp = NULL;
00107 }

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha