VirtualBox

Changeset 59737 in vbox for trunk/src/VBox/Devices/USB


Ignore:
Timestamp:
Feb 19, 2016 11:26:16 AM (9 years ago)
Author:
vboxsync
Message:

VUSB: Some structural cleanup (#6 Use RTLIST* where appropriate)

Location:
trunk/src/VBox/Devices/USB
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/DrvVUSBRootHub.cpp

    r59722 r59737  
    541541{
    542542    if (!cMillies)
    543         vusbUrbDoReapAsync(pDev->pAsyncUrbHead, 0);
     543        vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, 0);
    544544    else
    545545    {
     
    547547        do
    548548        {
    549             vusbUrbDoReapAsync(pDev->pAsyncUrbHead, RT_MIN(cMillies >> 8, 10));
    550         } while (   pDev->pAsyncUrbHead
     549            vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, RT_MIN(cMillies >> 8, 10));
     550        } while (   !RTListIsEmpty(&pDev->LstAsyncUrbs)
    551551                 && RTTimeMilliTS() - u64Start < cMillies);
    552552    }
     
    561561    PVUSBDEV pDev = (PVUSBDEV)pDevice;
    562562
    563     if (!pDev->pAsyncUrbHead)
     563    if (RTListIsEmpty(&pDev->LstAsyncUrbs))
    564564        return;
    565565
     
    606606     * moment.
    607607     */
    608     PVUSBURB pUrb = pDev->pAsyncUrbHead;
    609 
    610     while (pUrb)
    611     {
    612         PVUSBURB pNext = pUrb->pVUsb->pNext;
     608    PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
     609
     610    RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
     611    {
     612        PVUSBURB pUrb = pVUsbUrb->pUrb;
    613613        /* Call the worker directly. */
    614614        vusbUrbCancelWorker(pUrb, CANCELMODE_FAIL);
    615         pUrb = pNext;
    616615    }
    617616
     
    648647     * Iterate the URBs, find ones corresponding to given EP, and cancel them.
    649648     */
    650     PVUSBURB pUrb = pDev->pAsyncUrbHead;
    651     while (pUrb)
    652     {
    653         PVUSBURB pNext = pUrb->pVUsb->pNext;
     649    PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
     650
     651    RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
     652    {
     653        PVUSBURB pUrb = pVUsbUrb->pUrb;
    654654
    655655        Assert(pUrb->pVUsb->pDev == pDev);
     
    661661            AssertRC(rc);
    662662        }
    663         pUrb = pNext;
    664663    }
    665664
  • trunk/src/VBox/Devices/USB/VUSBDevice.cpp

    r59718 r59737  
    10491049     * Iterate the URBs and cancel them.
    10501050     */
    1051     PVUSBURB pUrb = pDev->pAsyncUrbHead;
    1052     while (pUrb)
    1053     {
    1054         PVUSBURB pNext = pUrb->pVUsb->pNext;
     1051    PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
     1052    RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
     1053    {
     1054        PVUSBURB pUrb = pVUsbUrb->pUrb;
    10551055
    10561056        Assert(pUrb->pVUsb->pDev == pDev);
     
    10591059        int rc = vusbUrbCancelWorker(pUrb, CANCELMODE_FAIL);
    10601060        AssertRC(rc);
    1061         pUrb = pNext;
    10621061    }
    10631062
     
    10701069    {
    10711070        cReaped = 0;
    1072         pUrb = pDev->pAsyncUrbHead;
    1073         while (pUrb)
     1071        pVUsbUrb = RTListGetFirst(&pDev->LstAsyncUrbs, VUSBURBVUSBINT, NdLst);
     1072        while (pVUsbUrb)
    10741073        {
    1075             PVUSBURB pNext = pUrb->pVUsb->pNext;
     1074            PVUSBURBVUSB pNext = RTListGetNext(&pDev->LstAsyncUrbs, pVUsbUrb, VUSBURBVUSBINT, NdLst);
     1075            PVUSBURB pUrb = pVUsbUrb->pUrb;
    10761076            Assert(pUrb->pVUsb->pDev == pDev);
    10771077
     
    10901090            if (pRipe)
    10911091            {
    1092                 if (pRipe == pNext)
    1093                     pNext = pNext->pVUsb->pNext;
     1092                if (pRipe == pNext->pUrb)
     1093                    pNext = RTListGetNext(&pDev->LstAsyncUrbs, pNext, VUSBURBVUSBINT, NdLst);
    10941094                vusbUrbRipe(pRipe);
    10951095                cReaped++;
    10961096            }
    10971097
    1098             pUrb = pNext;
     1098            pVUsbUrb = pNext;
    10991099        }
    11001100    } while (cReaped > 0);
     
    11051105    if (fDetaching)
    11061106    {
    1107         pUrb = pDev->pAsyncUrbHead;
    1108         while (pUrb)
     1107        RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
    11091108        {
    1110             PVUSBURB pNext = pUrb->pVUsb->pNext;
     1109            PVUSBURB pUrb = pVUsbUrb->pUrb;
    11111110            Assert(pUrb->pVUsb->pDev == pDev);
    11121111
     
    11191118             */
    11201119            pUrb->pVUsb->pfnFree(pUrb);
    1121             pUrb = pNext;
    11221120        }
    11231121    }
     
    17641762    pDev->pCurCfgDesc = NULL;
    17651763    pDev->paIfStates = NULL;
     1764    RTListInit(&pDev->LstAsyncUrbs);
    17661765    memset(&pDev->aPipes[0], 0, sizeof(pDev->aPipes));
    17671766    for (unsigned i = 0; i < RT_ELEMENTS(pDev->aPipes); i++)
  • trunk/src/VBox/Devices/USB/VUSBInternal.h

    r59724 r59737  
    7575typedef struct VUSBURBVUSBINT
    7676{
    77     /** URB chain pointer. */
    78     PVUSBURB        pNext;
    79     /** URB chain pointer. */
    80     PVUSBURB       *ppPrev;
     77    /** Node for one of the lists the URB can be in. */
     78    RTLISTNODE      NdLst;
     79    /** Pointer to the URB this structure is part of. */
     80    PVUSBURB        pUrb;
    8181    /** Pointer to the original for control messages. */
    8282    PVUSBURB        pCtrlUrb;
     
    248248    RTCRITSECT          CritSectAsyncUrbs;
    249249    /** List of active async URBs. */
    250     PVUSBURB            pAsyncUrbHead;
     250    RTLISTANCHOR        LstAsyncUrbs;
     251#if HC_ARCH_BITS == 32
     252    /** Align the size to a 8 byte boundary. */
     253    uint32_t            u32Alignment0;
     254#endif
    251255
    252256    /** Dumper state. */
     
    476480int  vusbUrbSubmit(PVUSBURB pUrb);
    477481void vusbUrbTrace(PVUSBURB pUrb, const char *pszMsg, bool fComplete);
    478 void vusbUrbDoReapAsync(PVUSBURB pHead, RTMSINTERVAL cMillies);
     482void vusbUrbDoReapAsync(PRTLISTANCHOR pUrbLst, RTMSINTERVAL cMillies);
    479483void vusbUrbDoReapAsyncDev(PVUSBDEV pDev, RTMSINTERVAL cMillies);
    480484void vusbUrbCancel(PVUSBURB pUrb, CANCELMODE mode);
     
    548552
    549553    RTCritSectEnter(&pDev->CritSectAsyncUrbs);
    550     *pUrb->pVUsb->ppPrev = pUrb->pVUsb->pNext;
    551     if (pUrb->pVUsb->pNext)
    552         pUrb->pVUsb->pNext->pVUsb->ppPrev = pUrb->pVUsb->ppPrev;
    553     pUrb->pVUsb->pNext = NULL;
    554     pUrb->pVUsb->ppPrev = NULL;
     554    RTListNodeRemove(&pUrb->pVUsb->NdLst);
    555555    RTCritSectLeave(&pDev->CritSectAsyncUrbs);
    556556}
  • trunk/src/VBox/Devices/USB/VUSBUrb.cpp

    r59704 r59737  
    12361236    ASMAtomicIncU32(&pDev->aPipes[pUrb->EndPt].async);
    12371237
    1238     /* Queue the pUrb on the roothub */
    1239     pUrb->pVUsb->pNext = pDev->pAsyncUrbHead;
    1240     if (pDev->pAsyncUrbHead)
    1241         pDev->pAsyncUrbHead->pVUsb->ppPrev = &pUrb->pVUsb->pNext;
    1242     pDev->pAsyncUrbHead = pUrb;
    1243     pUrb->pVUsb->ppPrev = &pDev->pAsyncUrbHead;
     1238    /* Queue the Urb on the roothub */
     1239    RTListAppend(&pDev->LstAsyncUrbs, &pUrb->pVUsb->NdLst);
    12441240    RTCritSectLeave(&pDev->CritSectAsyncUrbs);
    12451241
     
    19941990 * Reap in-flight URBs.
    19951991 *
    1996  * @param   pHead       Pointer to the head of the URB list.
     1992 * @param   pUrbLst     Pointer to the head of the URB list.
    19971993 * @param   cMillies    Number of milliseconds to block in each reap operation.
    19981994 *                      Use 0 to not block at all.
    19991995 */
    2000 void vusbUrbDoReapAsync(PVUSBURB pHead, RTMSINTERVAL cMillies)
    2001 {
    2002     PVUSBURB pUrb = pHead;
    2003     while (pUrb)
    2004     {
     1996void vusbUrbDoReapAsync(PRTLISTANCHOR pUrbLst, RTMSINTERVAL cMillies)
     1997{
     1998    PVUSBURBVUSB pVUsbUrb = RTListGetFirst(pUrbLst, VUSBURBVUSBINT, NdLst);
     1999    while (pVUsbUrb)
     2000    {
     2001        PVUSBURB pUrb = pVUsbUrb->pUrb;
     2002
    20052003        vusbUrbAssert(pUrb);
    2006         PVUSBURB pUrbNext = pUrb->pVUsb->pNext;
    2007         PVUSBDEV pDev = pUrb->pVUsb->pDev;
     2004        PVUSBURBVUSB pVUsbUrbNext = RTListGetNext(pUrbLst, pVUsbUrb, VUSBURBVUSBINT, NdLst);
     2005        PVUSBDEV pDev = pVUsbUrb->pDev;
    20082006
    20092007        /* Don't touch resetting devices - paranoid safety precaution. */
     
    20242022            {
    20252023                vusbUrbAssert(pRipe);
    2026                 if (pRipe == pUrbNext)
    2027                     pUrbNext = pUrbNext->pVUsb->pNext;
     2024                if (pRipe == pVUsbUrbNext->pUrb)
     2025                    pVUsbUrbNext = RTListGetNext(pUrbLst, pVUsbUrb, VUSBURBVUSBINT, NdLst);
    20282026                vusbUrbRipe(pRipe);
    20292027            }
     
    20312029
    20322030        /* next */
    2033         pUrb = pUrbNext;
     2031        pVUsbUrb = pVUsbUrbNext;
    20342032    }
    20352033}
  • trunk/src/VBox/Devices/USB/VUSBUrbPool.cpp

    r59722 r59737  
    192192    pUrb->pVUsb                  = (PVUSBURBVUSB)&pUrb->abData[offAlloc];
    193193    offAlloc += sizeof(VUSBURBVUSBINT);
     194    pUrb->pVUsb->pUrb            = pUrb;
    194195    pUrb->pVUsb->pvFreeCtx       = NULL;
    195196    pUrb->pVUsb->pfnFree         = NULL;
    196     pUrb->pVUsb->pNext           = NULL;
    197     pUrb->pVUsb->ppPrev          = NULL;
    198197    pUrb->pVUsb->pCtrlUrb        = NULL;
    199198    pUrb->pVUsb->u64SubmitTS     = 0;
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