xref: /openbsd-src/usr.bin/dig/lib/isc/event.c (revision b9558d14c675017cf470d7469a47201d05e39444)
15185a700Sflorian /*
25185a700Sflorian  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
35185a700Sflorian  *
45185a700Sflorian  * Permission to use, copy, modify, and/or distribute this software for any
55185a700Sflorian  * purpose with or without fee is hereby granted, provided that the above
65185a700Sflorian  * copyright notice and this permission notice appear in all copies.
75185a700Sflorian  *
85185a700Sflorian  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
95185a700Sflorian  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105185a700Sflorian  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
115185a700Sflorian  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
125185a700Sflorian  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
135185a700Sflorian  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
145185a700Sflorian  * PERFORMANCE OF THIS SOFTWARE.
155185a700Sflorian  */
165185a700Sflorian 
17*b9558d14Sjsg /* $Id: event.c,v 1.3 2020/02/25 05:00:43 jsg Exp $ */
185185a700Sflorian 
195185a700Sflorian /*!
205185a700Sflorian  * \file
215185a700Sflorian  * \author Principal Author: Bob Halley
225185a700Sflorian  */
235185a700Sflorian 
245185a700Sflorian #include <stdlib.h>
255185a700Sflorian #include <isc/event.h>
265185a700Sflorian 
275185a700Sflorian #include <isc/util.h>
285185a700Sflorian 
295185a700Sflorian /***
305185a700Sflorian  *** Events.
315185a700Sflorian  ***/
325185a700Sflorian 
335185a700Sflorian static void
destroy(isc_event_t * event)345185a700Sflorian destroy(isc_event_t *event) {
355185a700Sflorian 	free(event);
365185a700Sflorian }
375185a700Sflorian 
385185a700Sflorian isc_event_t *
isc_event_allocate(void * sender,isc_eventtype_t type,isc_taskaction_t action,void * arg,size_t size)395185a700Sflorian isc_event_allocate(void *sender, isc_eventtype_t type,
405185a700Sflorian 		   isc_taskaction_t action, void *arg, size_t size)
415185a700Sflorian {
425185a700Sflorian 	isc_event_t *event;
435185a700Sflorian 
445185a700Sflorian 	REQUIRE(size >= sizeof(struct isc_event));
455185a700Sflorian 	REQUIRE(action != NULL);
465185a700Sflorian 
475185a700Sflorian 	event = malloc(size);
485185a700Sflorian 	if (event == NULL)
495185a700Sflorian 		return (NULL);
505185a700Sflorian 
515185a700Sflorian 	ISC_EVENT_INIT(event, size, 0, NULL, type, action, arg,
525185a700Sflorian 		       sender, destroy);
535185a700Sflorian 
545185a700Sflorian 	return (event);
555185a700Sflorian }
565185a700Sflorian 
575185a700Sflorian void
isc_event_free(isc_event_t ** eventp)585185a700Sflorian isc_event_free(isc_event_t **eventp) {
595185a700Sflorian 	isc_event_t *event;
605185a700Sflorian 
615185a700Sflorian 	REQUIRE(eventp != NULL);
625185a700Sflorian 	event = *eventp;
635185a700Sflorian 	REQUIRE(event != NULL);
645185a700Sflorian 
655185a700Sflorian 	REQUIRE(!ISC_LINK_LINKED(event, ev_link));
665185a700Sflorian 	REQUIRE(!ISC_LINK_LINKED(event, ev_ratelink));
675185a700Sflorian 
685185a700Sflorian 	if (event->ev_destroy != NULL)
695185a700Sflorian 		(event->ev_destroy)(event);
705185a700Sflorian 
715185a700Sflorian 	*eventp = NULL;
725185a700Sflorian }
73