]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOEventSource.cpp
2 * Copyright (c) 1998-2000, 2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32 * 1998-7-13 Godfrey van der Linden(gvdl)
35 #include <IOKit/IOLib.h>
37 #include <IOKit/IOEventSource.h>
38 #include <IOKit/IOWorkLoop.h>
39 #include <libkern/Block.h>
41 #define super OSObject
43 OSDefineMetaClassAndAbstractStructors(IOEventSource
, OSObject
)
45 OSMetaClassDefineReservedUnused(IOEventSource
, 0);
46 OSMetaClassDefineReservedUnused(IOEventSource
, 1);
47 OSMetaClassDefineReservedUnused(IOEventSource
, 2);
48 OSMetaClassDefineReservedUnused(IOEventSource
, 3);
49 OSMetaClassDefineReservedUnused(IOEventSource
, 4);
50 OSMetaClassDefineReservedUnused(IOEventSource
, 5);
51 OSMetaClassDefineReservedUnused(IOEventSource
, 6);
52 OSMetaClassDefineReservedUnused(IOEventSource
, 7);
55 IOEventSource::checkForWork()
60 /* inline function implementations */
64 #define IOStatisticsRegisterCounter() \
66 reserved->counter = IOStatistics::registerEventSource(inOwner); \
69 #define IOStatisticsUnregisterCounter() \
72 IOStatistics::unregisterEventSource(reserved->counter); \
75 #define IOStatisticsOpenGate() \
77 IOStatistics::countOpenGate(reserved->counter); \
80 #define IOStatisticsCloseGate() \
82 IOStatistics::countCloseGate(reserved->counter); \
87 #define IOStatisticsRegisterCounter()
88 #define IOStatisticsUnregisterCounter()
89 #define IOStatisticsOpenGate()
90 #define IOStatisticsCloseGate()
92 #endif /* IOKITSTATS */
95 IOEventSource::signalWorkAvailable()
97 workLoop
->signalWorkAvailable();
101 IOEventSource::openGate()
103 IOStatisticsOpenGate();
104 workLoop
->openGate();
108 IOEventSource::closeGate()
110 workLoop
->closeGate();
111 IOStatisticsCloseGate();
115 IOEventSource::tryCloseGate()
118 if ((res
= workLoop
->tryCloseGate())) {
119 IOStatisticsCloseGate();
125 IOEventSource::sleepGate(void *event
, UInt32 type
)
128 IOStatisticsOpenGate();
129 res
= workLoop
->sleepGate(event
, type
);
130 IOStatisticsCloseGate();
135 IOEventSource::sleepGate(void *event
, AbsoluteTime deadline
, UInt32 type
)
138 IOStatisticsOpenGate();
139 res
= workLoop
->sleepGate(event
, deadline
, type
);
140 IOStatisticsCloseGate();
145 IOEventSource::wakeupGate(void *event
, bool oneThread
)
147 workLoop
->wakeupGate(event
, oneThread
);
152 IOEventSource::init(OSObject
*inOwner
,
161 if (!super::init()) {
165 (void) setAction(inAction
);
169 reserved
= IONew(ExpansionData
, 1);
175 IOStatisticsRegisterCounter();
181 IOEventSource::free( void )
183 IOStatisticsUnregisterCounter();
185 if ((kActionBlock
& flags
) && actionBlock
) {
186 Block_release(actionBlock
);
190 IODelete(reserved
, ExpansionData
, 1);
197 IOEventSource::setRefcon(void *newrefcon
)
203 IOEventSource::getRefcon() const
208 IOEventSource::Action
209 IOEventSource::getAction() const
211 if (kActionBlock
& flags
) {
217 IOEventSource::ActionBlock
218 IOEventSource::getActionBlock(ActionBlock
) const
220 if (kActionBlock
& flags
) {
227 IOEventSource::setAction(Action inAction
)
229 if ((kActionBlock
& flags
) && actionBlock
) {
230 Block_release(actionBlock
);
236 IOEventSource::setActionBlock(ActionBlock block
)
238 if ((kActionBlock
& flags
) && actionBlock
) {
239 Block_release(actionBlock
);
241 actionBlock
= Block_copy(block
);
242 flags
|= kActionBlock
;
246 IOEventSource::getNext() const
248 return eventChainNext
;
252 IOEventSource::setNext(IOEventSource
*inNext
)
254 eventChainNext
= inNext
;
258 IOEventSource::enable()
262 return signalWorkAvailable();
267 IOEventSource::disable()
273 IOEventSource::isEnabled() const
279 IOEventSource::setWorkLoop(IOWorkLoop
*inWorkLoop
)
284 workLoop
= inWorkLoop
;
288 IOEventSource::getWorkLoop() const
294 IOEventSource::onThread() const
296 return (workLoop
!= NULL
) && workLoop
->onThread();