ondestroy.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 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: ondestroy.c,v 1.16 2007/06/19 23:47:17 tbox Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <stddef.h>
00025 
00026 #include <isc/event.h>
00027 #include <isc/magic.h>
00028 #include <isc/ondestroy.h>
00029 #include <isc/task.h>
00030 #include <isc/util.h>
00031 
00032 #define ONDESTROY_MAGIC         ISC_MAGIC('D', 'e', 'S', 't')
00033 #define VALID_ONDESTROY(s)      ISC_MAGIC_VALID(s, ONDESTROY_MAGIC)
00034 
00035 void
00036 isc_ondestroy_init(isc_ondestroy_t *ondest) {
00037         ondest->magic = ONDESTROY_MAGIC;
00038         ISC_LIST_INIT(ondest->events);
00039 }
00040 
00041 isc_result_t
00042 isc_ondestroy_register(isc_ondestroy_t *ondest, isc_task_t *task,
00043                        isc_event_t **eventp)
00044 {
00045         isc_event_t *theevent;
00046         isc_task_t *thetask = NULL;
00047 
00048         REQUIRE(VALID_ONDESTROY(ondest));
00049         REQUIRE(task != NULL);
00050         REQUIRE(eventp != NULL);
00051 
00052         theevent = *eventp;
00053 
00054         REQUIRE(theevent != NULL);
00055 
00056         isc_task_attach(task, &thetask);
00057 
00058         theevent->ev_sender = thetask;
00059 
00060         ISC_LIST_APPEND(ondest->events, theevent, ev_link);
00061 
00062         return (ISC_R_SUCCESS);
00063 }
00064 
00065 void
00066 isc_ondestroy_notify(isc_ondestroy_t *ondest, void *sender) {
00067         isc_event_t *eventp;
00068         isc_task_t *task;
00069 
00070         REQUIRE(VALID_ONDESTROY(ondest));
00071 
00072         eventp = ISC_LIST_HEAD(ondest->events);
00073         while (eventp != NULL) {
00074                 ISC_LIST_UNLINK(ondest->events, eventp, ev_link);
00075 
00076                 task = eventp->ev_sender;
00077                 eventp->ev_sender = sender;
00078 
00079                 isc_task_sendanddetach(&task, &eventp);
00080 
00081                 eventp = ISC_LIST_HEAD(ondest->events);
00082         }
00083 }
00084 
00085 

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