]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/call_entry.h
xnu-6153.121.1.tar.gz
[apple/xnu.git] / osfmk / kern / call_entry.h
CommitLineData
1c79356b 1/*
c910b4d9 2 * Copyright (c) 1993-1995, 1999-2008 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
c910b4d9 29 * Declarations for generic call outs.
1c79356b
A
30 */
31
32#ifndef _KERN_CALL_ENTRY_H_
33#define _KERN_CALL_ENTRY_H_
34
39236c6e 35#ifdef XNU_KERNEL_PRIVATE
1c79356b
A
36#include <kern/queue.h>
37
5ba3f43e 38#if !CONFIG_EMBEDDED
0a7de745 39#define TIMER_TRACE 1
5ba3f43e 40#endif
39236c6e 41
0a7de745
A
42typedef void *call_entry_param_t;
43typedef void (*call_entry_func_t)(
44 call_entry_param_t param0,
45 call_entry_param_t param1);
1c79356b
A
46
47typedef struct call_entry {
0a7de745
A
48 queue_chain_t q_link;
49 queue_head_t *queue;
50 call_entry_func_t func;
51 call_entry_param_t param0;
52 call_entry_param_t param1;
53 uint64_t deadline;
39236c6e 54#if TIMER_TRACE
0a7de745 55 uint64_t entry_time;
39236c6e 56#endif
1c79356b
A
57} call_entry_data_t;
58
0a7de745 59typedef struct call_entry *call_entry_t;
c910b4d9 60
39236c6e 61#ifdef MACH_KERNEL_PRIVATE
c910b4d9 62
0a7de745
A
63#define call_entry_setup(entry, pfun, p0) \
64MACRO_BEGIN \
65 (entry)->func = (call_entry_func_t)(pfun); \
66 (entry)->param0 = (call_entry_param_t)(p0); \
67 (entry)->queue = NULL; \
68 (entry)->deadline = 0; \
69 queue_chain_init((entry)->q_link); \
1c79356b
A
70MACRO_END
71
0a7de745
A
72#define qe(x) ((queue_entry_t)(x))
73#define CE(x) ((call_entry_t)(x))
6d2010ae
A
74
75static __inline__ queue_head_t *
76call_entry_enqueue_tail(
0a7de745
A
77 call_entry_t entry,
78 queue_t queue)
6d2010ae 79{
0a7de745 80 queue_t old_queue = entry->queue;
6d2010ae 81
0a7de745 82 if (old_queue != NULL) {
5ba3f43e 83 re_queue_tail(queue, &entry->q_link);
0a7de745 84 } else {
5ba3f43e 85 enqueue_tail(queue, &entry->q_link);
0a7de745 86 }
6d2010ae 87
0a7de745 88 entry->queue = queue;
6d2010ae 89
0a7de745 90 return old_queue;
6d2010ae
A
91}
92
93static __inline__ queue_head_t *
94call_entry_dequeue(
0a7de745 95 call_entry_t entry)
6d2010ae 96{
0a7de745 97 queue_t old_queue = entry->queue;
6d2010ae
A
98
99 if (old_queue != NULL) {
100 (void)remque(qe(entry));
101
102 entry->queue = NULL;
103 }
0a7de745 104 return old_queue;
6d2010ae
A
105}
106
107static __inline__ queue_head_t *
108call_entry_enqueue_deadline(
0a7de745
A
109 call_entry_t entry,
110 queue_head_t *queue,
111 uint64_t deadline)
6d2010ae 112{
0a7de745
A
113 queue_t old_queue = entry->queue;
114 call_entry_t current;
6d2010ae
A
115
116 if (old_queue != queue || entry->deadline < deadline) {
117 if (old_queue == NULL) {
118 current = CE(queue_first(queue));
119 } else if (old_queue != queue) {
120 (void)remque(qe(entry));
121 current = CE(queue_first(queue));
122 } else {
123 current = CE(queue_next(qe(entry)));
124 (void)remque(qe(entry));
125 }
126
127 while (TRUE) {
128 if (queue_end(queue, qe(current)) ||
129 deadline < current->deadline) {
130 current = CE(queue_prev(qe(current)));
131 break;
132 }
133
134 current = CE(queue_next(qe(current)));
135 }
136 insque(qe(entry), qe(current));
0a7de745 137 } else if (deadline < entry->deadline) {
6d2010ae
A
138 current = CE(queue_prev(qe(entry)));
139
140 (void)remque(qe(entry));
141
142 while (TRUE) {
143 if (queue_end(queue, qe(current)) ||
144 current->deadline <= deadline) {
145 break;
146 }
147
148 current = CE(queue_prev(qe(current)));
149 }
150 insque(qe(entry), qe(current));
151 }
152 entry->queue = queue;
153 entry->deadline = deadline;
154
0a7de745 155 return old_queue;
6d2010ae 156}
1c79356b
A
157#endif /* MACH_KERNEL_PRIVATE */
158
39236c6e
A
159#endif /* XNU_KERNEL_PRIVATE */
160
1c79356b 161#endif /* _KERN_CALL_ENTRY_H_ */