VirtualBox

Changeset 37144 in vbox


Ignore:
Timestamp:
May 18, 2011 4:47:44 PM (14 years ago)
Author:
vboxsync
Message:

dev/usb/win: avoid using a crit sect for race fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/win/USBProxyDevice-win.cpp

    r37135 r37144  
    3636#include <iprt/string.h>
    3737#include <iprt/thread.h>
     38#include <iprt/asm.h>
    3839#include "../USBProxyDevice.h"
    3940#include <VBox/usblib.h>
     
    617618     */
    618619    PVUSBURB pUrb = NULL;
    619     unsigned cQueuedUrbs;
    620     /* we must get the queued urb count inside a lock
    621      * otherwise we may end up in a situation when cQueuedUrbs is incremented
    622      * by the usbProxyWinAsyncIoThread, but the pPriv->paHandles[cQueuedUrbs-1]
    623      * is still invalid */
    624     RTCritSectEnter(&pPriv->CritSect);
    625     cQueuedUrbs = pPriv->cQueuedUrbs;
    626     RTCritSectLeave(&pPriv->CritSect);
     620    unsigned cQueuedUrbs = ASMAtomicReadU32((volatile uint32_t *)&pPriv->cQueuedUrbs);
    627621
    628622    DWORD rc = WaitForMultipleObjects(cQueuedUrbs, pPriv->paHandles, FALSE, cMillies);
     
    728722                    {
    729723                        /* insert into the queue */
    730                         unsigned j = pPriv->cQueuedUrbs++;
     724                        unsigned j = pPriv->cQueuedUrbs;
    731725                        pPriv->paQueuedUrbs[j] = pQUrbWin;
    732                         pPriv->paHandles[j]    = pQUrbWin->overlapped.hEvent;
     726                        pPriv->paHandles[j] = pQUrbWin->overlapped.hEvent;
     727                        /* do an atomic increment to allow usbProxyWinUrbReap thread get it outside a lock,
     728                         * being sure that pPriv->paHandles contains cQueuedUrbs valid handles */
     729                        ASMAtomicIncU32((uint32_t volatile *)&pPriv->cQueuedUrbs);
    733730                    }
    734731                    else
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