event.c revision 258945
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) { 37258945Sroberto isc_mem_t *mctx = event->ev_destroy_arg; 38258945Sroberto 39258945Sroberto isc_mem_put(mctx, event, event->ev_size); 40258945Sroberto} 41258945Sroberto 42258945Srobertoisc_event_t * 43258945Srobertoisc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 44258945Sroberto isc_taskaction_t action, const void *arg, size_t size) 45258945Sroberto{ 46258945Sroberto isc_event_t *event; 47258945Sroberto void *deconst_arg; 48258945Sroberto 49258945Sroberto REQUIRE(size >= sizeof(struct isc_event)); 50258945Sroberto REQUIRE(action != NULL); 51258945Sroberto 52258945Sroberto event = isc_mem_get(mctx, size); 53258945Sroberto if (event == NULL) 54258945Sroberto return (NULL); 55258945Sroberto 56258945Sroberto /* 57258945Sroberto * Removing the const attribute from "arg" is the best of two 58258945Sroberto * evils here. If the event->ev_arg member is made const, then 59258945Sroberto * it affects a great many users of the task/event subsystem 60258945Sroberto * which are not passing in an "arg" which starts its life as 61258945Sroberto * const. Changing isc_event_allocate() and isc_task_onshutdown() 62258945Sroberto * to not have "arg" prototyped as const (which is quite legitimate, 63258945Sroberto * because neither of those functions modify arg) can cause 64258945Sroberto * compiler whining anytime someone does want to use a const 65258945Sroberto * arg that they themselves never modify, such as with 66258945Sroberto * gcc -Wwrite-strings and using a string "arg". 67258945Sroberto */ 68258945Sroberto DE_CONST(arg, deconst_arg); 69258945Sroberto 70258945Sroberto ISC_EVENT_INIT(event, size, 0, NULL, type, action, deconst_arg, 71258945Sroberto sender, destroy, mctx); 72258945Sroberto 73258945Sroberto return (event); 74258945Sroberto} 75258945Sroberto 76258945Srobertovoid 77258945Srobertoisc_event_free(isc_event_t **eventp) { 78258945Sroberto isc_event_t *event; 79258945Sroberto 80258945Sroberto REQUIRE(eventp != NULL); 81258945Sroberto event = *eventp; 82258945Sroberto REQUIRE(event != NULL); 83258945Sroberto 84258945Sroberto if (event->ev_destroy != NULL) 85258945Sroberto (event->ev_destroy)(event); 86258945Sroberto 87258945Sroberto *eventp = NULL; 88258945Sroberto} 89