]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/Kernel/IOEventSource.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / Kernel / IOEventSource.cpp
... / ...
CommitLineData
1/*
2 * Copyright (c) 1998-2000, 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 *
31 * HISTORY
32 * 1998-7-13 Godfrey van der Linden(gvdl)
33 * Created.
34 * ]*/
35
36#define IOKIT_ENABLE_SHARED_PTR
37
38#include <IOKit/IOLib.h>
39
40#include <IOKit/IOEventSource.h>
41#include <IOKit/IOWorkLoop.h>
42#include <libkern/Block.h>
43
44#define super OSObject
45
46OSDefineMetaClassAndAbstractStructors(IOEventSource, OSObject)
47
48OSMetaClassDefineReservedUnused(IOEventSource, 0);
49OSMetaClassDefineReservedUnused(IOEventSource, 1);
50OSMetaClassDefineReservedUnused(IOEventSource, 2);
51OSMetaClassDefineReservedUnused(IOEventSource, 3);
52OSMetaClassDefineReservedUnused(IOEventSource, 4);
53OSMetaClassDefineReservedUnused(IOEventSource, 5);
54OSMetaClassDefineReservedUnused(IOEventSource, 6);
55OSMetaClassDefineReservedUnused(IOEventSource, 7);
56
57bool
58IOEventSource::checkForWork()
59{
60 return false;
61}
62
63/* inline function implementations */
64
65#if IOKITSTATS
66
67#define IOStatisticsRegisterCounter() \
68do { \
69 reserved->counter = IOStatistics::registerEventSource(inOwner); \
70} while (0)
71
72#define IOStatisticsUnregisterCounter() \
73do { \
74 if (reserved) \
75 IOStatistics::unregisterEventSource(reserved->counter); \
76} while (0)
77
78#define IOStatisticsOpenGate() \
79do { \
80 IOStatistics::countOpenGate(reserved->counter); \
81} while (0)
82
83#define IOStatisticsCloseGate() \
84do { \
85 IOStatistics::countCloseGate(reserved->counter); \
86} while (0)
87
88#else
89
90#define IOStatisticsRegisterCounter()
91#define IOStatisticsUnregisterCounter()
92#define IOStatisticsOpenGate()
93#define IOStatisticsCloseGate()
94
95#endif /* IOKITSTATS */
96
97void
98IOEventSource::signalWorkAvailable()
99{
100 workLoop->signalWorkAvailable();
101}
102
103void
104IOEventSource::openGate()
105{
106 IOStatisticsOpenGate();
107 workLoop->openGate();
108}
109
110void
111IOEventSource::closeGate()
112{
113 workLoop->closeGate();
114 IOStatisticsCloseGate();
115}
116
117bool
118IOEventSource::tryCloseGate()
119{
120 bool res;
121 if ((res = workLoop->tryCloseGate())) {
122 IOStatisticsCloseGate();
123 }
124 return res;
125}
126
127int
128IOEventSource::sleepGate(void *event, UInt32 type)
129{
130 int res;
131 IOStatisticsOpenGate();
132 res = workLoop->sleepGate(event, type);
133 IOStatisticsCloseGate();
134 return res;
135}
136
137int
138IOEventSource::sleepGate(void *event, AbsoluteTime deadline, UInt32 type)
139{
140 int res;
141 IOStatisticsOpenGate();
142 res = workLoop->sleepGate(event, deadline, type);
143 IOStatisticsCloseGate();
144 return res;
145}
146
147void
148IOEventSource::wakeupGate(void *event, bool oneThread)
149{
150 workLoop->wakeupGate(event, oneThread);
151}
152
153
154bool
155IOEventSource::init(OSObject *inOwner,
156 Action inAction)
157{
158 if (!inOwner) {
159 return false;
160 }
161
162 owner = inOwner;
163
164 if (!super::init()) {
165 return false;
166 }
167
168 (void) setAction(inAction);
169 enabled = true;
170
171 if (!reserved) {
172 reserved = IONew(ExpansionData, 1);
173 if (!reserved) {
174 return false;
175 }
176 }
177
178 IOStatisticsRegisterCounter();
179
180 return true;
181}
182
183void
184IOEventSource::free( void )
185{
186 IOStatisticsUnregisterCounter();
187
188 if ((kActionBlock & flags) && actionBlock) {
189 Block_release(actionBlock);
190 }
191
192 if (reserved) {
193 IODelete(reserved, ExpansionData, 1);
194 }
195
196 super::free();
197}
198
199void
200IOEventSource::setRefcon(void *newrefcon)
201{
202 refcon = newrefcon;
203}
204
205void *
206IOEventSource::getRefcon() const
207{
208 return refcon;
209}
210
211IOEventSource::Action
212IOEventSource::getAction() const
213{
214 if (kActionBlock & flags) {
215 return NULL;
216 }
217 return action;
218}
219
220IOEventSource::ActionBlock
221IOEventSource::getActionBlock(ActionBlock) const
222{
223 if (kActionBlock & flags) {
224 return actionBlock;
225 }
226 return NULL;
227}
228
229void
230IOEventSource::setAction(Action inAction)
231{
232 if ((kActionBlock & flags) && actionBlock) {
233 Block_release(actionBlock);
234 }
235 action = inAction;
236 flags &= ~kActionBlock;
237}
238
239void
240IOEventSource::setActionBlock(ActionBlock block)
241{
242 if ((kActionBlock & flags) && actionBlock) {
243 Block_release(actionBlock);
244 }
245 actionBlock = Block_copy(block);
246 flags |= kActionBlock;
247}
248
249IOEventSource *
250IOEventSource::getNext() const
251{
252 return eventChainNext;
253};
254
255void
256IOEventSource::setNext(IOEventSource *inNext)
257{
258 eventChainNext = inNext;
259}
260
261void
262IOEventSource::enable()
263{
264 enabled = true;
265 if (workLoop) {
266 return signalWorkAvailable();
267 }
268}
269
270void
271IOEventSource::disable()
272{
273 enabled = false;
274}
275
276bool
277IOEventSource::isEnabled() const
278{
279 return enabled;
280}
281
282void
283IOEventSource::setWorkLoop(IOWorkLoop *inWorkLoop)
284{
285 if (!inWorkLoop) {
286 disable();
287 }
288 workLoop = inWorkLoop;
289}
290
291IOWorkLoop *
292IOEventSource::getWorkLoop() const
293{
294 return workLoop;
295}
296
297bool
298IOEventSource::onThread() const
299{
300 return (workLoop != NULL) && workLoop->onThread();
301}