]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOCommandPool.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / iokit / IOKit / IOCommandPool.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30
31/*
32 *
33 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
34 *
35 * HISTORY
36 *
37 * 2001-01-17 gvdl Re-implement on IOCommandGate::commandSleep
38 * 11/13/2000 CJS Created IOCommandPool class and implementation
39 *
40 */
41
42/*!
43 * @header IOCommandPool
44 * @abstract
45 * This header contains the IOCommandPool class definition.
46 */
47
48#ifndef _IOKIT_IO_COMMAND_POOL_H_
49#define _IOKIT_IO_COMMAND_POOL_H_
50
51/*
52 * Kernel
53 */
54
55#if defined(KERNEL) && defined(__cplusplus)
56
57#include <kern/kern_types.h>
58#include <kern/queue.h>
59#include <IOKit/IOCommand.h>
60#include <IOKit/IOCommandGate.h>
61#include <IOKit/IOService.h>
62#include <IOKit/IOWorkLoop.h>
63
64/*!
65 * @class IOCommandPool
91447636 66 * @abstract Manipulates a pool of commands which inherit from IOCommand.
1c79356b
A
67 * @discussion
68 * The IOCommandPool class is used to manipulate a pool of commands which
69 * inherit from IOCommand. It includes a factory method to create a pool
70 * of a certain size. Once the factory method is invoked, the semaphore
71 * is set to zero. The caller must then put commands in the pool by creating
72 * the command (via the controller's factory method or a memory allocation)
73 * and calling the returnCommand method with the newly created command as its
74 * argument.
75 */
76
77class IOCommandPool : public OSObject
78{
79
80 OSDeclareDefaultStructors(IOCommandPool)
81
82
83protected:
84
85 queue_head_t fQueueHead; /* head of the queue of elements available */
86 UInt32 fSleepers; /* Count of threads sleeping on this pool */
87 IOCommandGate *fSerializer; /* command gate used for serializing pool access */
88
89/*! @struct ExpansionData
90 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
91 */
92 struct ExpansionData { };
93
94/*! @var reserved
95 Reserved for future use. (Internal use only) */
96 ExpansionData *reserved;
97
98 /*!
91447636
A
99 * @const kIOCommandPoolDefaultSize
100 * @abstract The default size of any command pool.
1c79356b
A
101 * @discussion
102 * kIOCommandPoolDefaultSize is the default size of any command pool.
103 * The default size was determined to be the smallest size for which
104 * a pool makes sense.
105 */
106
107 static const UInt32 kIOCommandPoolDefaultSize = 2;
108
109 /*
110 * Free all of this object's outstanding resources.
111 */
112
113 virtual void free(void);
114
115
116public:
117
118 /*!
119 * @function initWithWorkLoop
91447636
A
120 * @abstract Primary initializer for an IOCommandPool object.
121 * @discussion Primary initializer for an IOCommandPool.
1c79356b
A
122 * Should probably use IOCommandPool::withWorkLoop() as it is easier to use.
123 * @param inWorkLoop
91447636
A
124 * The workloop that this command pool should synchronize with.
125 * @result Returns true if command pool was successfully initialized.
1c79356b
A
126 */
127 virtual bool initWithWorkLoop(IOWorkLoop *workLoop);
128
129 /*!
130 * @function withWorkLoop
131 * @abstract Primary factory method for the IOCommandPool class
132 * @discussion
133 * The withWorkLoop method is what is known as a factory method. It creates
134 * a new instance of an IOCommandPool and returns a pointer to that object.
135 * @param inWorkLoop
91447636 136 * The workloop that this command pool should synchronize with.
1c79356b
A
137 * @result
138 * Returns a pointer to an instance of IOCommandPool if successful,
139 * otherwise NULL.
140 */
141
142 static IOCommandPool *withWorkLoop(IOWorkLoop *inWorkLoop);
143
144 /*!
145 * @function init
91447636 146 * @abstract Should never be used, obsolete. See initWithWorkLoop.
1c79356b
A
147 */
148 virtual bool init(IOService *inOwner,
149 IOWorkLoop *inWorkLoop,
150 UInt32 inSize = kIOCommandPoolDefaultSize);
151
152 /*!
153 * @function withWorkLoop
91447636 154 * @abstract Should never be used, obsolete. See IOCommandPool::withWorkLoop.
1c79356b
A
155 */
156 static IOCommandPool *commandPool(IOService *inOwner,
157 IOWorkLoop *inWorkLoop,
158 UInt32 inSize = kIOCommandPoolDefaultSize);
159
160
161 /*!
162 * @function getCommand
91447636 163 * @discussion The getCommand method is used to get a pointer to an object of type IOCommand from the pool.
1c79356b
A
164 * @param blockForCommand
165 * If the caller would like to have its thread slept until a command is
91447636 166 * available, it should pass true, else false.
1c79356b
A
167 * @result
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.
172 */
173
174 virtual IOCommand *getCommand(bool blockForCommand = true);
175
176 /*!
177 * @function returnCommand
178 * @discussion
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.
181 * @param commmand
182 * The command to place in the pool.
183 */
184
185 virtual void returnCommand(IOCommand *command);
186
187protected:
188
189 /*!
190 * @function gatedGetCommand
191 * @discussion
192 * The gatedGetCommand method is used to serialize the extraction of a
91447636 193 * command from the pool behind a command gate, runAction-ed by getCommand.
1c79356b
A
194 * @param vCommand
195 * A pointer to a pointer to an IOCommand object where the returned
91447636 196 * command will be stored.
1c79356b
A
197 * @param vBlock
198 * A bool that indicates whether to block the request until a command
199 * becomes available.
200 * @result
201 * Returns kIOReturnNoResources if no command is available and the client
91447636 202 * doesn't wish to block until one does become available.
1c79356b
A
203 * kIOReturnSuccess if the vCommand argument is valid.
204 */
205 virtual IOReturn gatedGetCommand(IOCommand **command, bool blockForCommand);
206
207 /*!
208 * @function gatedReturnCommand
209 * @discussion
210 * The gatedReturnCommand method is used to serialize the return of a
91447636 211 * command to the pool behind a command gate, runAction-ed by returnCommand.
1c79356b
A
212 * @param vCommand
213 * A pointer to the IOCommand object to be returned to the pool.
214 * @result
215 * Always returns kIOReturnSuccess if the vCommand argument is valid.
216 */
217 virtual IOReturn gatedReturnCommand(IOCommand *command);
218
219private:
220 OSMetaClassDeclareReservedUnused(IOCommandPool, 0);
221 OSMetaClassDeclareReservedUnused(IOCommandPool, 1);
222 OSMetaClassDeclareReservedUnused(IOCommandPool, 2);
223 OSMetaClassDeclareReservedUnused(IOCommandPool, 3);
224 OSMetaClassDeclareReservedUnused(IOCommandPool, 4);
225 OSMetaClassDeclareReservedUnused(IOCommandPool, 5);
226 OSMetaClassDeclareReservedUnused(IOCommandPool, 6);
227 OSMetaClassDeclareReservedUnused(IOCommandPool, 7);
228};
229
230#endif /* defined(KERNEL) && defined(__cplusplus) */
231
232#endif /* _IOKIT_IO_COMMAND_POOL_H_ */