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 * 11/13/2000 CJS Created IOCommandPool class and implementation
38 * @header IOCommandPool
40 * This header contains the IOCommandPool class definition.
43 #ifndef _IOKIT_IO_COMMAND_POOL_H_
44 #define _IOKIT_IO_COMMAND_POOL_H_
50 #if defined(KERNEL) && defined(__cplusplus)
52 #include <kern/kern_types.h>
53 #include <kern/queue.h>
54 #include <IOKit/IOCommand.h>
55 #include <IOKit/IOCommandGate.h>
56 #include <IOKit/IOService.h>
57 #include <IOKit/IOWorkLoop.h>
60 * @class IOCommandPool
62 * The IOCommandPool class is used to manipulate a pool of commands which
63 * inherit from IOCommand.
65 * The IOCommandPool class is used to manipulate a pool of commands which
66 * inherit from IOCommand. It includes a factory method to create a pool
67 * of a certain size. Once the factory method is invoked, the semaphore
68 * is set to zero. The caller must then put commands in the pool by creating
69 * the command (via the controller's factory method or a memory allocation)
70 * and calling the returnCommand method with the newly created command as its
74 class IOCommandPool
: public OSObject
77 OSDeclareDefaultStructors(IOCommandPool
)
82 queue_head_t fQueueHead
; /* head of the queue of elements available */
83 UInt32 fSleepers
; /* Count of threads sleeping on this pool */
84 IOCommandGate
*fSerializer
; /* command gate used for serializing pool access */
86 /*! @struct ExpansionData
87 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
89 struct ExpansionData
{ };
92 Reserved for future use. (Internal use only) */
93 ExpansionData
*reserved
;
96 * @defined kIOCommandPoolDefaultSize
98 * kIOCommandPoolDefaultSize is the default size of any command pool.
100 * kIOCommandPoolDefaultSize is the default size of any command pool.
101 * The default size was determined to be the smallest size for which
102 * a pool makes sense.
105 static const UInt32 kIOCommandPoolDefaultSize
= 2;
108 * Free all of this object's outstanding resources.
111 virtual void free(void);
117 * @function initWithWorkLoop
118 * @abstract Primary initialiser for an IOCommandPool Object
119 * @discussion Primary initialiser for an IOCommandPool.
120 * Should probably use IOCommandPool::withWorkLoop() as it is easier to use.
122 * The workloop that this command pool should synchronise with.
123 * @result true if command pool was sucessfully initialised.
125 virtual bool initWithWorkLoop(IOWorkLoop
*workLoop
);
128 * @function withWorkLoop
129 * @abstract Primary factory method for the IOCommandPool class
131 * The withWorkLoop method is what is known as a factory method. It creates
132 * a new instance of an IOCommandPool and returns a pointer to that object.
134 * The workloop that this command pool should synchronise with.
136 * Returns a pointer to an instance of IOCommandPool if successful,
140 static IOCommandPool
*withWorkLoop(IOWorkLoop
*inWorkLoop
);
144 * @abstract Should never be used, obsolete See initWithWorkLoop
146 virtual bool init(IOService
*inOwner
,
147 IOWorkLoop
*inWorkLoop
,
148 UInt32 inSize
= kIOCommandPoolDefaultSize
);
151 * @function withWorkLoop
152 * @abstract Should never be used, obsolete See IOCommandPool::withWorkLoop
154 static IOCommandPool
*commandPool(IOService
*inOwner
,
155 IOWorkLoop
*inWorkLoop
,
156 UInt32 inSize
= kIOCommandPoolDefaultSize
);
160 * @function getCommand
162 * The getCommand method is used to get a pointer to an object of type IOCommand
164 * @param blockForCommand
165 * If the caller would like to have its thread slept until a command is
166 * available, it should pass true, else false
168 * If the caller passes true in blockForCommand, getCommand guarantees that
169 * the result will be a pointer to an IOCommand object from the pool. If
170 * the caller passes false, s/he is responsible for checking whether a non-NULL
171 * pointer was returned.
174 virtual IOCommand
*getCommand(bool blockForCommand
= true);
177 * @function returnCommand
179 * The returnCommand method is used to place an object of type IOCommand
180 * into the pool, whether it be the first time, or the 1000th time.
182 * The command to place in the pool.
185 virtual void returnCommand(IOCommand
*command
);
190 * @function gatedGetCommand
192 * The gatedGetCommand method is used to serialize the extraction of a
193 * command of from the pool behind a command gate.
194 * runAction-ed by getCommand.
196 * A pointer to a pointer to an IOCommand object where the returned
197 * command will be stored
199 * A bool that indicates whether to block the request until a command
202 * Returns kIOReturnNoResources if no command is available and the client
203 * doesn't with to block until one does become available.
204 * kIOReturnSuccess if the vCommand argument is valid.
206 virtual IOReturn
gatedGetCommand(IOCommand
**command
, bool blockForCommand
);
209 * @function gatedReturnCommand
211 * The gatedReturnCommand method is used to serialize the return of a
212 * command of to the pool behind a command gate.
213 * runAction-ed by returnCommand.
215 * A pointer to the IOCommand object to be returned to the pool.
217 * Always returns kIOReturnSuccess if the vCommand argument is valid.
219 virtual IOReturn
gatedReturnCommand(IOCommand
*command
);
222 OSMetaClassDeclareReservedUnused(IOCommandPool
, 0);
223 OSMetaClassDeclareReservedUnused(IOCommandPool
, 1);
224 OSMetaClassDeclareReservedUnused(IOCommandPool
, 2);
225 OSMetaClassDeclareReservedUnused(IOCommandPool
, 3);
226 OSMetaClassDeclareReservedUnused(IOCommandPool
, 4);
227 OSMetaClassDeclareReservedUnused(IOCommandPool
, 5);
228 OSMetaClassDeclareReservedUnused(IOCommandPool
, 6);
229 OSMetaClassDeclareReservedUnused(IOCommandPool
, 7);
232 #endif /* defined(KERNEL) && defined(__cplusplus) */
234 #endif /* _IOKIT_IO_COMMAND_POOL_H_ */