1258945Sroberto/* 2258945Sroberto * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3258945Sroberto * Copyright (C) 1998-2001 Internet Software Consortium. 4258945Sroberto * 5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any 6258945Sroberto * purpose with or without fee is hereby granted, provided that the above 7258945Sroberto * copyright notice and this permission notice appear in all copies. 8258945Sroberto * 9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11258945Sroberto * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15258945Sroberto * PERFORMANCE OF THIS SOFTWARE. 16258945Sroberto */ 17258945Sroberto 18258945Sroberto/* $Id: event.c,v 1.21 2007/06/19 23:47:17 tbox Exp $ */ 19258945Sroberto 20258945Sroberto/*! 21258945Sroberto * \file 22258945Sroberto * \author Principal Author: Bob Halley 23258945Sroberto */ 24258945Sroberto 25258945Sroberto#include <config.h> 26258945Sroberto 27258945Sroberto#include <isc/event.h> 28258945Sroberto#include <isc/mem.h> 29258945Sroberto#include <isc/util.h> 30258945Sroberto 31258945Sroberto/*** 32258945Sroberto *** Events. 33258945Sroberto ***/ 34258945Sroberto 35258945Srobertostatic void 36258945Srobertodestroy(isc_event_t *event) { 37280849Scy isc_mem_put(event->ev_destroy_arg, event, event->ev_size); 38258945Sroberto} 39258945Sroberto 40258945Srobertoisc_event_t * 41258945Srobertoisc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 42258945Sroberto isc_taskaction_t action, const void *arg, size_t size) 43258945Sroberto{ 44258945Sroberto isc_event_t *event; 45258945Sroberto void *deconst_arg; 46258945Sroberto 47258945Sroberto REQUIRE(size >= sizeof(struct isc_event)); 48258945Sroberto REQUIRE(action != NULL); 49258945Sroberto 50258945Sroberto event = isc_mem_get(mctx, size); 51258945Sroberto if (event == NULL) 52258945Sroberto return (NULL); 53258945Sroberto 54258945Sroberto /* 55258945Sroberto * Removing the const attribute from "arg" is the best of two 56258945Sroberto * evils here. If the event->ev_arg member is made const, then 57258945Sroberto * it affects a great many users of the task/event subsystem 58258945Sroberto * which are not passing in an "arg" which starts its life as 59258945Sroberto * const. Changing isc_event_allocate() and isc_task_onshutdown() 60258945Sroberto * to not have "arg" prototyped as const (which is quite legitimate, 61258945Sroberto * because neither of those functions modify arg) can cause 62258945Sroberto * compiler whining anytime someone does want to use a const 63258945Sroberto * arg that they themselves never modify, such as with 64258945Sroberto * gcc -Wwrite-strings and using a string "arg". 65258945Sroberto */ 66258945Sroberto DE_CONST(arg, deconst_arg); 67258945Sroberto 68258945Sroberto ISC_EVENT_INIT(event, size, 0, NULL, type, action, deconst_arg, 69258945Sroberto sender, destroy, mctx); 70258945Sroberto 71258945Sroberto return (event); 72258945Sroberto} 73258945Sroberto 74258945Srobertovoid 75258945Srobertoisc_event_free(isc_event_t **eventp) { 76258945Sroberto isc_event_t *event; 77258945Sroberto 78258945Sroberto REQUIRE(eventp != NULL); 79258945Sroberto event = *eventp; 80258945Sroberto REQUIRE(event != NULL); 81258945Sroberto 82258945Sroberto if (event->ev_destroy != NULL) 83258945Sroberto (event->ev_destroy)(event); 84258945Sroberto 85258945Sroberto *eventp = NULL; 86258945Sroberto} 87