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