Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame^] | 1 | /* $NetBSD: callout.h,v 1.22 2005/12/11 12:25:20 christos Exp $ */
|
| 2 |
|
| 3 | /*-
|
| 4 | * Copyright (c) 2000, 2003 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) 2000-2001 Artur Grabowski <art@openbsd.org>
|
| 42 | * All rights reserved.
|
| 43 | *
|
| 44 | * Redistribution and use in source and binary forms, with or without
|
| 45 | * modification, are permitted provided that the following conditions
|
| 46 | * are met:
|
| 47 | *
|
| 48 | * 1. Redistributions of source code must retain the above copyright
|
| 49 | * notice, this list of conditions and the following disclaimer.
|
| 50 | * 2. Redistributions in binary form must reproduce the above copyright
|
| 51 | * notice, this list of conditions and the following disclaimer in the
|
| 52 | * documentation and/or other materials provided with the distribution.
|
| 53 | * 3. The name of the author may not be used to endorse or promote products
|
| 54 | * derived from this software without specific prior written permission.
|
| 55 | *
|
| 56 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
| 57 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
| 58 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
| 59 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 60 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 61 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
| 62 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
| 63 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
| 64 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
| 65 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 66 | */
|
| 67 |
|
| 68 | #ifndef _SYS_CALLOUT_H_
|
| 69 | #define _SYS_CALLOUT_H_
|
| 70 |
|
| 71 | /*
|
| 72 | * The following funkyness is to appease gcc3's strict aliasing.
|
| 73 | */
|
| 74 | struct callout;
|
| 75 | struct callout_circq {
|
| 76 | /* next element */
|
| 77 | union {
|
| 78 | struct callout *elem;
|
| 79 | struct callout_circq *list;
|
| 80 | } cq_next;
|
| 81 | /* previous element */
|
| 82 | union {
|
| 83 | struct callout *elem;
|
| 84 | struct callout_circq *list;
|
| 85 | } cq_prev;
|
| 86 | };
|
| 87 | #define cq_next_e cq_next.elem
|
| 88 | #define cq_prev_e cq_prev.elem
|
| 89 | #define cq_next_l cq_next.list
|
| 90 | #define cq_prev_l cq_prev.list
|
| 91 |
|
| 92 | struct callout {
|
| 93 | struct callout_circq c_list; /* linkage on queue */
|
| 94 | void (*c_func)(void *); /* function to call */
|
| 95 | void *c_arg; /* function argument */
|
| 96 | int c_time; /* when callout fires */
|
| 97 | int c_flags; /* state of this entry */
|
| 98 | };
|
| 99 |
|
| 100 | #define CALLOUT_PENDING 0x0002 /* callout is on the queue */
|
| 101 | #define CALLOUT_FIRED 0x0004 /* callout has fired */
|
| 102 | #define CALLOUT_INVOKING 0x0008 /* callout function is being invoked */
|
| 103 |
|
| 104 | #define CALLOUT_INITIALIZER_SETFUNC(func, arg) \
|
| 105 | { {{NULL}, {NULL}}, func, arg, 0, 0 }
|
| 106 |
|
| 107 | #define CALLOUT_INITIALIZER CALLOUT_INITIALIZER_SETFUNC(NULL, NULL)
|
| 108 |
|
| 109 | #ifdef _KERNEL
|
| 110 | void callout_startup(void);
|
| 111 | void callout_init(struct callout *);
|
| 112 | void callout_setfunc(struct callout *, void (*)(void *), void *);
|
| 113 | void callout_reset(struct callout *, int, void (*)(void *), void *);
|
| 114 | void callout_schedule(struct callout *, int);
|
| 115 | void callout_stop(struct callout *);
|
| 116 | int callout_hardclock(void);
|
| 117 |
|
| 118 | #define callout_setfunc(c, f, a) \
|
| 119 | do { \
|
| 120 | (c)->c_func = (f); \
|
| 121 | (c)->c_arg = (a); \
|
| 122 | } while (/*CONSTCOND*/0)
|
| 123 |
|
| 124 | #define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
|
| 125 | #define callout_expired(c) ((c)->c_flags & CALLOUT_FIRED)
|
| 126 | #define callout_active(c) ((c)->c_flags & (CALLOUT_PENDING|CALLOUT_FIRED))
|
| 127 | #define callout_invoking(c) ((c)->c_flags & CALLOUT_INVOKING)
|
| 128 | #define callout_ack(c) ((c)->c_flags &= ~CALLOUT_INVOKING)
|
| 129 | #endif /* _KERNEL */
|
| 130 |
|
| 131 | #endif /* !_SYS_CALLOUT_H_ */
|