]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandPool.cpp
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
29 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
30 * 10/9/2000 CJS Created IOCommandPool class and implementation
34 #include <IOKit/IOCommandPool.h>
36 #define super OSObject
37 OSDefineMetaClassAndStructors(IOCommandPool
, OSObject
);
38 OSMetaClassDefineReservedUnused(IOCommandPool
, 0);
39 OSMetaClassDefineReservedUnused(IOCommandPool
, 1);
40 OSMetaClassDefineReservedUnused(IOCommandPool
, 2);
41 OSMetaClassDefineReservedUnused(IOCommandPool
, 3);
42 OSMetaClassDefineReservedUnused(IOCommandPool
, 4);
43 OSMetaClassDefineReservedUnused(IOCommandPool
, 5);
44 OSMetaClassDefineReservedUnused(IOCommandPool
, 6);
45 OSMetaClassDefineReservedUnused(IOCommandPool
, 7);
47 //--------------------------------------------------------------------------
48 // withWorkLoop - primary initializer and factory method
49 //--------------------------------------------------------------------------
51 IOCommandPool
*IOCommandPool::
52 withWorkLoop(IOWorkLoop
*inWorkLoop
)
54 IOCommandPool
* me
= new IOCommandPool
;
56 if (me
&& !me
->initWithWorkLoop(inWorkLoop
)) {
66 initWithWorkLoop(IOWorkLoop
*inWorkLoop
)
73 queue_init(&fQueueHead
);
75 fSerializer
= IOCommandGate::commandGate(this);
80 if (kIOReturnSuccess
!= inWorkLoop
->addEventSource(fSerializer
))
86 //--------------------------------------------------------------------------
87 // commandPool & init - obsolete initializer and factory method
88 //--------------------------------------------------------------------------
90 IOCommandPool
*IOCommandPool::
91 commandPool(IOService
* inOwner
, IOWorkLoop
*inWorkLoop
, UInt32 inSize
)
93 IOCommandPool
* me
= new IOCommandPool
;
95 if (me
&& !me
->init(inOwner
, inWorkLoop
, inSize
)) {
104 init(IOService */
* inOwner */
, IOWorkLoop
*inWorkLoop
, UInt32
/* inSize */)
106 return initWithWorkLoop(inWorkLoop
);
110 //--------------------------------------------------------------------------
111 // free - free all allocated resources
112 //--------------------------------------------------------------------------
115 IOCommandPool::free(void)
118 // remove our event source from owner's workloop
119 IOWorkLoop
*wl
= fSerializer
->getWorkLoop();
121 wl
->removeEventSource(fSerializer
);
123 fSerializer
->release();
127 // Tell our superclass to cleanup too
132 //--------------------------------------------------------------------------
133 // getCommand - Gets a command from the pool. Pass true in
134 // blockForCommand if you want your thread to sleep
135 // waiting for resources
136 //--------------------------------------------------------------------------
139 IOCommandPool::getCommand(bool blockForCommand
)
141 IOReturn result
= kIOReturnSuccess
;
142 IOCommand
*command
= 0;
144 result
= fSerializer
->runAction((IOCommandGate::Action
)
145 &IOCommandPool::gatedGetCommand
,
146 (void *) &command
, (void *) blockForCommand
);
147 if (kIOReturnSuccess
== result
)
154 //--------------------------------------------------------------------------
155 // gatedGetCommand - Static callthrough function
156 // (on safe side of command gate)
157 //--------------------------------------------------------------------------
159 IOReturn
IOCommandPool::
160 gatedGetCommand(IOCommand
**command
, bool blockForCommand
)
162 while (queue_empty(&fQueueHead
)) {
163 if (!blockForCommand
)
164 return kIOReturnNoResources
;
167 fSerializer
->commandSleep(&fSleepers
, THREAD_UNINT
);
170 queue_remove_first(&fQueueHead
,
171 *command
, IOCommand
*, fCommandChain
);
172 return kIOReturnSuccess
;
176 //--------------------------------------------------------------------------
177 // returnCommand - Returns command to the pool.
178 //--------------------------------------------------------------------------
181 returnCommand(IOCommand
*command
)
183 (void) fSerializer
->runAction((IOCommandGate::Action
)
184 &IOCommandPool::gatedReturnCommand
, (void *) command
);
188 //--------------------------------------------------------------------------
189 // gatedReturnCommand - Callthrough function
190 // (on safe side of command gate)
191 //--------------------------------------------------------------------------
193 IOReturn
IOCommandPool::
194 gatedReturnCommand(IOCommand
*command
)
196 queue_enter(&fQueueHead
, command
, IOCommand
*, fCommandChain
);
198 fSerializer
->commandWakeup(&fSleepers
, /* oneThread */ true);
201 return kIOReturnSuccess
;