]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
32 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
33 * 10/9/2000 CJS Created IOCommandPool class and implementation
37 #include <IOKit/IOCommandPool.h>
39 #define super OSObject
40 OSDefineMetaClassAndStructors(IOCommandPool
, OSObject
);
41 OSMetaClassDefineReservedUnused(IOCommandPool
, 0);
42 OSMetaClassDefineReservedUnused(IOCommandPool
, 1);
43 OSMetaClassDefineReservedUnused(IOCommandPool
, 2);
44 OSMetaClassDefineReservedUnused(IOCommandPool
, 3);
45 OSMetaClassDefineReservedUnused(IOCommandPool
, 4);
46 OSMetaClassDefineReservedUnused(IOCommandPool
, 5);
47 OSMetaClassDefineReservedUnused(IOCommandPool
, 6);
48 OSMetaClassDefineReservedUnused(IOCommandPool
, 7);
50 //--------------------------------------------------------------------------
51 // withWorkLoop - primary initializer and factory method
52 //--------------------------------------------------------------------------
54 IOCommandPool
*IOCommandPool::
55 withWorkLoop(IOWorkLoop
*inWorkLoop
)
57 IOCommandPool
* me
= new IOCommandPool
;
59 if (me
&& !me
->initWithWorkLoop(inWorkLoop
)) {
69 initWithWorkLoop(IOWorkLoop
*inWorkLoop
)
76 queue_init(&fQueueHead
);
78 fSerializer
= IOCommandGate::commandGate(this);
83 if (kIOReturnSuccess
!= inWorkLoop
->addEventSource(fSerializer
))
89 //--------------------------------------------------------------------------
90 // commandPool & init - obsolete initializer and factory method
91 //--------------------------------------------------------------------------
93 IOCommandPool
*IOCommandPool::
94 commandPool(IOService
* inOwner
, IOWorkLoop
*inWorkLoop
, UInt32 inSize
)
96 IOCommandPool
* me
= new IOCommandPool
;
98 if (me
&& !me
->init(inOwner
, inWorkLoop
, inSize
)) {
107 init(IOService */
* inOwner */
, IOWorkLoop
*inWorkLoop
, UInt32
/* inSize */)
109 return initWithWorkLoop(inWorkLoop
);
113 //--------------------------------------------------------------------------
114 // free - free all allocated resources
115 //--------------------------------------------------------------------------
118 IOCommandPool::free(void)
121 // remove our event source from owner's workloop
122 IOWorkLoop
*wl
= fSerializer
->getWorkLoop();
124 wl
->removeEventSource(fSerializer
);
126 fSerializer
->release();
130 // Tell our superclass to cleanup too
135 //--------------------------------------------------------------------------
136 // getCommand - Gets a command from the pool. Pass true in
137 // blockForCommand if you want your thread to sleep
138 // waiting for resources
139 //--------------------------------------------------------------------------
142 IOCommandPool::getCommand(bool blockForCommand
)
144 IOReturn result
= kIOReturnSuccess
;
145 IOCommand
*command
= 0;
147 result
= fSerializer
->runAction((IOCommandGate::Action
)
148 &IOCommandPool::gatedGetCommand
,
149 (void *) &command
, (void *) blockForCommand
);
150 if (kIOReturnSuccess
== result
)
157 //--------------------------------------------------------------------------
158 // gatedGetCommand - Static callthrough function
159 // (on safe side of command gate)
160 //--------------------------------------------------------------------------
162 IOReturn
IOCommandPool::
163 gatedGetCommand(IOCommand
**command
, bool blockForCommand
)
165 while (queue_empty(&fQueueHead
)) {
166 if (!blockForCommand
)
167 return kIOReturnNoResources
;
170 fSerializer
->commandSleep(&fSleepers
, THREAD_UNINT
);
173 queue_remove_first(&fQueueHead
,
174 *command
, IOCommand
*, fCommandChain
);
175 return kIOReturnSuccess
;
179 //--------------------------------------------------------------------------
180 // returnCommand - Returns command to the pool.
181 //--------------------------------------------------------------------------
184 returnCommand(IOCommand
*command
)
186 (void) fSerializer
->runAction((IOCommandGate::Action
)
187 &IOCommandPool::gatedReturnCommand
, (void *) command
);
191 //--------------------------------------------------------------------------
192 // gatedReturnCommand - Callthrough function
193 // (on safe side of command gate)
194 //--------------------------------------------------------------------------
196 IOReturn
IOCommandPool::
197 gatedReturnCommand(IOCommand
*command
)
199 queue_enter(&fQueueHead
, command
, IOCommand
*, fCommandChain
);
201 fSerializer
->commandWakeup(&fSleepers
, /* oneThread */ true);
204 return kIOReturnSuccess
;