VirtualBox

Changeset 39498 in vbox


Ignore:
Timestamp:
Dec 1, 2011 7:59:21 PM (13 years ago)
Author:
vboxsync
Message:

RTReq refactoring.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r39447 r39498  
    10161016# define RTRandU64                                      RT_MANGLER(RTRandU64)
    10171017# define RTRandU64Ex                                    RT_MANGLER(RTRandU64Ex)
    1018 # define RTReqAlloc                                     RT_MANGLER(RTReqAlloc)
    1019 # define RTReqCall                                      RT_MANGLER(RTReqCall)
    1020 # define RTReqCallEx                                    RT_MANGLER(RTReqCallEx)
    1021 # define RTReqCallV                                     RT_MANGLER(RTReqCallV)
    1022 # define RTReqCallVoid                                  RT_MANGLER(RTReqCallVoid)
    1023 # define RTReqCreateQueue                               RT_MANGLER(RTReqCreateQueue)
    1024 # define RTReqDestroyQueue                              RT_MANGLER(RTReqDestroyQueue)
     1018# define RTReqQueueAlloc                                     RT_MANGLER(RTReqQueueAlloc)
     1019# define RTReqQueueCall                                      RT_MANGLER(RTReqQueueCall)
     1020# define RTReqQueueCallEx                                    RT_MANGLER(RTReqQueueCallEx)
     1021# define RTReqQueueCallV                                     RT_MANGLER(RTReqQueueCallV)
     1022# define RTReqQueueCallVoid                                  RT_MANGLER(RTReqQueueCallVoid)
     1023# define RTReqQueueCreate                               RT_MANGLER(RTReqQueueCreate)
     1024# define RTReqQueueDestroy                              RT_MANGLER(RTReqQueueDestroy)
    10251025# define RTReqFree                                      RT_MANGLER(RTReqFree)
    1026 # define RTReqIsBusy                                    RT_MANGLER(RTReqIsBusy)
    1027 # define RTReqProcess                                   RT_MANGLER(RTReqProcess)
    1028 # define RTReqQueue                                     RT_MANGLER(RTReqQueue)
     1026# define RTReqQueueIsBusy                                    RT_MANGLER(RTReqQueueIsBusy)
     1027# define RTReqQueueProcess                                   RT_MANGLER(RTReqQueueProcess)
     1028# define RTReqSubmit                                     RT_MANGLER(RTReqSubmit)
    10291029# define RTReqWait                                      RT_MANGLER(RTReqWait)
    10301030# define RTS3BucketsDestroy                             RT_MANGLER(RTS3BucketsDestroy)
  • trunk/include/iprt/req.h

    r33540 r39498  
    11/** @file
    2  * IPRT - Request packets
     2 * IPRT - Request Queue & Pool.
    33 */
    44
    55/*
    6  * Copyright (C) 2006-2007 Oracle Corporation
     6 * Copyright (C) 2006-2011 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3434RT_C_DECLS_BEGIN
    3535
    36 /** @defgroup grp_rt_req    RTReq - Request Packet Management
     36/** @defgroup grp_rt_req    RTReq - Request Queue & Pool.
    3737 * @ingroup grp_rt
    3838 * @{
    3939 */
     40
     41/** Request queue handle. */
     42typedef struct RTREQQUEUEINT *RTREQQUEUE;
     43/** Pointer to a request queue handle. */
     44typedef RTREQQUEUE *PRTREQQUEUE;
     45/** NIL request queue handle. */
     46#define NIL_RTREQQUEUE      ((RTREQQUEUE)0)
     47
     48/** Request thread pool handle. */
     49typedef struct RTREQPOOLINT *RTREQPOOL;
     50/** Poiner to a request thread pool handle. */
     51typedef RTREQPOOL *PRTREQPOOL;
     52/** NIL request pool handle. */
     53#define NIL_RTREQPOOL       ((RTREQPOOL)0)
     54
    4055
    4156/**
     
    86101} RTREQFLAGS;
    87102
    88 /** Pointer to a request queue. */
    89 typedef struct RTREQQUEUE *PRTREQQUEUE;
    90103
    91104/**
     
    99112    struct RTREQ * volatile pNext;
    100113    /** Pointer to the queue this packet belongs to. */
    101     PRTREQQUEUE             pQueue;
     114    RTREQQUEUE              hQueue;
    102115    /** Request state. */
    103116    volatile RTREQSTATE     enmState;
     
    133146typedef RTREQ *PRTREQ;
    134147
    135 /** @todo hide this */
    136 typedef 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     /** Set if busy (pending or processing requests). */
    151     bool volatile           fBusy;
    152 } RTREQQUEUE;
    153148
    154149#ifdef IN_RING3
     
    158153 *
    159154 * @returns iprt status code.
    160  * @param   ppQueue         Where to store the request queue pointer.
    161  */
    162 RTDECL(int) RTReqCreateQueue(PRTREQQUEUE *ppQueue);
    163 
     155 * @param   phQueue         Where to store the request queue handle.
     156 */
     157RTDECL(int) RTReqQueueCreate(PRTREQQUEUE phQueue);
    164158
    165159/**
     
    167161 *
    168162 * @returns iprt status code.
    169  * @param   pQueue          The request queue.
    170  */
    171 RTDECL(int) RTReqDestroyQueue(PRTREQQUEUE pQueue);
    172 
     163 * @param   hQueue          The request queue.
     164 */
     165RTDECL(int) RTReqQueueDestroy(RTREQQUEUE hQueue);
    173166
    174167/**
     
    178171 * @returns VERR_TIMEOUT if cMillies was reached without the packet being added.
    179172 *
    180  * @param   pQueue          The request queue.
     173 * @param   hQueue          The request queue.
    181174 * @param   cMillies        Number of milliseconds to wait for a pending request.
    182175 *                          Use RT_INDEFINITE_WAIT to only wait till one is added.
    183176 */
    184 RTDECL(int) RTReqProcess(PRTREQQUEUE pQueue, RTMSINTERVAL cMillies);
    185 
     177RTDECL(int) RTReqQueueProcess(RTREQQUEUE hQueue, RTMSINTERVAL cMillies);
    186178
    187179/**
     
    197189 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    198190 *
    199  * @param   pQueue          The request queue.
     191 * @param   hQueue          The request queue.
    200192 * @param   ppReq           Where to store the pointer to the request.
    201193 *                          This will be NULL or a valid request pointer not matter what happens.
     
    207199 * @param   ...             Function arguments.
    208200 *
    209  * @remarks See remarks on RTReqCallV.
    210  */
    211 RTDECL(int) RTReqCall(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
    212 
     201 * @remarks See remarks on RTReqQueueCallV.
     202 */
     203RTDECL(int) RTReqQueueCall(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
    213204
    214205/**
     
    224215 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    225216 *
    226  * @param   pQueue          The request queue.
     217 * @param   hQueue          The request queue.
    227218 * @param   ppReq           Where to store the pointer to the request.
    228219 *                          This will be NULL or a valid request pointer not matter what happens.
     
    234225 * @param   ...             Function arguments.
    235226 *
    236  * @remarks See remarks on RTReqCallV.
    237  */
    238 RTDECL(int) RTReqCallVoid(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
    239 
     227 * @remarks See remarks on RTReqQueueCallV.
     228 */
     229RTDECL(int) RTReqQueueCallVoid(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
    240230
    241231/**
     
    251241 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    252242 *
    253  * @param   pQueue          The request queue.
     243 * @param   hQueue          The request queue.
    254244 * @param   ppReq           Where to store the pointer to the request.
    255245 *                          This will be NULL or a valid request pointer not matter what happens, unless fFlags
     
    263253 * @param   ...             Function arguments.
    264254 *
    265  * @remarks See remarks on RTReqCallV.
    266  */
    267 RTDECL(int) RTReqCallEx(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
    268 
     255 * @remarks See remarks on RTReqQueueCallV.
     256 */
     257RTDECL(int) RTReqQueueCallEx(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
    269258
    270259/**
     
    280269 * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    281270 *
    282  * @param   pQueue          The request queue.
     271 * @param   hQueue          The request queue.
    283272 * @param   ppReq           Where to store the pointer to the request.
    284273 *                          This will be NULL or a valid request pointer not matter what happens, unless fFlags
     
    301290 *                Use (void *)NULL or (uintptr_t)0 instead of NULL.
    302291 */
    303 RTDECL(int) RTReqCallV(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
    304 
     292RTDECL(int) RTReqQueueCallV(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
     293
     294/**
     295 * Checks if the queue is busy or not.
     296 *
     297 * The caller is responsible for dealing with any concurrent submitts.
     298 *
     299 * @returns true if busy, false if idle.
     300 * @param   hQueue              The queue.
     301 */
     302RTDECL(bool) RTReqQueueIsBusy(RTREQQUEUE hQueue);
    305303
    306304/**
     
    312310 * @returns iprt status code.
    313311 *
    314  * @param   pQueue          The request queue.
     312 * @param   hQueue          The request queue.
    315313 * @param   ppReq           Where to store the pointer to the allocated packet.
    316314 * @param   enmType         Package type.
    317315 */
    318 RTDECL(int) RTReqAlloc(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTREQTYPE enmType);
     316RTDECL(int) RTReqQueueAlloc(RTREQQUEUE hQueue, PRTREQ *ppReq, RTREQTYPE enmType);
    319317
    320318
     
    333331 * Queue a request.
    334332 *
    335  * The quest must be allocated using RTReqAlloc() and contain
    336  * all the required data.
     333 * The quest must be allocated using RTReqQueueAlloc() or RTReqPoolAlloc() and
     334 * contain all the required data.
     335 *
    337336 * If it's desired to poll on the completion of the request set cMillies
    338337 * to 0 and use RTReqWait() to check for completion. In the other case
     
    348347 *                          wait till it's completed.
    349348 */
    350 RTDECL(int) RTReqQueue(PRTREQ pReq, RTMSINTERVAL cMillies);
     349RTDECL(int) RTReqSubmit(PRTREQ pReq, RTMSINTERVAL cMillies);
    351350
    352351
     
    364363RTDECL(int) RTReqWait(PRTREQ pReq, RTMSINTERVAL cMillies);
    365364
    366 /**
    367  * Checks if the queue is busy or not.
    368  *
    369  * The caller is responsible for dealing with any concurrent submitts.
    370  *
    371  * @returns true if busy, false if idle.
    372  * @param   pQueue              The queue.
    373  */
    374 RTDECL(bool) RTReqIsBusy(PRTREQQUEUE pQueue);
    375365
    376366#endif /* IN_RING3 */
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r39465 r39498  
    154154    PPDMTHREAD              pSlirpThread;
    155155    /** Queue for NAT-thread-external events. */
    156     PRTREQQUEUE             pSlirpReqQueue;
     156    RTREQQUEUE              hSlirpReqQueue;
    157157    /** The guest IP for port-forwarding. */
    158158    uint32_t                GuestIP;
     
    185185    RTSEMEVENT              EventUrgRecv;
    186186    /** Receive Req queue (deliver packets to the guest) */
    187     PRTREQQUEUE             pRecvReqQueue;
     187    RTREQQUEUE              hRecvReqQueue;
    188188    /** Receive Urgent Req queue (deliver packets to the guest). */
    189     PRTREQQUEUE             pUrgRecvReqQueue;
     189    RTREQQUEUE              hUrgRecvReqQueue;
    190190
    191191    /** makes access to device func RecvAvail and Recv atomical. */
     
    219219    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    220220    {
    221         RTReqProcess(pThis->pRecvReqQueue, 0);
     221        RTReqQueueProcess(pThis->hRecvReqQueue, 0);
    222222        if (ASMAtomicReadU32(&pThis->cPkts) == 0)
    223223            RTSemEventWait(pThis->EventRecv, RT_INDEFINITE_WAIT);
     
    246246    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    247247    {
    248         RTReqProcess(pThis->pUrgRecvReqQueue, 0);
     248        RTReqQueueProcess(pThis->hUrgRecvReqQueue, 0);
    249249        if (ASMAtomicReadU32(&pThis->cUrgPkts) == 0)
    250250        {
     
    535535
    536536#ifdef VBOX_WITH_SLIRP_MT
    537         PRTREQQUEUE pQueue = (PRTREQQUEUE)slirp_get_queue(pThis->pNATState);
     537        RTREQQUEUE hQueue = (RTREQQUEUE)slirp_get_queue(pThis->pNATState);
    538538#else
    539         PRTREQQUEUE pQueue = pThis->pSlirpReqQueue;
     539        RTREQQUEUE hQueue = pThis->hSlirpReqQueue;
    540540#endif
    541         rc = RTReqCallEx(pQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    542                          (PFNRT)drvNATSendWorker, 2, pThis, pSgBuf);
     541        rc = RTReqQueueCallEx(hQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     542                              (PFNRT)drvNATSendWorker, 2, pThis, pSgBuf);
    543543        if (RT_SUCCESS(rc))
    544544        {
     
    637637
    638638    PRTREQ pReq;
    639     int rc = RTReqCallEx(pThis->pSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
    640                          (PFNRT)drvNATNotifyLinkChangedWorker, 2, pThis, enmLinkState);
     639    int rc = RTReqQueueCallEx(pThis->hSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
     640                              (PFNRT)drvNATNotifyLinkChangedWorker, 2, pThis, enmLinkState);
    641641    if (RT_LIKELY(rc == VERR_TIMEOUT))
    642642    {
     
    684684    PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkNATCfg);
    685685    PRTREQ pReq;
    686     int rc = RTReqCallEx(pThis->pSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
    687                          (PFNRT)drvNATNotifyApplyPortForwardCommand, 7, pThis, fRemove,
    688                          fUdp, pHostIp, u16HostPort, pGuestIp, u16GuestPort);
     686    int rc = RTReqQueueCallEx(pThis->hSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
     687                              (PFNRT)drvNATNotifyApplyPortForwardCommand, 7, pThis, fRemove,
     688                              fUdp, pHostIp, u16HostPort, pGuestIp, u16GuestPort);
    689689    if (RT_LIKELY(rc == VERR_TIMEOUT))
    690690    {
     
    707707 * dedicated thread. We take care that this thread does not become the
    708708 * bottleneck: If the guest wants to send, a request is enqueued into the
    709  * pSlirpReqQueue and handled asynchronously by this thread.  If this thread
     709 * hSlirpReqQueue and handled asynchronously by this thread.  If this thread
    710710 * wants to deliver packets to the guest, it enqueues a request into
    711  * pRecvReqQueue which is later handled by the Recv thread.
     711 * hRecvReqQueue which is later handled by the Recv thread.
    712712 */
    713713static DECLCALLBACK(int) drvNATAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
     
    792792        }
    793793        /* process _all_ outstanding requests but don't wait */
    794         RTReqProcess(pThis->pSlirpReqQueue, 0);
     794        RTReqQueueProcess(pThis->hSlirpReqQueue, 0);
    795795        RTMemFree(polls);
    796796
     
    819819        slirp_select_poll(pThis->pNATState, /* fTimeout=*/false, /* fIcmp=*/(dwEvent == WSA_WAIT_EVENT_0));
    820820        /* process _all_ outstanding requests but don't wait */
    821         RTReqProcess(pThis->pSlirpReqQueue, 0);
     821        RTReqQueueProcess(pThis->hSlirpReqQueue, 0);
    822822# ifdef VBOX_NAT_DELAY_HACK
    823823        if (cBreak++ > 128)
     
    903903
    904904    ASMAtomicIncU32(&pThis->cUrgPkts);
    905     int rc = RTReqCallEx(pThis->pUrgRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    906                          (PFNRT)drvNATUrgRecvWorker, 4, pThis, pu8Buf, cb, m);
     905    int rc = RTReqQueueCallEx(pThis->hUrgRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     906                              (PFNRT)drvNATUrgRecvWorker, 4, pThis, pu8Buf, cb, m);
    907907    AssertRC(rc);
    908908    drvNATUrgRecvWakeup(pThis->pDrvIns, pThis->pUrgRecvThread);
     
    937937
    938938    ASMAtomicIncU32(&pThis->cPkts);
    939     int rc = RTReqCallEx(pThis->pRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    940                          (PFNRT)drvNATRecvWorker, 4, pThis, pu8Buf, cb, m);
     939    int rc = RTReqQueueCallEx(pThis->hRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     940                              (PFNRT)drvNATRecvWorker, 4, pThis, pu8Buf, cb, m);
    941941    AssertRC(rc);
    942942    drvNATRecvWakeup(pThis->pDrvIns, pThis->pRecvThread);
     
    11191119    }
    11201120
    1121     RTReqDestroyQueue(pThis->pSlirpReqQueue);
    1122     pThis->pSlirpReqQueue = NULL;
    1123 
    1124     RTReqDestroyQueue(pThis->pUrgRecvReqQueue);
    1125     pThis->pUrgRecvReqQueue = NULL;
     1121    RTReqQueueDestroy(pThis->hSlirpReqQueue);
     1122    pThis->hSlirpReqQueue = NIL_RTREQQUEUE;
     1123
     1124    RTReqQueueDestroy(pThis->hUrgRecvReqQueue);
     1125    pThis->hUrgRecvReqQueue = NIL_RTREQQUEUE;
    11261126
    11271127    RTSemEventDestroy(pThis->EventRecv);
     
    11721172    pThis->pszBootFile                  = NULL;
    11731173    pThis->pszNextServer                = NULL;
    1174     pThis->pSlirpReqQueue               = NULL;
    1175     pThis->pUrgRecvReqQueue             = NULL;
     1174    pThis->hSlirpReqQueue               = NIL_RTREQQUEUE;
     1175    pThis->hUrgRecvReqQueue             = NIL_RTREQQUEUE;
    11761176    pThis->EventRecv                    = NIL_RTSEMEVENT;
    11771177    pThis->EventUrgRecv                 = NIL_RTSEMEVENT;
     
    13011301             */
    13021302            rc = PDMDrvHlpSSMRegisterLoadDone(pDrvIns, drvNATLoadDone);
    1303             AssertRCReturn(rc, rc);
    1304 
    1305             rc = RTReqCreateQueue(&pThis->pSlirpReqQueue);
    1306             if (RT_FAILURE(rc))
    1307             {
    1308                 LogRel(("NAT: Can't create request queue\n"));
    1309                 return rc;
    1310             }
    1311 
    1312             rc = RTReqCreateQueue(&pThis->pRecvReqQueue);
    1313             if (RT_FAILURE(rc))
    1314             {
    1315                 LogRel(("NAT: Can't create request queue\n"));
    1316                 return rc;
    1317             }
    1318 
    1319             rc = RTReqCreateQueue(&pThis->pUrgRecvReqQueue);
    1320             if (RT_FAILURE(rc))
    1321             {
    1322                 LogRel(("NAT: Can't create request queue\n"));
    1323                 return rc;
    1324             }
     1303            AssertLogRelRCReturn(rc, rc);
     1304
     1305            rc = RTReqQueueCreate(&pThis->hSlirpReqQueue);
     1306            AssertLogRelRCReturn(rc, rc);
     1307
     1308            rc = RTReqQueueCreate(&pThis->hRecvReqQueue);
     1309            AssertLogRelRCReturn(rc, rc);
     1310
     1311            rc = RTReqQueueCreate(&pThis->hUrgRecvReqQueue);
     1312            AssertLogRelRCReturn(rc, rc);
    13251313
    13261314            rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pRecvThread, pThis, drvNATRecv,
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r39471 r39498  
    622622    QSOCKET_LOCK_CREATE(tcb);
    623623    QSOCKET_LOCK_CREATE(udb);
    624     rc = RTReqCreateQueue(&pData->pReqQueue);
     624    rc = RTReqQueueCreate(&pData->pReqQueue);
    625625    AssertReleaseRC(rc);
    626626#endif
     
    19501950void slirp_process_queue(PNATState pData)
    19511951{
    1952      RTReqProcess(pData->pReqQueue, RT_INDEFINITE_WAIT);
     1952     RTReqQueueProcess(pData->pReqQueue, RT_INDEFINITE_WAIT);
    19531953}
    19541954void *slirp_get_queue(PNATState pData)
  • trunk/src/VBox/Devices/Network/slirp/slirp_state.h

    r39287 r39498  
    136136    int soMaxConn;
    137137#ifdef VBOX_WITH_SLIRP_MT
    138     PRTREQQUEUE pReqQueue;
     138    RTREQQUEUE hReqQueue;
    139139#endif
    140140#ifdef RT_OS_WINDOWS
     
    474474        PRTREQ pReq;                                                    \
    475475        int rc;                                                         \
    476         rc = RTReqCallVoid((data)->pReqQueue, &pReq, 0 /*cMillies*/,    \
    477                            (PFNRT)tcp_output 2, data, sotcb);           \
     476        rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \
     477                                (PFNRT)tcp_output 2, data, sotcb);      \
    478478        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    479479        {                                                               \
     
    491491    do {                                                                \
    492492        int rc;                                                         \
    493         rc = RTReqCallEx((data)->pReqQueue, NULL, 0 /*cMillies*/,       \
    494                          RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,          \
    495                          (PFNRT)tcp_input, 4, data, mbuf, size, so);    \
     493        rc = RTReqQueueCallEx((data)->hReqQueue, NULL, 0 /*cMillies*/,  \
     494                              RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,     \
     495                              (PFNRT)tcp_input, 4, data, mbuf, size, so); \
    496496        AssertReleaseRC(rc);                                            \
    497497    } while(0)
     
    501501        PRTREQ pReq;                                                    \
    502502        int rc;                                                         \
    503         rc = RTReqCallVoid((data)->pReqQueue, &pReq, 0 /*cMillies*/,    \
    504                            (PFNRT)tcp_connect, 2, data, so);            \
     503        rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \
     504                                (PFNRT)tcp_connect, 2, data, so);       \
    505505        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    506506        {                                                               \
     
    519519        PRTREQ pReq;                                                    \
    520520        int rc;                                                         \
    521         rc = RTReqCallVoid((data)->pReqQueue, &pReq, 0 /*cMillies*/,    \
    522                            (PFNRT)soread_queue, 4,                      \
    523                            data, so, ifclose, &(ret));                  \
     521        rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies*/, \
     522                                (PFNRT)soread_queue, 4,                 \
     523                                data, so, ifclose, &(ret));             \
    524524        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    525525        {                                                               \
     
    538538        PRTREQ pReq;                                                    \
    539539        int rc;                                                         \
    540         rc = RTReqCall((data)->pReqQueue, &pReq, 0 /*cMillies*/,        \
    541                        (PFNRT)sowrite, 2, data, so);                    \
     540        rc = RTReqQueueCall((data)->hReqQueue, &pReq, 0 /*cMillies*/,   \
     541                            (PFNRT)sowrite, 2, data, so);               \
    542542        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    543543        {                                                               \
     
    556556        PRTREQ pReq;                                                    \
    557557        int rc;                                                         \
    558         rc = RTReqCallVoid((data)->pReqQueue, &pReq, 0 /*cMillies */,  \
    559                            (PFNRT)sorecvfrom, 2, data, so);             \
     558        rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /*cMillies */, \
     559                                (PFNRT)sorecvfrom, 2, data, so);        \
    560560        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    561561        {                                                               \
     
    574574        PRTREQ pReq;                                                    \
    575575        int rc;                                                         \
    576         rc = RTReqCallVoid((data)->pReqQueue, &pReq, 0 /* cMillies*/,  \
    577                            (PFNRT)udp_detach, 2, data, so);             \
     576        rc = RTReqQueueCallVoid((data)->hReqQueue, &pReq, 0 /* cMillies*/, \
     577                                (PFNRT)udp_detach, 2, data, so);        \
    578578        if (RT_LIKELY(rc == VERR_TIMEOUT))                              \
    579579        {                                                               \
  • trunk/src/VBox/Devices/Storage/DrvSCSI.cpp

    r38878 r39498  
    9191    PPDMTHREAD              pAsyncIOThread;
    9292    /** Queue for passing the requests to the thread. */
    93     PRTREQQUEUE             pQueueRequests;
     93    RTREQQUEUE              hQueueRequests;
    9494    /** Request that we've left pending on wakeup or reset. */
    9595    PRTREQ                  pPendingDummyReq;
     
    398398    {
    399399        /* I/O thread. */
    400         rc = RTReqCallEx(pThis->pQueueRequests, NULL, 0, RTREQFLAGS_NO_WAIT,
    401                          (PFNRT)drvscsiProcessRequestOne, 2, pThis, hVScsiIoReq);
     400        rc = RTReqQueueCallEx(pThis->hQueueRequests, NULL, 0, RTREQFLAGS_NO_WAIT,
     401                              (PFNRT)drvscsiProcessRequestOne, 2, pThis, hVScsiIoReq);
    402402    }
    403403
     
    486486    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    487487    {
    488         rc = RTReqProcess(pThis->pQueueRequests, RT_INDEFINITE_WAIT);
     488        rc = RTReqQueueProcess(pThis->hQueueRequests, RT_INDEFINITE_WAIT);
    489489        AssertMsg(rc == VWRN_STATE_CHANGED, ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n", rc));
    490490    }
     
    519519    int rc;
    520520
    521     AssertMsgReturn(pThis->pQueueRequests, ("pQueueRequests is NULL\n"), VERR_INVALID_STATE);
     521    AssertMsgReturn(pThis->hQueueRequests != NIL_RTREQQUEUE, ("hQueueRequests is NULL\n"), VERR_INVALID_STATE);
    522522
    523523    if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 10000 /* 10 sec */))
     
    527527    }
    528528
    529     rc = RTReqCall(pThis->pQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsiAsyncIOLoopWakeupFunc, 1, pThis);
     529    rc = RTReqQueueCall(pThis->hQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsiAsyncIOLoopWakeupFunc, 1, pThis);
    530530    if (RT_SUCCESS(rc))
    531531        RTReqFree(pReq);
     
    634634    if (!pThis->pDrvBlockAsync)
    635635    {
    636         if (!pThis->pQueueRequests)
     636        if (pThis->hQueueRequests != NIL_RTREQQUEUE)
    637637            return;
    638638
     
    640640        if (drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
    641641        {
    642             if (!RTReqIsBusy(pThis->pQueueRequests))
     642            if (!RTReqQueueIsBusy(pThis->hQueueRequests))
    643643            {
    644644                ASMAtomicWriteBool(&pThis->fDummySignal, false);
     
    647647
    648648            PRTREQ pReq;
    649             int rc = RTReqCall(pThis->pQueueRequests, &pReq, 0 /*ms*/, (PFNRT)drvscsiAsyncIOLoopSyncCallback, 1, pThis);
     649            int rc = RTReqQueueCall(pThis->hQueueRequests, &pReq, 0 /*ms*/, (PFNRT)drvscsiAsyncIOLoopSyncCallback, 1, pThis);
    650650            if (RT_SUCCESS(rc))
    651651            {
     
    760760    PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
    761761
    762     if (pThis->pQueueRequests)
     762    if (pThis->hQueueRequests != NIL_RTREQQUEUE)
    763763    {
    764764        if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 100 /*ms*/))
    765765            LogRel(("drvscsiDestruct#%u: previous dummy request is still pending\n", pDrvIns->iInstance));
    766766
    767         int rc = RTReqDestroyQueue(pThis->pQueueRequests);
     767        int rc = RTReqQueueDestroy(pThis->hQueueRequests);
    768768        AssertMsgRC(rc, ("Failed to destroy queue rc=%Rrc\n", rc));
     769        pThis->hQueueRequests = NIL_RTREQQUEUE;
    769770    }
    770771
     
    792793    LogFlowFunc(("pDrvIns=%#p pCfg=%#p\n", pDrvIns, pCfg));
    793794    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
     795
     796    /*
     797     * Initialize the instance data.
     798     */
     799    pThis->pDrvIns                              = pDrvIns;
     800    pThis->ISCSIConnector.pfnSCSIRequestSend    = drvscsiRequestSend;
     801
     802    pDrvIns->IBase.pfnQueryInterface            = drvscsiQueryInterface;
     803
     804    pThis->IPort.pfnQueryDeviceLocation         = drvscsiQueryDeviceLocation;
     805    pThis->IPortAsync.pfnTransferCompleteNotify = drvscsiTransferCompleteNotify;
     806    pThis->hQueueRequests                       = NIL_RTREQQUEUE;
     807
     808    /* Query the SCSI port interface above. */
     809    pThis->pDevScsiPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISCSIPORT);
     810    AssertMsgReturn(pThis->pDevScsiPort, ("Missing SCSI port interface above\n"), VERR_PDM_MISSING_INTERFACE);
     811
     812    /* Query the optional LED interface above. */
     813    pThis->pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
     814    if (pThis->pLedPort != NULL)
     815    {
     816        /* Get The Led. */
     817        rc = pThis->pLedPort->pfnQueryStatusLed(pThis->pLedPort, 0, &pThis->pLed);
     818        if (RT_FAILURE(rc))
     819            pThis->pLed = &pThis->Led;
     820    }
     821    else
     822        pThis->pLed = &pThis->Led;
    794823
    795824    /*
     
    804833        return PDMDRV_SET_ERROR(pDrvIns, rc,
    805834                    N_("SCSI configuration error: failed to read \"NonRotationalMedium\" as boolean"));
    806 
    807     /*
    808      * Initialize the instance data.
    809      */
    810     pThis->pDrvIns                           = pDrvIns;
    811     pThis->ISCSIConnector.pfnSCSIRequestSend = drvscsiRequestSend;
    812 
    813     pDrvIns->IBase.pfnQueryInterface         = drvscsiQueryInterface;
    814 
    815     pThis->IPort.pfnQueryDeviceLocation         = drvscsiQueryDeviceLocation;
    816     pThis->IPortAsync.pfnTransferCompleteNotify = drvscsiTransferCompleteNotify;
    817 
    818     /* Query the SCSI port interface above. */
    819     pThis->pDevScsiPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISCSIPORT);
    820     AssertMsgReturn(pThis->pDevScsiPort, ("Missing SCSI port interface above\n"), VERR_PDM_MISSING_INTERFACE);
    821 
    822     /* Query the optional LED interface above. */
    823     pThis->pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
    824     if (pThis->pLedPort != NULL)
    825     {
    826         /* Get The Led. */
    827         rc = pThis->pLedPort->pfnQueryStatusLed(pThis->pLedPort, 0, &pThis->pLed);
    828         if (RT_FAILURE(rc))
    829             pThis->pLed = &pThis->Led;
    830     }
    831     else
    832         pThis->pLed = &pThis->Led;
    833835
    834836    /*
     
    895897    {
    896898        /* Create request queue. */
    897         rc = RTReqCreateQueue(&pThis->pQueueRequests);
     899        rc = RTReqQueueCreate(&pThis->hQueueRequests);
    898900        AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create request queue rc=%Rrc\n"), rc);
    899901        /* Create I/O thread. */
  • trunk/src/VBox/Devices/Storage/DrvSCSIHost.cpp

    r37596 r39498  
    6363    PPDMTHREAD              pAsyncIOThread;
    6464    /** Queue for passing the requests to the thread. */
    65     PRTREQQUEUE             pQueueRequests;
     65    RTREQQUEUE              hQueueRequests;
    6666} DRVSCSIHOST, *PDRVSCSIHOST;
    6767
     
    352352    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    353353    {
    354         rc = RTReqProcess(pThis->pQueueRequests, RT_INDEFINITE_WAIT);
     354        rc = RTReqQueueProcess(pThis->hQueueRequests, RT_INDEFINITE_WAIT);
    355355        AssertMsg(rc == VWRN_STATE_CHANGED, ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n", rc));
    356356    }
     
    365365    PRTREQ pReq;
    366366
    367     AssertMsgReturn(pThis->pQueueRequests, ("pQueueRequests is NULL\n"), VERR_INVALID_STATE);
    368 
    369     rc = RTReqCall(pThis->pQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsihostAsyncIOLoopWakeupFunc, 0);
     367    AssertReturn(pThis->hQueueRequests != NIL_RTREQQUEUE, VERR_INVALID_STATE);
     368
     369    rc = RTReqQueueCall(pThis->hQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsihostAsyncIOLoopWakeupFunc, 0);
    370370    AssertMsgRC(rc, ("Inserting request into queue failed rc=%Rrc\n"));
    371371
     
    382382    PRTREQ pReq;
    383383
    384     AssertMsgReturn(pThis->pQueueRequests, ("pQueueRequests is NULL\n"), VERR_INVALID_STATE);
    385 
    386     rc = RTReqCallEx(pThis->pQueueRequests, &pReq, 0, RTREQFLAGS_NO_WAIT, (PFNRT)drvscsihostProcessRequestOne, 2, pThis, pSCSIRequest);
     384    AssertReturn(pThis->hQueueRequests != NIL_RTREQQUEUE, VERR_INVALID_STATE);
     385
     386    rc = RTReqQueueCallEx(pThis->hQueueRequests, &pReq, 0, RTREQFLAGS_NO_WAIT, (PFNRT)drvscsihostProcessRequestOne, 2, pThis, pSCSIRequest);
    387387    AssertMsgReturn(RT_SUCCESS(rc), ("Inserting request into queue failed rc=%Rrc\n", rc), rc);
    388388
     
    429429    }
    430430
    431     if (pThis->pQueueRequests)
    432     {
    433         int rc = RTReqDestroyQueue(pThis->pQueueRequests);
     431    if (pThis->hQueueRequests != NIL_RTREQQUEUE)
     432    {
     433        int rc = RTReqQueueDestroy(pThis->hQueueRequests);
    434434        AssertMsgRC(rc, ("Failed to destroy queue rc=%Rrc\n", rc));
     435        pThis->hQueueRequests = NIL_RTREQQUEUE;
    435436    }
    436437
     
    447448    LogFlowFunc(("pDrvIns=%#p pCfg=%#p\n", pDrvIns, pCfg));
    448449    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
     450
     451    /*
     452     * Initialize the instance data first because of the destructor.
     453     */
     454    pDrvIns->IBase.pfnQueryInterface            = drvscsihostQueryInterface;
     455    pThis->ISCSIConnector.pfnSCSIRequestSend    = drvscsihostRequestSend;
     456    pThis->pDrvIns                              = pDrvIns;
     457    pThis->hDeviceFile                          = NIL_RTFILE;
     458    pThis->hQueueRequests                       = NIL_RTREQQUEUE;
    449459
    450460    /*
     
    455465                                N_("Invalid configuration for host scsi access driver"));
    456466
    457     /*
    458      * Initialize interfaces.
    459      */
    460     pDrvIns->IBase.pfnQueryInterface                    = drvscsihostQueryInterface;
    461     pThis->ISCSIConnector.pfnSCSIRequestSend            = drvscsihostRequestSend;
    462     pThis->pDrvIns     = pDrvIns;
    463     pThis->hDeviceFile = NIL_RTFILE;
    464467
    465468    /* Query the SCSI port interface above. */
     
    468471
    469472    /* Create request queue. */
    470     int rc = RTReqCreateQueue(&pThis->pQueueRequests);
     473    int rc = RTReqQueueCreate(&pThis->hQueueRequests);
    471474    AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create request queue rc=%Rrc\n"), rc);
    472475
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetNAT.cpp

    r39468 r39498  
    101101    RTSEMEVENT              m_EventUrgSend;
    102102
    103     PRTREQQUEUE             m_pReqQueue;
    104     PRTREQQUEUE             m_pSendQueue;
    105     PRTREQQUEUE             m_pUrgSendQueue;
     103    RTREQQUEUE              m_hReqQueue;
     104    RTREQQUEUE              m_hSendQueue;
     105    RTREQQUEUE              m_hUrgSendQueue;
    106106    volatile uint32_t       cUrgPkt;
    107107    volatile uint32_t       cPkt;
     
    186186    slirp_register_external_event(m_pNATState, m_hWakeupEvent, VBOX_WAKEUP_EVENT_INDEX);
    187187#endif
    188     rc = RTReqCreateQueue(&m_pReqQueue);
    189     AssertReleaseRC(rc);
    190 
    191     rc = RTReqCreateQueue(&m_pSendQueue);
    192     AssertReleaseRC(rc);
    193 
    194     rc = RTReqCreateQueue(&m_pUrgSendQueue);
     188    rc = RTReqQueueCreate(&m_hReqQueue);
     189    AssertReleaseRC(rc);
     190
     191    rc = RTReqQueueCreate(&m_hSendQueue);
     192    AssertReleaseRC(rc);
     193
     194    rc = RTReqQueueCreate(&m_hUrgSendQueue);
    195195    AssertReleaseRC(rc);
    196196
     
    226226        WaitReq.cMillies = 2000; /* 2 secs - the sleep is for some reason uninterruptible... */  /** @todo fix interruptability in SrvIntNet! */
    227227#if 0
    228         RTReqProcess(m_pSendQueue, 0);
    229         RTReqProcess(m_pUrgSendQueue, 0);
     228        RTReqProcess(m_hSendQueue, 0);
     229        RTReqProcess(m_hUrgSendQueue, 0);
    230230#endif
    231231        int rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, VMMR0_DO_INTNET_IF_WAIT, 0, &WaitReq.Hdr);
     
    267267
    268268                    /* don't wait, we may have to wakeup the NAT thread first */
    269                     rc = RTReqCallEx(m_pReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    270                                      (PFNRT)SendWorker, 2, m, cbFrame);
     269                    rc = RTReqQueueCallEx(m_hReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     270                                          (PFNRT)SendWorker, 2, m, cbFrame);
    271271                    natNotifyNATThread();
    272272                    AssertReleaseRC(rc);
     
    301301                        memcpy(pvSlirpFrame, pvSegFrame, cbSegFrame);
    302302
    303                         rc = RTReqCallEx(m_pReqQueue, NULL /*ppReq*/, 0 /*cMillies*/,
    304                                          RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    305                                          (PFNRT)SendWorker, 2, m, cbSegFrame);
     303                        rc = RTReqQueueCallEx(m_hReqQueue, NULL /*ppReq*/, 0 /*cMillies*/,
     304                                              RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     305                                              (PFNRT)SendWorker, 2, m, cbSegFrame);
    306306                        AssertReleaseRC(rc);
    307307                    }
     
    357357{
    358358    LogFlowFunc(("ENTER: m:%p, pu8Buf:%p, cb:%d\n", m, pu8Buf, cb));
    359     int rc = RTReqCallEx(g_pNAT->m_pUrgSendQueue,  NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    360                          (PFNRT)IntNetSendWorker, 4, (uintptr_t)1, (uintptr_t)pu8Buf, (uintptr_t)cb, (uintptr_t)m);
     359    int rc = RTReqQueueCallEx(g_pNAT->m_hUrgSendQueue,  NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     360                              (PFNRT)IntNetSendWorker, 4, (uintptr_t)1, (uintptr_t)pu8Buf, (uintptr_t)cb, (uintptr_t)m);
    361361    ASMAtomicIncU32(&g_pNAT->cUrgPkt);
    362362    RTSemEventSignal(g_pNAT->m_EventUrgSend);
     
    368368    LogFlowFunc(("ENTER: m:%p, pu8Buf:%p, cb:%d\n", m, pu8Buf, cb));
    369369    AssertRelease(g_pNAT == pvUser);
    370     int rc = RTReqCallEx(g_pNAT->m_pSendQueue,  NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    371                          (PFNRT)IntNetSendWorker, 4, (uintptr_t)0, (uintptr_t)pu8Buf, (uintptr_t)cb, (uintptr_t)m);
     370    int rc = RTReqQueueCallEx(g_pNAT->m_hSendQueue,  NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     371                              (PFNRT)IntNetSendWorker, 4, (uintptr_t)0, (uintptr_t)pu8Buf, (uintptr_t)cb, (uintptr_t)m);
    372372    ASMAtomicIncU32(&g_pNAT->cPkt);
    373373    RTSemEventSignal(g_pNAT->m_EventSend);
     
    524524        }
    525525        /* process _all_ outstanding requests but don't wait */
    526         RTReqProcess(pThis->m_pReqQueue, 0);
     526        RTReqQueueProcess(pThis->m_hReqQueue, 0);
    527527        RTMemFree(polls);
    528528
     
    551551        slirp_select_poll(pThis->m_pNATState, /* fTimeout=*/false, /* fIcmp=*/(dwEvent == WSA_WAIT_EVENT_0));
    552552        /* process _all_ outstanding requests but don't wait */
    553         RTReqProcess(pThis->m_pReqQueue, 0);
     553        RTReqQueueProcess(pThis->m_hReqQueue, 0);
    554554#endif /* RT_OS_WINDOWS */
    555555    }
     
    561561{
    562562    while (g_pNAT->fIsRunning)
    563         RTReqProcess(g_pNAT->m_pSendQueue, 0);
     563        RTReqQueueProcess(g_pNAT->m_hSendQueue, 0);
    564564    return VINF_SUCCESS;
    565565}
     
    567567{
    568568    while (g_pNAT->fIsRunning)
    569         RTReqProcess(g_pNAT->m_pUrgSendQueue, 0);
     569        RTReqQueueProcess(g_pNAT->m_hUrgSendQueue, 0);
    570570    return VINF_SUCCESS;
    571571}
  • trunk/src/VBox/Runtime/common/misc/req.cpp

    r39032 r39498  
    4141#include <iprt/mem.h>
    4242
     43#include "internal/req.h"
     44
    4345
    4446/*******************************************************************************
     
    4951
    5052
    51 /**
    52  * Create a request packet queue
    53  *
    54  * @returns iprt status code.
    55  * @param   ppQueue         Where to store the request queue pointer.
    56  */
    57 RTDECL(int) RTReqCreateQueue(PRTREQQUEUE *ppQueue)
    58 {
    59     PRTREQQUEUE pQueue = (PRTREQQUEUE)RTMemAllocZ(sizeof(RTREQQUEUE));
     53RTDECL(int) RTReqQueueCreate(RTREQQUEUE *phQueue)
     54{
     55    PRTREQQUEUEINT pQueue = (PRTREQQUEUEINT)RTMemAllocZ(sizeof(RTREQQUEUEINT));
    6056    if (!pQueue)
    6157        return VERR_NO_MEMORY;
     
    6359    if (RT_SUCCESS(rc))
    6460    {
    65         *ppQueue = pQueue;
     61        *phQueue = pQueue;
    6662        return VINF_SUCCESS;
    6763    }
     
    7066    return rc;
    7167}
    72 RT_EXPORT_SYMBOL(RTReqCreateQueue);
    73 
    74 
    75 /**
    76  * Destroy a request packet queue
    77  *
    78  * @returns iprt status code.
    79  * @param   pQueue          The request queue.
    80  */
    81 RTDECL(int) RTReqDestroyQueue(PRTREQQUEUE pQueue)
     68RT_EXPORT_SYMBOL(RTReqQueueCreate);
     69
     70
     71RTDECL(int) RTReqQueueDestroy(RTREQQUEUE hQueue)
    8272{
    8373    /*
    8474     * Check input.
    8575     */
    86     if (!pQueue)
     76    if (hQueue == NIL_RTREQQUEUE)
    8777        return VINF_SUCCESS;
    88     AssertPtr(pQueue);
     78    PRTREQQUEUEINT pQueue = hQueue;
     79    AssertPtrReturn(pQueue, VERR_INVALID_HANDLE);
     80
    8981    RTSemEventDestroy(pQueue->EventSem);
    9082    pQueue->EventSem = NIL_RTSEMEVENT;
     
    9284    return VINF_SUCCESS;
    9385}
    94 RT_EXPORT_SYMBOL(RTReqDestroyQueue);
    95 
    96 
    97 /**
    98  * Process one or more request packets
    99  *
    100  * @returns iprt status code.
    101  * @returns VERR_TIMEOUT if cMillies was reached without the packet being added.
    102  *
    103  * @param   pQueue          The request queue.
    104  * @param   cMillies        Number of milliseconds to wait for a pending request.
    105  *                          Use RT_INDEFINITE_WAIT to only wait till one is added.
    106  */
    107 RTDECL(int) RTReqProcess(PRTREQQUEUE pQueue, RTMSINTERVAL cMillies)
    108 {
    109     LogFlow(("RTReqProcess %x\n", pQueue));
     86RT_EXPORT_SYMBOL(RTReqQueueDestroy);
     87
     88
     89RTDECL(int) RTReqQueueProcess(RTREQQUEUE hQueue, RTMSINTERVAL cMillies)
     90{
     91    LogFlow(("RTReqProcess %x\n", hQueue));
     92
    11093    /*
    11194     * Check input.
    11295     */
    113     if (!pQueue)
    114     {
    115         AssertFailed();
    116         return VERR_INVALID_PARAMETER;
    117     }
     96    PRTREQQUEUEINT pQueue = hQueue;
     97    AssertPtrReturn(pQueue, VERR_INVALID_HANDLE);
    11898
    11999    /*
     
    152132        {
    153133            Assert(pReq->enmState == RTREQSTATE_QUEUED);
    154             Assert(pReq->pQueue == pQueue);
     134            Assert(pReq->hQueue == pQueue);
    155135            PRTREQ pCur = pReq;
    156136            pReq = pReq->pNext;
     
    181161    return rc;
    182162}
    183 RT_EXPORT_SYMBOL(RTReqProcess);
    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 completion. 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 happens.
    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  * @param   ...             Function arguments.
    206  *
    207  * @remarks See remarks on RTReqCallV.
    208  */
    209 RTDECL(int) RTReqCall(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
     163RT_EXPORT_SYMBOL(RTReqQueueProcess);
     164
     165
     166RTDECL(int) RTReqQueueCall(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
    210167{
    211168    va_list va;
    212169    va_start(va, cArgs);
    213     int rc = RTReqCallV(pQueue, ppReq, cMillies, RTREQFLAGS_IPRT_STATUS, pfnFunction, cArgs, va);
     170    int rc = RTReqQueueCallV(hQueue, ppReq, cMillies, RTREQFLAGS_IPRT_STATUS, pfnFunction, cArgs, va);
    214171    va_end(va);
    215172    return rc;
    216173}
    217 RT_EXPORT_SYMBOL(RTReqCall);
    218 
    219 
    220 /**
    221  * Allocate and queue a call request to a void function.
    222  *
    223  * If it's desired to poll on the completion of the request set cMillies
    224  * to 0 and use RTReqWait() to check for completion. In the other case
    225  * use RT_INDEFINITE_WAIT.
    226  * The returned request packet must be freed using RTReqFree().
    227  *
    228  * @returns iprt status code.
    229  *          Will not return VERR_INTERRUPTED.
    230  * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    231  *
    232  * @param   pQueue          The request queue.
    233  * @param   ppReq           Where to store the pointer to the request.
    234  *                          This will be NULL or a valid request pointer not matter what happens.
    235  * @param   cMillies        Number of milliseconds to wait for the request to
    236  *                          be completed. Use RT_INDEFINITE_WAIT to only
    237  *                          wait till it's completed.
    238  * @param   pfnFunction     Pointer to the function to call.
    239  * @param   cArgs           Number of arguments following in the ellipsis.
    240  * @param   ...             Function arguments.
    241  *
    242  * @remarks See remarks on RTReqCallV.
    243  */
    244 RTDECL(int) RTReqCallVoid(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
     174RT_EXPORT_SYMBOL(RTReqQueueCall);
     175
     176
     177RTDECL(int) RTReqQueueCallVoid(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
    245178{
    246179    va_list va;
    247180    va_start(va, cArgs);
    248     int rc = RTReqCallV(pQueue, ppReq, cMillies, RTREQFLAGS_VOID, pfnFunction, cArgs, va);
     181    int rc = RTReqQueueCallV(hQueue, ppReq, cMillies, RTREQFLAGS_VOID, pfnFunction, cArgs, va);
    249182    va_end(va);
    250183    return rc;
    251184}
    252 RT_EXPORT_SYMBOL(RTReqCallVoid);
    253 
    254 
    255 /**
    256  * Allocate and queue a call request to a void function.
    257  *
    258  * If it's desired to poll on the completion of the request set cMillies
    259  * to 0 and use RTReqWait() to check for completion. In the other case
    260  * use RT_INDEFINITE_WAIT.
    261  * The returned request packet must be freed using RTReqFree().
    262  *
    263  * @returns iprt status code.
    264  *          Will not return VERR_INTERRUPTED.
    265  * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    266  *
    267  * @param   pQueue          The request queue.
    268  * @param   ppReq           Where to store the pointer to the request.
    269  *                          This will be NULL or a valid request pointer not matter what happens, unless fFlags
    270  *                          contains RTREQFLAGS_NO_WAIT when it will be optional and always NULL.
    271  * @param   cMillies        Number of milliseconds to wait for the request to
    272  *                          be completed. Use RT_INDEFINITE_WAIT to only
    273  *                          wait till it's completed.
    274  * @param   fFlags          A combination of the RTREQFLAGS values.
    275  * @param   pfnFunction     Pointer to the function to call.
    276  * @param   cArgs           Number of arguments following in the ellipsis.
    277  * @param   ...             Function arguments.
    278  *
    279  * @remarks See remarks on RTReqCallV.
    280  */
    281 RTDECL(int) RTReqCallEx(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...)
     185RT_EXPORT_SYMBOL(RTReqQueueCallVoid);
     186
     187
     188RTDECL(int) RTReqQueueCallEx(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...)
    282189{
    283190    va_list va;
    284191    va_start(va, cArgs);
    285     int rc = RTReqCallV(pQueue, ppReq, cMillies, fFlags, pfnFunction, cArgs, va);
     192    int rc = RTReqQueueCallV(hQueue, ppReq, cMillies, fFlags, pfnFunction, cArgs, va);
    286193    va_end(va);
    287194    return rc;
    288195}
    289 RT_EXPORT_SYMBOL(RTReqCallEx);
    290 
    291 
    292 /**
    293  * Allocate and queue a call request.
    294  *
    295  * If it's desired to poll on the completion of the request set cMillies
    296  * to 0 and use RTReqWait() to check for completion. In the other case
    297  * use RT_INDEFINITE_WAIT.
    298  * The returned request packet must be freed using RTReqFree().
    299  *
    300  * @returns iprt status code.
    301  *          Will not return VERR_INTERRUPTED.
    302  * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    303  *
    304  * @param   pQueue          The request queue.
    305  * @param   ppReq           Where to store the pointer to the request.
    306  *                          This will be NULL or a valid request pointer not matter what happens, unless fFlags
    307  *                          contains RTREQFLAGS_NO_WAIT when it will be optional and always NULL.
    308  * @param   cMillies        Number of milliseconds to wait for the request to
    309  *                          be completed. Use RT_INDEFINITE_WAIT to only
    310  *                          wait till it's completed.
    311  * @param   fFlags          A combination of the RTREQFLAGS values.
    312  * @param   pfnFunction     Pointer to the function to call.
    313  * @param   cArgs           Number of arguments following in the ellipsis.
    314  * @param   Args            Variable argument vector.
    315  *
    316  * @remarks Caveats:
    317  *              - Do not pass anything which is larger than an uintptr_t.
    318  *              - 64-bit integers are larger than uintptr_t on 32-bit hosts.
    319  *                Pass integers > 32-bit by reference (pointers).
    320  *              - Don't use NULL since it should be the integer 0 in C++ and may
    321  *                therefore end up with garbage in the bits 63:32 on 64-bit
    322  *                hosts because 'int' is 32-bit.
    323  *                Use (void *)NULL or (uintptr_t)0 instead of NULL.
    324  */
    325 RTDECL(int) RTReqCallV(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args)
     196RT_EXPORT_SYMBOL(RTReqQueueCallEx);
     197
     198
     199RTDECL(int) RTReqQueueCallV(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args)
    326200{
    327201    LogFlow(("RTReqCallV: cMillies=%d fFlags=%#x pfnFunction=%p cArgs=%d\n", cMillies, fFlags, pfnFunction, cArgs));
     
    330204     * Check input.
    331205     */
    332     if (!pfnFunction || !pQueue || (fFlags & ~(RTREQFLAGS_RETURN_MASK | RTREQFLAGS_NO_WAIT)))
    333     {
    334         AssertFailed();
    335         return VERR_INVALID_PARAMETER;
    336     }
     206    PRTREQQUEUEINT pQueue = hQueue;
     207    AssertPtrReturn(pQueue, VERR_INVALID_HANDLE);
     208    AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
     209    AssertReturn(!(fFlags & ~(RTREQFLAGS_RETURN_MASK | RTREQFLAGS_NO_WAIT)), VERR_INVALID_PARAMETER);
     210
    337211    if (!(fFlags & RTREQFLAGS_NO_WAIT) || ppReq)
    338212    {
    339         Assert(ppReq);
     213        AssertPtrReturn(ppReq, VERR_INVALID_POINTER);
    340214        *ppReq = NULL;
    341215    }
     216
    342217    PRTREQ pReq = NULL;
    343     if (cArgs * sizeof(uintptr_t) > sizeof(pReq->u.Internal.aArgs))
    344     {
    345         AssertMsgFailed(("cArg=%d\n", cArgs));
    346         return VERR_TOO_MUCH_DATA;
    347     }
     218    AssertMsgReturn(cArgs * sizeof(uintptr_t) <= sizeof(pReq->u.Internal.aArgs), ("cArgs=%u\n", cArgs), VERR_TOO_MUCH_DATA);
    348219
    349220    /*
    350221     * Allocate request
    351222     */
    352     int rc = RTReqAlloc(pQueue, &pReq, RTREQTYPE_INTERNAL);
     223    int rc = RTReqQueueAlloc(pQueue, &pReq, RTREQTYPE_INTERNAL);
    353224    if (rc != VINF_SUCCESS)
    354225        return rc;
     
    366237     * Queue the request and return.
    367238     */
    368     rc = RTReqQueue(pReq, cMillies);
     239    rc = RTReqSubmit(pReq, cMillies);
    369240    if (   rc != VINF_SUCCESS
    370241        && rc != VERR_TIMEOUT)
     
    383254    return rc;
    384255}
    385 RT_EXPORT_SYMBOL(RTReqCallV);
     256RT_EXPORT_SYMBOL(RTReqQueueCallV);
     257
     258
     259RTDECL(bool) RTReqQueueIsBusy(RTREQQUEUE hQueue)
     260{
     261    PRTREQQUEUEINT pQueue = hQueue;
     262    AssertPtrReturn(pQueue, false);
     263
     264    if (ASMAtomicReadBool(&pQueue->fBusy))
     265        return true;
     266    if (ASMAtomicReadPtrT(&pQueue->pReqs, PRTREQ) != NULL)
     267        return true;
     268    if (ASMAtomicReadBool(&pQueue->fBusy))
     269        return true;
     270    return false;
     271}
     272RT_EXPORT_SYMBOL(RTReqQueueIsBusy);
    386273
    387274
     
    415302 * Joins the list pList with whatever is linked up at *pHead.
    416303 */
    417 static void vmr3ReqJoinFree(PRTREQQUEUE pQueue, PRTREQ pList)
     304static void vmr3ReqJoinFree(PRTREQQUEUEINT pQueue, PRTREQ pList)
    418305{
    419306    /*
     
    439326
    440327
    441 /**
    442  * Allocates a request packet.
    443  *
    444  * The caller allocates a request packet, fills in the request data
    445  * union and queues the request.
    446  *
    447  * @returns iprt status code.
    448  *
    449  * @param   pQueue          The request queue.
    450  * @param   ppReq           Where to store the pointer to the allocated packet.
    451  * @param   enmType         Package type.
    452  */
    453 RTDECL(int) RTReqAlloc(PRTREQQUEUE pQueue, PRTREQ *ppReq, RTREQTYPE enmType)
     328RTDECL(int) RTReqQueueAlloc(RTREQQUEUE hQueue, PRTREQ *ppReq, RTREQTYPE enmType)
    454329{
    455330    /*
    456331     * Validate input.
    457332     */
    458     if (    enmType < RTREQTYPE_INVALID
    459         ||  enmType > RTREQTYPE_MAX)
    460     {
    461         AssertMsgFailed(("Invalid package type %d valid range %d-%d inclusively.\n",
    462                          enmType, RTREQTYPE_INVALID + 1, RTREQTYPE_MAX - 1));
    463         return VERR_RT_REQUEST_INVALID_TYPE;
    464     }
     333    PRTREQQUEUEINT pQueue = hQueue;
     334    AssertPtrReturn(pQueue, VERR_INVALID_HANDLE);
     335    AssertMsgReturn(enmType > RTREQTYPE_INVALID && enmType < RTREQTYPE_MAX, ("%d\n", enmType), VERR_RT_REQUEST_INVALID_TYPE);
    465336
    466337    /*
     
    526397            Assert(pReq->enmType == RTREQTYPE_INVALID);
    527398            Assert(pReq->enmState == RTREQSTATE_FREE);
    528             Assert(pReq->pQueue == pQueue);
     399            Assert(pReq->hQueue == pQueue);
    529400            ASMAtomicXchgSize(&pReq->pNext, NULL);
    530401            pReq->enmState = RTREQSTATE_ALLOCATED;
     
    561432     */
    562433    pReq->pNext    = NULL;
    563     pReq->pQueue   = pQueue;
     434    pReq->hQueue   = pQueue;
    564435    pReq->enmState = RTREQSTATE_ALLOCATED;
    565436    pReq->iStatus  = VERR_RT_REQUEST_STATUS_STILL_PENDING;
     
    572443    return VINF_SUCCESS;
    573444}
    574 RT_EXPORT_SYMBOL(RTReqAlloc);
    575 
    576 
    577 /**
    578  * Free a request packet.
    579  *
    580  * @returns iprt status code.
    581  *
    582  * @param   pReq            Package to free.
    583  * @remark  The request packet must be in allocated or completed state!
    584  */
     445RT_EXPORT_SYMBOL(RTReqQueueAlloc);
     446
     447
    585448RTDECL(int) RTReqFree(PRTREQ pReq)
    586449{
     
    612475    pReq->enmType  = RTREQTYPE_INVALID;
    613476
    614     PRTREQQUEUE pQueue = pReq->pQueue;
     477    PRTREQQUEUEINT pQueue = pReq->hQueue;
    615478    if (pQueue->cReqFree < 128)
    616479    {
     
    634497
    635498
    636 /**
    637  * Queue a request.
    638  *
    639  * The quest must be allocated using RTReqAlloc() and contain
    640  * all the required data.
    641  * If it's desired to poll on the completion of the request set cMillies
    642  * to 0 and use RTReqWait() to check for completion. In the other case
    643  * use RT_INDEFINITE_WAIT.
    644  *
    645  * @returns iprt status code.
    646  *          Will not return VERR_INTERRUPTED.
    647  * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    648  *
    649  * @param   pReq            The request to queue.
    650  * @param   cMillies        Number of milliseconds to wait for the request to
    651  *                          be completed. Use RT_INDEFINITE_WAIT to only
    652  *                          wait till it's completed.
    653  */
    654 RTDECL(int) RTReqQueue(PRTREQ pReq, RTMSINTERVAL cMillies)
     499RTDECL(int) RTReqSubmit(PRTREQ pReq, RTMSINTERVAL cMillies)
    655500{
    656501    LogFlow(("RTReqQueue: pReq=%p cMillies=%d\n", pReq, cMillies));
     
    663508        return VERR_RT_REQUEST_STATE;
    664509    }
    665     if (   !pReq->pQueue
     510    if (   !pReq->hQueue
    666511        ||  pReq->pNext
    667512        ||  !pReq->EventSem)
     
    682527     * Insert it.
    683528     */
    684     PRTREQQUEUE pQueue = ((RTREQ volatile *)pReq)->pQueue;                 /* volatile paranoia */
     529    PRTREQQUEUEINT pQueue = ((RTREQ volatile *)pReq)->hQueue;              /* volatile paranoia */
    685530    unsigned fFlags = ((RTREQ volatile *)pReq)->fFlags;                    /* volatile paranoia */
    686531    pReq->enmState = RTREQSTATE_QUEUED;
     
    706551    return rc;
    707552}
    708 RT_EXPORT_SYMBOL(RTReqQueue);
    709 
    710 
    711 /**
    712  * Wait for a request to be completed.
    713  *
    714  * @returns iprt status code.
    715  *          Will not return VERR_INTERRUPTED.
    716  * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
    717  *
    718  * @param   pReq            The request to wait for.
    719  * @param   cMillies        Number of milliseconds to wait.
    720  *                          Use RT_INDEFINITE_WAIT to only wait till it's completed.
    721  */
     553RT_EXPORT_SYMBOL(RTReqSubmit);
     554
     555
    722556RTDECL(int) RTReqWait(PRTREQ pReq, RTMSINTERVAL cMillies)
    723557{
     
    734568        return VERR_RT_REQUEST_STATE;
    735569    }
    736     if (    !pReq->pQueue
     570    if (    !pReq->hQueue
    737571        ||  !pReq->EventSem)
    738572    {
     
    916750}
    917751
    918 
    919 /**
    920  * Checks if the queue is busy or not.
    921  *
    922  * The caller is responsible for dealing with any concurrent submitts.
    923  *
    924  * @returns true if busy, false if idle.
    925  * @param   pQueue              The queue.
    926  */
    927 RTDECL(bool) RTReqIsBusy(PRTREQQUEUE pQueue)
    928 {
    929     AssertPtrReturn(pQueue, false);
    930 
    931     if (ASMAtomicReadBool(&pQueue->fBusy))
    932         return true;
    933     if (ASMAtomicReadPtrT(&pQueue->pReqs, PRTREQ) != NULL)
    934         return true;
    935     if (ASMAtomicReadBool(&pQueue->fBusy))
    936         return true;
    937     return false;
    938 }
    939 RT_EXPORT_SYMBOL(RTReqIsBusy);
Note: See TracChangeset for help on using the changeset viewer.

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