VirtualBox

source: vbox/trunk/include/iprt/req.h@ 7706

Last change on this file since 7706 was 7170, checked in by vboxsync, 17 years ago

Doxygen fixes. (DOXYGEN -> DOXYGEN_RUNNING, ++)

  • Property eol-style set to native
File size: 12.4 KB
Line 
1/** @file
2 * innotek Portable Runtime - Request packets
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_req_h
27#define ___iprt_req_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32#include <iprt/stdarg.h>
33
34__BEGIN_DECLS
35
36/** @defgroup grp_rt_req RTReq - Request Packet Management
37 * @ingroup grp_rt
38 * @{
39 */
40
41/**
42 * Request type.
43 */
44typedef enum RTREQTYPE
45{
46 /** Invalid request. */
47 RTREQTYPE_INVALID = 0,
48 /** RT: Internal. */
49 RTREQTYPE_INTERNAL,
50 /** Maximum request type (exclusive). Used for validation. */
51 RTREQTYPE_MAX
52} RTREQTYPE;
53
54/**
55 * Request state.
56 */
57typedef enum RTREQSTATE
58{
59 /** The state is invalid. */
60 RTREQSTATE_INVALID = 0,
61 /** The request have been allocated and is in the process of being filed. */
62 RTREQSTATE_ALLOCATED,
63 /** The request is queued by the requester. */
64 RTREQSTATE_QUEUED,
65 /** The request is begin processed. */
66 RTREQSTATE_PROCESSING,
67 /** The request is completed, the requester is begin notified. */
68 RTREQSTATE_COMPLETED,
69 /** The request packet is in the free chain. (The requester */
70 RTREQSTATE_FREE
71} RTREQSTATE;
72
73/**
74 * Request flags.
75 */
76typedef enum RTREQFLAGS
77{
78 /** The request returns a iprt status code. */
79 RTREQFLAGS_IPRT_STATUS = 0,
80 /** The request is a void request and have no status code. */
81 RTREQFLAGS_VOID = 1,
82 /** Return type mask. */
83 RTREQFLAGS_RETURN_MASK = 1,
84 /** Caller does not wait on the packet, Queue process thread will free it. */
85 RTREQFLAGS_NO_WAIT = 2
86} RTREQFLAGS;
87
88/** Pointer to a request queue. */
89typedef struct RTREQQUEUE *PRTREQQUEUE;
90
91/**
92 * RT Request packet.
93 *
94 * This is used to request an action in the queue handler thread.
95 */
96typedef struct RTREQ
97{
98 /** Pointer to the next request in the chain. */
99 struct RTREQ * volatile pNext;
100 /** Pointer to the queue this packet belongs to. */
101 PRTREQQUEUE pQueue;
102 /** Request state. */
103 volatile RTREQSTATE enmState;
104 /** iprt status code for the completed request. */
105 volatile int iStatus;
106 /** Requester event sem.
107 * The request can use this event semaphore to wait/poll for completion
108 * of the request.
109 */
110 RTSEMEVENT EventSem;
111 /** Set if the event semaphore is clear. */
112 volatile bool fEventSemClear;
113 /** Flags, RTREQ_FLAGS_*. */
114 unsigned fFlags;
115 /** Request type. */
116 RTREQTYPE enmType;
117 /** Request specific data. */
118 union RTREQ_U
119 {
120 /** RTREQTYPE_INTERNAL. */
121 struct
122 {
123 /** Pointer to the function to be called. */
124 PFNRT pfn;
125 /** Number of arguments. */
126 unsigned cArgs;
127 /** Array of arguments. */
128 uintptr_t aArgs[64];
129 } Internal;
130 } u;
131} RTREQ;
132/** Pointer to an RT request packet. */
133typedef RTREQ *PRTREQ;
134
135/** @todo hide this */
136typedef struct RTREQQUEUE
137{
138 /** Head of the request queue. Atomic. */
139 volatile PRTREQ pReqs;
140 /** The last index used during alloc/free. */
141 volatile uint32_t iReqFree;
142 /** Number of free request packets. */
143 volatile uint32_t cReqFree;
144 /** Array of pointers to lists of free request packets. Atomic. */
145 volatile PRTREQ apReqFree[9];
146 /** Requester event sem.
147 * The request can use this event semaphore to wait/poll for new requests.
148 */
149 RTSEMEVENT EventSem;
150} RTREQQUEUE;
151
152#ifdef IN_RING3
153
154/**
155 * Create a request packet queueu
156 *
157 * @returns iprt status code.
158 * @param ppQueue Where to store the request queue pointer.
159 */
160RTDECL(int) RTReqCreateQueue(PRTREQQUEUE *ppQueue);
161
162
163/**
164 * Destroy a request packet queueu
165 *
166 * @returns iprt status code.
167 * @param pQueue The request queue.
168 */
169RTDECL(int) RTReqDestroyQueue(PRTREQQUEUE pQueue);
170
171
172/**
173 * Process one or more request packets
174 *
175 * @returns iprt status code.
176 * @returns VERR_TIMEOUT if cMillies was reached without the packet being added.
177 *
178 * @param pQueue The request queue.
179 * @param cMillies Number of milliseconds to wait for a pending request.
180 * Use RT_INDEFINITE_WAIT to only wait till one is added.
181 */
182RTDECL(int) RTReqProcess(PRTREQQUEUE pQueue, unsigned cMillies);
183
184
185/**
186 * Allocate and queue a call request.
187 *
188 * If it's desired to poll on the completion of the request set cMillies
189 * to 0 and use RTReqWait() to check for completation. In the other case
190 * use RT_INDEFINITE_WAIT.
191 * The returned request packet must be freed using RTReqFree().
192 *
193 * @returns iprt statuscode.
194 * Will not return VERR_INTERRUPTED.
195 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
196 *
197 * @param pQueue The request queue.
198 * @param ppReq Where to store the pointer to the request.
199 * This will be NULL or a valid request pointer not matter what happends.
200 * @param cMillies Number of milliseconds to wait for the request to
201 * be completed. Use RT_INDEFINITE_WAIT to only
202 * wait till it's completed.
203 * @param pfnFunction Pointer to the function to call.
204 * @param cArgs Number of arguments following in the ellipsis.
205 * Not possible to pass 64-bit arguments!
206 * @param ... Function arguments.
207 */
208RTDECL(int) RTReqCall(PRTREQQUEUE pQueue, PRTREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
209
210
211/**
212 * Allocate and queue a call request to a void function.
213 *
214 * If it's desired to poll on the completion of the request set cMillies
215 * to 0 and use RTReqWait() to check for completation. In the other case
216 * use RT_INDEFINITE_WAIT.
217 * The returned request packet must be freed using RTReqFree().
218 *
219 * @returns iprt status code.
220 * Will not return VERR_INTERRUPTED.
221 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
222 *
223 * @param pQueue The request queue.
224 * @param ppReq Where to store the pointer to the request.
225 * This will be NULL or a valid request pointer not matter what happends.
226 * @param cMillies Number of milliseconds to wait for the request to
227 * be completed. Use RT_INDEFINITE_WAIT to only
228 * wait till it's completed.
229 * @param pfnFunction Pointer to the function to call.
230 * @param cArgs Number of arguments following in the ellipsis.
231 * Not possible to pass 64-bit arguments!
232 * @param ... Function arguments.
233 */
234RTDECL(int) RTReqCallVoid(PRTREQQUEUE pQueue, PRTREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
235
236
237/**
238 * Allocate and queue a call request to a void function.
239 *
240 * If it's desired to poll on the completion of the request set cMillies
241 * to 0 and use RTReqWait() to check for completation. In the other case
242 * use RT_INDEFINITE_WAIT.
243 * The returned request packet must be freed using RTReqFree().
244 *
245 * @returns iprt status code.
246 * Will not return VERR_INTERRUPTED.
247 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
248 *
249 * @param pQueue The request queue.
250 * @param ppReq Where to store the pointer to the request.
251 * This will be NULL or a valid request pointer not matter what happends, unless fFlags
252 * contains RTREQFLAGS_NO_WAIT when it will be optional and always NULL.
253 * @param cMillies Number of milliseconds to wait for the request to
254 * be completed. Use RT_INDEFINITE_WAIT to only
255 * wait till it's completed.
256 * @param fFlags A combination of the RTREQFLAGS values.
257 * @param pfnFunction Pointer to the function to call.
258 * @param cArgs Number of arguments following in the ellipsis.
259 * Not possible to pass 64-bit arguments!
260 * @param ... Function arguments.
261 */
262RTDECL(int) RTReqCallEx(PRTREQQUEUE pQueue, PRTREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
263
264
265/**
266 * Allocate and queue a call request.
267 *
268 * If it's desired to poll on the completion of the request set cMillies
269 * to 0 and use RTReqWait() to check for completation. In the other case
270 * use RT_INDEFINITE_WAIT.
271 * The returned request packet must be freed using RTReqFree().
272 *
273 * @returns iprt status code.
274 * Will not return VERR_INTERRUPTED.
275 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
276 *
277 * @param pQueue The request queue.
278 * @param ppReq Where to store the pointer to the request.
279 * This will be NULL or a valid request pointer not matter what happends, unless fFlags
280 * contains RTREQFLAGS_NO_WAIT when it will be optional and always NULL.
281 * @param cMillies Number of milliseconds to wait for the request to
282 * be completed. Use RT_INDEFINITE_WAIT to only
283 * wait till it's completed.
284 * @param fFlags A combination of the RTREQFLAGS values.
285 * @param pfnFunction Pointer to the function to call.
286 * @param cArgs Number of arguments following in the ellipsis.
287 * Not possible to pass 64-bit arguments!
288 * @param Args Variable argument vector.
289 */
290RTDECL(int) RTReqCallV(PRTREQQUEUE pQueue, PRTREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
291
292
293/**
294 * Allocates a request packet.
295 *
296 * The caller allocates a request packet, fills in the request data
297 * union and queues the request.
298 *
299 * @returns iprt status code.
300 *
301 * @param pQueue The request queue.
302 * @param ppReq Where to store the pointer to the allocated packet.
303 * @param enmType Package type.
304 */
305RTDECL(int) RTReqAlloc(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTREQTYPE enmType);
306
307
308/**
309 * Free a request packet.
310 *
311 * @returns iprt status code.
312 *
313 * @param pReq Package to free.
314 * @remark The request packet must be in allocated or completed state!
315 */
316RTDECL(int) RTReqFree(PRTREQ pReq);
317
318
319/**
320 * Queue a request.
321 *
322 * The quest must be allocated using RTReqAlloc() and contain
323 * all the required data.
324 * If it's disired to poll on the completion of the request set cMillies
325 * to 0 and use RTReqWait() to check for completation. In the other case
326 * use RT_INDEFINITE_WAIT.
327 *
328 * @returns iprt status code.
329 * Will not return VERR_INTERRUPTED.
330 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
331 *
332 * @param pReq The request to queue.
333 * @param cMillies Number of milliseconds to wait for the request to
334 * be completed. Use RT_INDEFINITE_WAIT to only
335 * wait till it's completed.
336 */
337RTDECL(int) RTReqQueue(PRTREQ pReq, unsigned cMillies);
338
339
340/**
341 * Wait for a request to be completed.
342 *
343 * @returns iprt status code.
344 * Will not return VERR_INTERRUPTED.
345 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
346 *
347 * @param pReq The request to wait for.
348 * @param cMillies Number of milliseconds to wait.
349 * Use RT_INDEFINITE_WAIT to only wait till it's completed.
350 */
351RTDECL(int) RTReqWait(PRTREQ pReq, unsigned cMillies);
352
353
354#endif /* IN_RING3 */
355
356
357/** @} */
358
359__END_DECLS
360
361#endif
362
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette