]>
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);
54 bool IOEventSource::checkForWork() { return false; }
56 /* inline function implementations */
60 #define IOStatisticsRegisterCounter() \
62 reserved->counter = IOStatistics::registerEventSource(inOwner); \
65 #define IOStatisticsUnregisterCounter() \
68 IOStatistics::unregisterEventSource(reserved->counter); \
71 #define IOStatisticsOpenGate() \
73 IOStatistics::countOpenGate(reserved->counter); \
76 #define IOStatisticsCloseGate() \
78 IOStatistics::countCloseGate(reserved->counter); \
83 #define IOStatisticsRegisterCounter()
84 #define IOStatisticsUnregisterCounter()
85 #define IOStatisticsOpenGate()
86 #define IOStatisticsCloseGate()
88 #endif /* IOKITSTATS */
90 void IOEventSource::signalWorkAvailable()
92 workLoop
->signalWorkAvailable();
95 void IOEventSource::openGate()
97 IOStatisticsOpenGate();
101 void IOEventSource::closeGate()
103 workLoop
->closeGate();
104 IOStatisticsCloseGate();
107 bool IOEventSource::tryCloseGate()
110 if ((res
= workLoop
->tryCloseGate())) {
111 IOStatisticsCloseGate();
116 int IOEventSource::sleepGate(void *event
, UInt32 type
)
119 IOStatisticsOpenGate();
120 res
= workLoop
->sleepGate(event
, type
);
121 IOStatisticsCloseGate();
125 int IOEventSource::sleepGate(void *event
, AbsoluteTime deadline
, UInt32 type
)
128 IOStatisticsOpenGate();
129 res
= workLoop
->sleepGate(event
, deadline
, type
);
130 IOStatisticsCloseGate();
134 void IOEventSource::wakeupGate(void *event
, bool oneThread
) { workLoop
->wakeupGate(event
, oneThread
); }
137 bool IOEventSource::init(OSObject
*inOwner
,
145 if ( !super::init() )
148 (void) setAction(inAction
);
152 reserved
= IONew(ExpansionData
, 1);
158 IOStatisticsRegisterCounter();
163 void IOEventSource::free( void )
165 IOStatisticsUnregisterCounter();
167 if ((kActionBlock
& flags
) && actionBlock
) Block_release(actionBlock
);
170 IODelete(reserved
, ExpansionData
, 1);
175 void IOEventSource::setRefcon(void *newrefcon
)
180 void * IOEventSource::getRefcon() const
185 IOEventSource::Action
IOEventSource::getAction() const
187 if (kActionBlock
& flags
) return NULL
;
191 IOEventSource::ActionBlock
IOEventSource::getActionBlock(ActionBlock
) const
193 if (kActionBlock
& flags
) return actionBlock
;
197 void IOEventSource::setAction(Action inAction
)
199 if ((kActionBlock
& flags
) && actionBlock
) Block_release(actionBlock
);
203 void IOEventSource::setActionBlock(ActionBlock block
)
205 if ((kActionBlock
& flags
) && actionBlock
) Block_release(actionBlock
);
206 actionBlock
= Block_copy(block
);
207 flags
|= kActionBlock
;
210 IOEventSource
*IOEventSource::getNext() const { return eventChainNext
; };
212 void IOEventSource::setNext(IOEventSource
*inNext
)
214 eventChainNext
= inNext
;
217 void IOEventSource::enable()
221 return signalWorkAvailable();
224 void IOEventSource::disable()
229 bool IOEventSource::isEnabled() const
234 void IOEventSource::setWorkLoop(IOWorkLoop
*inWorkLoop
)
238 workLoop
= inWorkLoop
;
241 IOWorkLoop
*IOEventSource::getWorkLoop() const
246 bool IOEventSource::onThread() const
248 return (workLoop
!= 0) && workLoop
->onThread();