]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandPool.cpp
3bddd5b8a28a580cac6895508cfa0da4bbe36790
2 * Copyright (c) 2000 Apple Computer, 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@
31 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
35 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
36 * 10/9/2000 CJS Created IOCommandPool class and implementation
40 #include <IOKit/IOCommandPool.h>
42 #define super OSObject
43 OSDefineMetaClassAndStructors(IOCommandPool
, OSObject
);
44 OSMetaClassDefineReservedUnused(IOCommandPool
, 0);
45 OSMetaClassDefineReservedUnused(IOCommandPool
, 1);
46 OSMetaClassDefineReservedUnused(IOCommandPool
, 2);
47 OSMetaClassDefineReservedUnused(IOCommandPool
, 3);
48 OSMetaClassDefineReservedUnused(IOCommandPool
, 4);
49 OSMetaClassDefineReservedUnused(IOCommandPool
, 5);
50 OSMetaClassDefineReservedUnused(IOCommandPool
, 6);
51 OSMetaClassDefineReservedUnused(IOCommandPool
, 7);
53 //--------------------------------------------------------------------------
54 // withWorkLoop - primary initializer and factory method
55 //--------------------------------------------------------------------------
57 IOCommandPool
*IOCommandPool::
58 withWorkLoop(IOWorkLoop
*inWorkLoop
)
60 IOCommandPool
* me
= new IOCommandPool
;
62 if (me
&& !me
->initWithWorkLoop(inWorkLoop
)) {
72 initWithWorkLoop(IOWorkLoop
*inWorkLoop
)
79 queue_init(&fQueueHead
);
81 fSerializer
= IOCommandGate::commandGate(this);
86 if (kIOReturnSuccess
!= inWorkLoop
->addEventSource(fSerializer
))
92 //--------------------------------------------------------------------------
93 // commandPool & init - obsolete initializer and factory method
94 //--------------------------------------------------------------------------
96 IOCommandPool
*IOCommandPool::
97 commandPool(IOService
* inOwner
, IOWorkLoop
*inWorkLoop
, UInt32 inSize
)
99 IOCommandPool
* me
= new IOCommandPool
;
101 if (me
&& !me
->init(inOwner
, inWorkLoop
, inSize
)) {
110 init(IOService */
* inOwner */
, IOWorkLoop
*inWorkLoop
, UInt32
/* inSize */)
112 return initWithWorkLoop(inWorkLoop
);
116 //--------------------------------------------------------------------------
117 // free - free all allocated resources
118 //--------------------------------------------------------------------------
121 IOCommandPool::free(void)
124 // remove our event source from owner's workloop
125 IOWorkLoop
*wl
= fSerializer
->getWorkLoop();
127 wl
->removeEventSource(fSerializer
);
129 fSerializer
->release();
133 // Tell our superclass to cleanup too
138 //--------------------------------------------------------------------------
139 // getCommand - Gets a command from the pool. Pass true in
140 // blockForCommand if you want your thread to sleep
141 // waiting for resources
142 //--------------------------------------------------------------------------
145 IOCommandPool::getCommand(bool blockForCommand
)
147 IOReturn result
= kIOReturnSuccess
;
148 IOCommand
*command
= 0;
150 result
= fSerializer
->runAction((IOCommandGate::Action
)
151 &IOCommandPool::gatedGetCommand
,
152 (void *) &command
, (void *) blockForCommand
);
153 if (kIOReturnSuccess
== result
)
160 //--------------------------------------------------------------------------
161 // gatedGetCommand - Static callthrough function
162 // (on safe side of command gate)
163 //--------------------------------------------------------------------------
165 IOReturn
IOCommandPool::
166 gatedGetCommand(IOCommand
**command
, bool blockForCommand
)
168 while (queue_empty(&fQueueHead
)) {
169 if (!blockForCommand
)
170 return kIOReturnNoResources
;
173 fSerializer
->commandSleep(&fSleepers
, THREAD_UNINT
);
176 queue_remove_first(&fQueueHead
,
177 *command
, IOCommand
*, fCommandChain
);
178 return kIOReturnSuccess
;
182 //--------------------------------------------------------------------------
183 // returnCommand - Returns command to the pool.
184 //--------------------------------------------------------------------------
187 returnCommand(IOCommand
*command
)
189 (void) fSerializer
->runAction((IOCommandGate::Action
)
190 &IOCommandPool::gatedReturnCommand
, (void *) command
);
194 //--------------------------------------------------------------------------
195 // gatedReturnCommand - Callthrough function
196 // (on safe side of command gate)
197 //--------------------------------------------------------------------------
199 IOReturn
IOCommandPool::
200 gatedReturnCommand(IOCommand
*command
)
202 queue_enter(&fQueueHead
, command
, IOCommand
*, fCommandChain
);
204 fSerializer
->commandWakeup(&fSleepers
, /* oneThread */ true);
207 return kIOReturnSuccess
;