1 /* $NetBSD: callout.h,v 1.16 2001/09/11 04:32:19 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /*- 41 * Copyright (c) 1990, 1993 42 * The Regents of the University of California. All rights reserved. 43 * (c) UNIX System Laboratories, Inc. 44 * All or some portions of this file are derived from material licensed 45 * to the University of California by American Telephone and Telegraph 46 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 47 * the permission of UNIX System Laboratories, Inc. 48 * 49 * Redistribution and use in source and binary forms, with or without 50 * modification, are permitted provided that the following conditions 51 * are met: 52 * 1. Redistributions of source code must retain the above copyright 53 * notice, this list of conditions and the following disclaimer. 54 * 2. Redistributions in binary form must reproduce the above copyright 55 * notice, this list of conditions and the following disclaimer in the 56 * documentation and/or other materials provided with the distribution. 57 * 3. All advertising materials mentioning features or use of this software 58 * must display the following acknowledgement: 59 * This product includes software developed by the University of 60 * California, Berkeley and its contributors. 61 * 4. Neither the name of the University nor the names of its contributors 62 * may be used to endorse or promote products derived from this software 63 * without specific prior written permission. 64 * 65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 75 * SUCH DAMAGE. 76 * 77 * @(#)callout.h 8.2 (Berkeley) 1/21/94 78 */ 79 #ifndef _SYS_CALLOUT_H_ 80 #define _SYS_CALLOUT_H_ 81 82 #include <sys/queue.h> 83 84 struct callout_queue { 85 uint64_t cq_hint; /* earliest callout in bkt */ 86 TAILQ_HEAD(, callout) cq_q; /* callouts in this bucket */ 87 }; 88 89 struct callout { 90 TAILQ_ENTRY(callout) c_link; 91 u_int64_t c_time; /* when callout fires */ 92 void *c_arg; /* function argument */ 93 void (*c_func)(void *); /* functiuon to call */ 94 int c_flags; /* state of this entry */ 95 }; 96 97 #define CALLOUT_ACTIVE 0x0001 /* callout is active */ 98 #define CALLOUT_PENDING 0x0002 /* callout time has not yet arrived */ 99 100 #define CALLOUT_INITIALIZER { { NULL, NULL }, 0, NULL, NULL, 0 } 101 102 #ifdef _KERNEL 103 extern struct callout_queue *callwheel; 104 extern int callwheelsize, callwheelbits, callwheelmask; 105 extern int ncallout; 106 107 #ifdef CALLWHEEL_STATS 108 extern int *callwheel_sizes; /* for allocsys() */ 109 #endif 110 111 void callout_setsize(void); 112 void callout_startup(void); 113 void callout_init(struct callout *); 114 void callout_reset(struct callout *, int, void (*)(void *), void *); 115 void callout_stop(struct callout *); 116 #ifdef CALLWHEEL_STATS 117 void callout_showstats(void); 118 #endif 119 120 #define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE) 121 #define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING) 122 #define callout_expired(c) (callout_pending((c)) == 0) 123 124 #define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE) 125 #endif /* _KERNEL */ 126 127 #endif /* !_SYS_CALLOUT_H_ */ 128