]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/sys/callout.h
Vlv2TbltDevicePkg/PlatformFlashAccessLib: Fix IA32 build issues
[mirror_edk2.git] / StdLib / Include / sys / callout.h
CommitLineData
2aa62f2b 1/* $NetBSD: callout.h,v 1.22 2005/12/11 12:25:20 christos Exp $ */\r
2\r
3/*-\r
4 * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.\r
5 * All rights reserved.\r
6 *\r
7 * This code is derived from software contributed to The NetBSD Foundation\r
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,\r
9 * NASA Ames Research Center.\r
10 *\r
11 * Redistribution and use in source and binary forms, with or without\r
12 * modification, are permitted provided that the following conditions\r
13 * are met:\r
14 * 1. Redistributions of source code must retain the above copyright\r
15 * notice, this list of conditions and the following disclaimer.\r
16 * 2. Redistributions in binary form must reproduce the above copyright\r
17 * notice, this list of conditions and the following disclaimer in the\r
18 * documentation and/or other materials provided with the distribution.\r
19 * 3. All advertising materials mentioning features or use of this software\r
20 * must display the following acknowledgement:\r
21 * This product includes software developed by the NetBSD\r
22 * Foundation, Inc. and its contributors.\r
23 * 4. Neither the name of The NetBSD Foundation nor the names of its\r
24 * contributors may be used to endorse or promote products derived\r
25 * from this software without specific prior written permission.\r
26 *\r
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
37 * POSSIBILITY OF SUCH DAMAGE.\r
38 */\r
39\r
40/*\r
41 * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>\r
42 * All rights reserved.\r
43 *\r
44 * Redistribution and use in source and binary forms, with or without\r
45 * modification, are permitted provided that the following conditions\r
46 * are met:\r
47 *\r
48 * 1. Redistributions of source code must retain the above copyright\r
49 * notice, this list of conditions and the following disclaimer.\r
50 * 2. Redistributions in binary form must reproduce the above copyright\r
51 * notice, this list of conditions and the following disclaimer in the\r
52 * documentation and/or other materials provided with the distribution.\r
53 * 3. The name of the author may not be used to endorse or promote products\r
54 * derived from this software without specific prior written permission.\r
55 *\r
56 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
57 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\r
58 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\r
59 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
60 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
61 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
62 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
63 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
64 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
65 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
66 */\r
67\r
68#ifndef _SYS_CALLOUT_H_\r
69#define _SYS_CALLOUT_H_\r
70\r
71/*\r
72 * The following funkyness is to appease gcc3's strict aliasing.\r
73 */\r
74struct callout;\r
75struct callout_circq {\r
76 /* next element */\r
77 union {\r
78 struct callout *elem;\r
79 struct callout_circq *list;\r
80 } cq_next;\r
81 /* previous element */\r
82 union {\r
83 struct callout *elem;\r
84 struct callout_circq *list;\r
85 } cq_prev;\r
86};\r
87#define cq_next_e cq_next.elem\r
88#define cq_prev_e cq_prev.elem\r
89#define cq_next_l cq_next.list\r
90#define cq_prev_l cq_prev.list\r
91\r
92struct callout {\r
93 struct callout_circq c_list; /* linkage on queue */\r
94 void (*c_func)(void *); /* function to call */\r
95 void *c_arg; /* function argument */\r
96 int c_time; /* when callout fires */\r
97 int c_flags; /* state of this entry */\r
98};\r
99\r
100#define CALLOUT_PENDING 0x0002 /* callout is on the queue */\r
101#define CALLOUT_FIRED 0x0004 /* callout has fired */\r
102#define CALLOUT_INVOKING 0x0008 /* callout function is being invoked */\r
103\r
104#define CALLOUT_INITIALIZER_SETFUNC(func, arg) \\r
105 { {{NULL}, {NULL}}, func, arg, 0, 0 }\r
106\r
107#define CALLOUT_INITIALIZER CALLOUT_INITIALIZER_SETFUNC(NULL, NULL)\r
108\r
109#ifdef _KERNEL\r
110void callout_startup(void);\r
111void callout_init(struct callout *);\r
112void callout_setfunc(struct callout *, void (*)(void *), void *);\r
113void callout_reset(struct callout *, int, void (*)(void *), void *);\r
114void callout_schedule(struct callout *, int);\r
115void callout_stop(struct callout *);\r
116int callout_hardclock(void);\r
117\r
118#define callout_setfunc(c, f, a) \\r
119do { \\r
120 (c)->c_func = (f); \\r
121 (c)->c_arg = (a); \\r
122} while (/*CONSTCOND*/0)\r
123\r
124#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)\r
125#define callout_expired(c) ((c)->c_flags & CALLOUT_FIRED)\r
126#define callout_active(c) ((c)->c_flags & (CALLOUT_PENDING|CALLOUT_FIRED))\r
127#define callout_invoking(c) ((c)->c_flags & CALLOUT_INVOKING)\r
128#define callout_ack(c) ((c)->c_flags &= ~CALLOUT_INVOKING)\r
129#endif /* _KERNEL */\r
130\r
131#endif /* !_SYS_CALLOUT_H_ */\r