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 * 11/13/2000 CJS Created IOCommandPool class and implementation
35 * @header IOCommandPool
37 * This header contains the IOCommandPool class definition.
40 #ifndef _IOKIT_IO_COMMAND_POOL_H_
41 #define _IOKIT_IO_COMMAND_POOL_H_
47 #if defined(KERNEL) && defined(__cplusplus)
49 #include <kern/kern_types.h>
50 #include <kern/queue.h>
51 #include <IOKit/IOCommand.h>
52 #include <IOKit/IOCommandGate.h>
53 #include <IOKit/IOService.h>
54 #include <IOKit/IOWorkLoop.h>
57 * @class IOCommandPool
59 * The IOCommandPool class is used to manipulate a pool of commands which
60 * inherit from IOCommand.
62 * The IOCommandPool class is used to manipulate a pool of commands which
63 * inherit from IOCommand. It includes a factory method to create a pool
64 * of a certain size. Once the factory method is invoked, the semaphore
65 * is set to zero. The caller must then put commands in the pool by creating
66 * the command (via the controller's factory method or a memory allocation)
67 * and calling the returnCommand method with the newly created command as its
71 class IOCommandPool
: public OSObject
74 OSDeclareDefaultStructors(IOCommandPool
)
79 queue_head_t fQueueHead
; /* head of the queue of elements available */
80 UInt32 fSleepers
; /* Count of threads sleeping on this pool */
81 IOCommandGate
*fSerializer
; /* command gate used for serializing pool access */
83 /*! @struct ExpansionData
84 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
86 struct ExpansionData
{ };
89 Reserved for future use. (Internal use only) */
90 ExpansionData
*reserved
;
93 * @defined kIOCommandPoolDefaultSize
95 * kIOCommandPoolDefaultSize is the default size of any command pool.
97 * kIOCommandPoolDefaultSize is the default size of any command pool.
98 * The default size was determined to be the smallest size for which
102 static const UInt32 kIOCommandPoolDefaultSize
= 2;
105 * Free all of this object's outstanding resources.
108 virtual void free(void);
114 * @function initWithWorkLoop
115 * @abstract Primary initialiser for an IOCommandPool Object
116 * @discussion Primary initialiser for an IOCommandPool.
117 * Should probably use IOCommandPool::withWorkLoop() as it is easier to use.
119 * The workloop that this command pool should synchronise with.
120 * @result true if command pool was sucessfully initialised.
122 virtual bool initWithWorkLoop(IOWorkLoop
*workLoop
);
125 * @function withWorkLoop
126 * @abstract Primary factory method for the IOCommandPool class
128 * The withWorkLoop method is what is known as a factory method. It creates
129 * a new instance of an IOCommandPool and returns a pointer to that object.
131 * The workloop that this command pool should synchronise with.
133 * Returns a pointer to an instance of IOCommandPool if successful,
137 static IOCommandPool
*withWorkLoop(IOWorkLoop
*inWorkLoop
);
141 * @abstract Should never be used, obsolete See initWithWorkLoop
143 virtual bool init(IOService
*inOwner
,
144 IOWorkLoop
*inWorkLoop
,
145 UInt32 inSize
= kIOCommandPoolDefaultSize
);
148 * @function withWorkLoop
149 * @abstract Should never be used, obsolete See IOCommandPool::withWorkLoop
151 static IOCommandPool
*commandPool(IOService
*inOwner
,
152 IOWorkLoop
*inWorkLoop
,
153 UInt32 inSize
= kIOCommandPoolDefaultSize
);
157 * @function getCommand
159 * The getCommand method is used to get a pointer to an object of type IOCommand
161 * @param blockForCommand
162 * If the caller would like to have its thread slept until a command is
163 * available, it should pass true, else false
165 * If the caller passes true in blockForCommand, getCommand guarantees that
166 * the result will be a pointer to an IOCommand object from the pool. If
167 * the caller passes false, s/he is responsible for checking whether a non-NULL
168 * pointer was returned.
171 virtual IOCommand
*getCommand(bool blockForCommand
= true);
174 * @function returnCommand
176 * The returnCommand method is used to place an object of type IOCommand
177 * into the pool, whether it be the first time, or the 1000th time.
179 * The command to place in the pool.
182 virtual void returnCommand(IOCommand
*command
);
187 * @function gatedGetCommand
189 * The gatedGetCommand method is used to serialize the extraction of a
190 * command of from the pool behind a command gate.
191 * runAction-ed by getCommand.
193 * A pointer to a pointer to an IOCommand object where the returned
194 * command will be stored
196 * A bool that indicates whether to block the request until a command
199 * Returns kIOReturnNoResources if no command is available and the client
200 * doesn't with to block until one does become available.
201 * kIOReturnSuccess if the vCommand argument is valid.
203 virtual IOReturn
gatedGetCommand(IOCommand
**command
, bool blockForCommand
);
206 * @function gatedReturnCommand
208 * The gatedReturnCommand method is used to serialize the return of a
209 * command of to the pool behind a command gate.
210 * runAction-ed by returnCommand.
212 * A pointer to the IOCommand object to be returned to the pool.
214 * Always returns kIOReturnSuccess if the vCommand argument is valid.
216 virtual IOReturn
gatedReturnCommand(IOCommand
*command
);
219 OSMetaClassDeclareReservedUnused(IOCommandPool
, 0);
220 OSMetaClassDeclareReservedUnused(IOCommandPool
, 1);
221 OSMetaClassDeclareReservedUnused(IOCommandPool
, 2);
222 OSMetaClassDeclareReservedUnused(IOCommandPool
, 3);
223 OSMetaClassDeclareReservedUnused(IOCommandPool
, 4);
224 OSMetaClassDeclareReservedUnused(IOCommandPool
, 5);
225 OSMetaClassDeclareReservedUnused(IOCommandPool
, 6);
226 OSMetaClassDeclareReservedUnused(IOCommandPool
, 7);
229 #endif /* defined(KERNEL) && defined(__cplusplus) */
231 #endif /* _IOKIT_IO_COMMAND_POOL_H_ */