]>
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)
36 #define IOKIT_ENABLE_SHARED_PTR
38 #include <IOKit/IOLib.h>
40 #include <IOKit/IOEventSource.h>
41 #include <IOKit/IOWorkLoop.h>
42 #include <libkern/Block.h>
44 #define super OSObject
46 OSDefineMetaClassAndAbstractStructors(IOEventSource
, OSObject
)
48 OSMetaClassDefineReservedUnused(IOEventSource
, 0);
49 OSMetaClassDefineReservedUnused(IOEventSource
, 1);
50 OSMetaClassDefineReservedUnused(IOEventSource
, 2);
51 OSMetaClassDefineReservedUnused(IOEventSource
, 3);
52 OSMetaClassDefineReservedUnused(IOEventSource
, 4);
53 OSMetaClassDefineReservedUnused(IOEventSource
, 5);
54 OSMetaClassDefineReservedUnused(IOEventSource
, 6);
55 OSMetaClassDefineReservedUnused(IOEventSource
, 7);
58 IOEventSource::checkForWork()
63 /* inline function implementations */
67 #define IOStatisticsRegisterCounter() \
69 reserved->counter = IOStatistics::registerEventSource(inOwner); \
72 #define IOStatisticsUnregisterCounter() \
75 IOStatistics::unregisterEventSource(reserved->counter); \
78 #define IOStatisticsOpenGate() \
80 IOStatistics::countOpenGate(reserved->counter); \
83 #define IOStatisticsCloseGate() \
85 IOStatistics::countCloseGate(reserved->counter); \
90 #define IOStatisticsRegisterCounter()
91 #define IOStatisticsUnregisterCounter()
92 #define IOStatisticsOpenGate()
93 #define IOStatisticsCloseGate()
95 #endif /* IOKITSTATS */
98 IOEventSource::signalWorkAvailable()
100 workLoop
->signalWorkAvailable();
104 IOEventSource::openGate()
106 IOStatisticsOpenGate();
107 workLoop
->openGate();
111 IOEventSource::closeGate()
113 workLoop
->closeGate();
114 IOStatisticsCloseGate();
118 IOEventSource::tryCloseGate()
121 if ((res
= workLoop
->tryCloseGate())) {
122 IOStatisticsCloseGate();
128 IOEventSource::sleepGate(void *event
, UInt32 type
)
131 IOStatisticsOpenGate();
132 res
= workLoop
->sleepGate(event
, type
);
133 IOStatisticsCloseGate();
138 IOEventSource::sleepGate(void *event
, AbsoluteTime deadline
, UInt32 type
)
141 IOStatisticsOpenGate();
142 res
= workLoop
->sleepGate(event
, deadline
, type
);
143 IOStatisticsCloseGate();
148 IOEventSource::wakeupGate(void *event
, bool oneThread
)
150 workLoop
->wakeupGate(event
, oneThread
);
155 IOEventSource::init(OSObject
*inOwner
,
164 if (!super::init()) {
168 (void) setAction(inAction
);
172 reserved
= IONew(ExpansionData
, 1);
178 IOStatisticsRegisterCounter();
184 IOEventSource::free( void )
186 IOStatisticsUnregisterCounter();
188 if ((kActionBlock
& flags
) && actionBlock
) {
189 Block_release(actionBlock
);
193 IODelete(reserved
, ExpansionData
, 1);
200 IOEventSource::setRefcon(void *newrefcon
)
206 IOEventSource::getRefcon() const
211 IOEventSource::Action
212 IOEventSource::getAction() const
214 if (kActionBlock
& flags
) {
220 IOEventSource::ActionBlock
221 IOEventSource::getActionBlock(ActionBlock
) const
223 if (kActionBlock
& flags
) {
230 IOEventSource::setAction(Action inAction
)
232 if ((kActionBlock
& flags
) && actionBlock
) {
233 Block_release(actionBlock
);
236 flags
&= ~kActionBlock
;
240 IOEventSource::setActionBlock(ActionBlock block
)
242 if ((kActionBlock
& flags
) && actionBlock
) {
243 Block_release(actionBlock
);
245 actionBlock
= Block_copy(block
);
246 flags
|= kActionBlock
;
250 IOEventSource::getNext() const
252 return eventChainNext
;
256 IOEventSource::setNext(IOEventSource
*inNext
)
258 eventChainNext
= inNext
;
262 IOEventSource::enable()
266 return signalWorkAvailable();
271 IOEventSource::disable()
277 IOEventSource::isEnabled() const
283 IOEventSource::setWorkLoop(IOWorkLoop
*inWorkLoop
)
288 workLoop
= inWorkLoop
;
292 IOEventSource::getWorkLoop() const
298 IOEventSource::onThread() const
300 return (workLoop
!= NULL
) && workLoop
->onThread();