]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandPool.cpp
5376591ce284ffae61ae4a9f543f2d407ea33466
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
37 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
38 * 10/9/2000 CJS Created IOCommandPool class and implementation
42 #include <IOKit/IOCommandPool.h>
44 #define super OSObject
45 OSDefineMetaClassAndStructors(IOCommandPool
, OSObject
);
46 OSMetaClassDefineReservedUnused(IOCommandPool
, 0);
47 OSMetaClassDefineReservedUnused(IOCommandPool
, 1);
48 OSMetaClassDefineReservedUnused(IOCommandPool
, 2);
49 OSMetaClassDefineReservedUnused(IOCommandPool
, 3);
50 OSMetaClassDefineReservedUnused(IOCommandPool
, 4);
51 OSMetaClassDefineReservedUnused(IOCommandPool
, 5);
52 OSMetaClassDefineReservedUnused(IOCommandPool
, 6);
53 OSMetaClassDefineReservedUnused(IOCommandPool
, 7);
55 //--------------------------------------------------------------------------
56 // withWorkLoop - primary initializer and factory method
57 //--------------------------------------------------------------------------
59 IOCommandPool
*IOCommandPool::
60 withWorkLoop(IOWorkLoop
*inWorkLoop
)
62 IOCommandPool
* me
= new IOCommandPool
;
64 if (me
&& !me
->initWithWorkLoop(inWorkLoop
)) {
74 initWithWorkLoop(IOWorkLoop
*inWorkLoop
)
81 queue_init(&fQueueHead
);
83 fSerializer
= IOCommandGate::commandGate(this);
88 if (kIOReturnSuccess
!= inWorkLoop
->addEventSource(fSerializer
))
94 //--------------------------------------------------------------------------
95 // commandPool & init - obsolete initializer and factory method
96 //--------------------------------------------------------------------------
98 IOCommandPool
*IOCommandPool::
99 commandPool(IOService
* inOwner
, IOWorkLoop
*inWorkLoop
, UInt32 inSize
)
101 IOCommandPool
* me
= new IOCommandPool
;
103 if (me
&& !me
->init(inOwner
, inWorkLoop
, inSize
)) {
112 init(IOService */
* inOwner */
, IOWorkLoop
*inWorkLoop
, UInt32
/* inSize */)
114 return initWithWorkLoop(inWorkLoop
);
118 //--------------------------------------------------------------------------
119 // free - free all allocated resources
120 //--------------------------------------------------------------------------
123 IOCommandPool::free(void)
126 // remove our event source from owner's workloop
127 IOWorkLoop
*wl
= fSerializer
->getWorkLoop();
129 wl
->removeEventSource(fSerializer
);
131 fSerializer
->release();
135 // Tell our superclass to cleanup too
140 //--------------------------------------------------------------------------
141 // getCommand - Gets a command from the pool. Pass true in
142 // blockForCommand if you want your thread to sleep
143 // waiting for resources
144 //--------------------------------------------------------------------------
147 IOCommandPool::getCommand(bool blockForCommand
)
149 IOReturn result
= kIOReturnSuccess
;
150 IOCommand
*command
= 0;
152 IOCommandGate::Action func
= OSMemberFunctionCast(
153 IOCommandGate::Action
, this, &IOCommandPool::gatedGetCommand
);
154 result
= fSerializer
->
155 runAction(func
, (void *) &command
, (void *) blockForCommand
);
156 if (kIOReturnSuccess
== result
)
163 //--------------------------------------------------------------------------
164 // gatedGetCommand - Static callthrough function
165 // (on safe side of command gate)
166 //--------------------------------------------------------------------------
168 IOReturn
IOCommandPool::
169 gatedGetCommand(IOCommand
**command
, bool blockForCommand
)
171 while (queue_empty(&fQueueHead
)) {
172 if (!blockForCommand
)
173 return kIOReturnNoResources
;
176 fSerializer
->commandSleep(&fSleepers
, THREAD_UNINT
);
179 queue_remove_first(&fQueueHead
,
180 *command
, IOCommand
*, fCommandChain
);
181 return kIOReturnSuccess
;
185 //--------------------------------------------------------------------------
186 // returnCommand - Returns command to the pool.
187 //--------------------------------------------------------------------------
190 returnCommand(IOCommand
*command
)
192 IOCommandGate::Action func
= OSMemberFunctionCast(
193 IOCommandGate::Action
, this, &IOCommandPool::gatedReturnCommand
);
194 (void) fSerializer
->runAction(func
, (void *) command
);
198 //--------------------------------------------------------------------------
199 // gatedReturnCommand - Callthrough function
200 // (on safe side of command gate)
201 //--------------------------------------------------------------------------
203 IOReturn
IOCommandPool::
204 gatedReturnCommand(IOCommand
*command
)
206 queue_enter_first(&fQueueHead
, command
, IOCommand
*, fCommandChain
);
208 fSerializer
->commandWakeup(&fSleepers
, /* oneThread */ true);
211 return kIOReturnSuccess
;