1135446Strhodes/* 2193149Sdougb * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 2000, 2001 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18234010Sdougb/* $Id: ondestroy.c,v 1.16 2007/06/19 23:47:17 tbox Exp $ */ 19135446Strhodes 20170222Sdougb/*! \file */ 21170222Sdougb 22135446Strhodes#include <config.h> 23135446Strhodes 24135446Strhodes#include <stddef.h> 25135446Strhodes 26135446Strhodes#include <isc/event.h> 27135446Strhodes#include <isc/magic.h> 28135446Strhodes#include <isc/ondestroy.h> 29135446Strhodes#include <isc/task.h> 30135446Strhodes#include <isc/util.h> 31135446Strhodes 32135446Strhodes#define ONDESTROY_MAGIC ISC_MAGIC('D', 'e', 'S', 't') 33135446Strhodes#define VALID_ONDESTROY(s) ISC_MAGIC_VALID(s, ONDESTROY_MAGIC) 34135446Strhodes 35135446Strhodesvoid 36135446Strhodesisc_ondestroy_init(isc_ondestroy_t *ondest) { 37135446Strhodes ondest->magic = ONDESTROY_MAGIC; 38135446Strhodes ISC_LIST_INIT(ondest->events); 39135446Strhodes} 40135446Strhodes 41135446Strhodesisc_result_t 42135446Strhodesisc_ondestroy_register(isc_ondestroy_t *ondest, isc_task_t *task, 43135446Strhodes isc_event_t **eventp) 44135446Strhodes{ 45135446Strhodes isc_event_t *theevent; 46135446Strhodes isc_task_t *thetask = NULL; 47135446Strhodes 48135446Strhodes REQUIRE(VALID_ONDESTROY(ondest)); 49135446Strhodes REQUIRE(task != NULL); 50135446Strhodes REQUIRE(eventp != NULL); 51135446Strhodes 52135446Strhodes theevent = *eventp; 53135446Strhodes 54135446Strhodes REQUIRE(theevent != NULL); 55135446Strhodes 56135446Strhodes isc_task_attach(task, &thetask); 57135446Strhodes 58135446Strhodes theevent->ev_sender = thetask; 59135446Strhodes 60135446Strhodes ISC_LIST_APPEND(ondest->events, theevent, ev_link); 61135446Strhodes 62135446Strhodes return (ISC_R_SUCCESS); 63135446Strhodes} 64135446Strhodes 65135446Strhodesvoid 66135446Strhodesisc_ondestroy_notify(isc_ondestroy_t *ondest, void *sender) { 67135446Strhodes isc_event_t *eventp; 68135446Strhodes isc_task_t *task; 69135446Strhodes 70135446Strhodes REQUIRE(VALID_ONDESTROY(ondest)); 71135446Strhodes 72135446Strhodes eventp = ISC_LIST_HEAD(ondest->events); 73135446Strhodes while (eventp != NULL) { 74135446Strhodes ISC_LIST_UNLINK(ondest->events, eventp, ev_link); 75135446Strhodes 76135446Strhodes task = eventp->ev_sender; 77135446Strhodes eventp->ev_sender = sender; 78135446Strhodes 79135446Strhodes isc_task_sendanddetach(&task, &eventp); 80135446Strhodes 81135446Strhodes eventp = ISC_LIST_HEAD(ondest->events); 82135446Strhodes } 83135446Strhodes} 84135446Strhodes 85135446Strhodes 86