]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandPool.cpp
18cd89f009b096a17dce78d764a475ba1d279910
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
30 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
31 * 10/9/2000 CJS Created IOCommandPool class and implementation
35 #include <IOKit/IOCommandPool.h>
37 #define super OSObject
38 OSDefineMetaClassAndStructors(IOCommandPool
, OSObject
);
39 OSMetaClassDefineReservedUnused(IOCommandPool
, 0);
40 OSMetaClassDefineReservedUnused(IOCommandPool
, 1);
41 OSMetaClassDefineReservedUnused(IOCommandPool
, 2);
42 OSMetaClassDefineReservedUnused(IOCommandPool
, 3);
43 OSMetaClassDefineReservedUnused(IOCommandPool
, 4);
44 OSMetaClassDefineReservedUnused(IOCommandPool
, 5);
45 OSMetaClassDefineReservedUnused(IOCommandPool
, 6);
46 OSMetaClassDefineReservedUnused(IOCommandPool
, 7);
48 //--------------------------------------------------------------------------
49 // withWorkLoop - primary initializer and factory method
50 //--------------------------------------------------------------------------
52 IOCommandPool
*IOCommandPool::
53 withWorkLoop(IOWorkLoop
*inWorkLoop
)
55 IOCommandPool
* me
= new IOCommandPool
;
57 if (me
&& !me
->initWithWorkLoop(inWorkLoop
)) {
67 initWithWorkLoop(IOWorkLoop
*inWorkLoop
)
74 queue_init(&fQueueHead
);
76 fSerializer
= IOCommandGate::commandGate(this);
81 if (kIOReturnSuccess
!= inWorkLoop
->addEventSource(fSerializer
))
87 //--------------------------------------------------------------------------
88 // commandPool & init - obsolete initializer and factory method
89 //--------------------------------------------------------------------------
91 IOCommandPool
*IOCommandPool::
92 commandPool(IOService
* inOwner
, IOWorkLoop
*inWorkLoop
, UInt32 inSize
)
94 IOCommandPool
* me
= new IOCommandPool
;
96 if (me
&& !me
->init(inOwner
, inWorkLoop
, inSize
)) {
105 init(IOService */
* inOwner */
, IOWorkLoop
*inWorkLoop
, UInt32
/* inSize */)
107 return initWithWorkLoop(inWorkLoop
);
111 //--------------------------------------------------------------------------
112 // free - free all allocated resources
113 //--------------------------------------------------------------------------
116 IOCommandPool::free(void)
119 // remove our event source from owner's workloop
120 IOWorkLoop
*wl
= fSerializer
->getWorkLoop();
122 wl
->removeEventSource(fSerializer
);
124 fSerializer
->release();
128 // Tell our superclass to cleanup too
133 //--------------------------------------------------------------------------
134 // getCommand - Gets a command from the pool. Pass true in
135 // blockForCommand if you want your thread to sleep
136 // waiting for resources
137 //--------------------------------------------------------------------------
140 IOCommandPool::getCommand(bool blockForCommand
)
142 IOReturn result
= kIOReturnSuccess
;
143 IOCommand
*command
= 0;
145 result
= fSerializer
->runAction((IOCommandGate::Action
)
146 &IOCommandPool::gatedGetCommand
,
147 (void *) &command
, (void *) blockForCommand
);
148 if (kIOReturnSuccess
== result
)
155 //--------------------------------------------------------------------------
156 // gatedGetCommand - Static callthrough function
157 // (on safe side of command gate)
158 //--------------------------------------------------------------------------
160 IOReturn
IOCommandPool::
161 gatedGetCommand(IOCommand
**command
, bool blockForCommand
)
163 while (queue_empty(&fQueueHead
)) {
164 if (!blockForCommand
)
165 return kIOReturnNoResources
;
168 fSerializer
->commandSleep(&fSleepers
, THREAD_UNINT
);
171 queue_remove_first(&fQueueHead
,
172 *command
, IOCommand
*, fCommandChain
);
173 return kIOReturnSuccess
;
177 //--------------------------------------------------------------------------
178 // returnCommand - Returns command to the pool.
179 //--------------------------------------------------------------------------
182 returnCommand(IOCommand
*command
)
184 (void) fSerializer
->runAction((IOCommandGate::Action
)
185 &IOCommandPool::gatedReturnCommand
, (void *) command
);
189 //--------------------------------------------------------------------------
190 // gatedReturnCommand - Callthrough function
191 // (on safe side of command gate)
192 //--------------------------------------------------------------------------
194 IOReturn
IOCommandPool::
195 gatedReturnCommand(IOCommand
*command
)
197 queue_enter(&fQueueHead
, command
, IOCommand
*, fCommandChain
);
199 fSerializer
->commandWakeup(&fSleepers
, /* oneThread */ true);
202 return kIOReturnSuccess
;