VirtualBox

Changeset 49814 in vbox for trunk/src/VBox/Devices/USB/linux


Ignore:
Timestamp:
Dec 6, 2013 9:38:28 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
91156
Message:

Devices/USB: First part of the rework, move most of the work to dedicated threads to improve performance

File:
1 edited

Legend:

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

    r46326 r49814  
    3333#include <iprt/stdint.h>
    3434#include <iprt/err.h>
     35#include <iprt/pipe.h>
    3536
    3637#include <sys/types.h>
     
    153154    /** Are we using sysfs to find the active configuration? */
    154155    bool                fUsingSysfs;
     156    /** Pipe handle for waiking up - writing end. */
     157    RTPIPE              hPipeWakeupW;
     158    /** Pipe handle for waiking up - reading end. */
     159    RTPIPE              hPipeWakeupR;
    155160    /** The device node/sysfs path of the device.
    156161     * Used to figure out the configuration after a reset. */
     
    657662    if (RT_SUCCESS(rc))
    658663    {
    659         /*
    660          * Allocate and initialize the linux backend data.
    661          */
    662         PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)RTMemAllocZVar(sizeof(*pDevLnx) + cchPath);
    663         if (pDevLnx)
    664         {
    665             pDevLnx->fUsingSysfs = fUsingSysfs;
    666             memcpy(&pDevLnx->szPath[0], pszPath, cchPath);
    667             pDevLnx->szPath[cchPath] = '\0';
    668             pDevLnx->hFile = hFile;
    669             rc = RTCritSectInit(&pDevLnx->CritSect);
    670             if (RT_SUCCESS(rc))
     664            /*
     665             * Allocate and initialize the linux backend data.
     666             */
     667            PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)RTMemAllocZVar(sizeof(*pDevLnx) + cchPath);
     668            if (pDevLnx)
    671669            {
    672                 pProxyDev->Backend.pv = pDevLnx;
    673 
    674                 LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n",
    675                          pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg));
    676 
    677                 return VINF_SUCCESS;
     670
     671                rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0);
     672                if (RT_SUCCESS(rc))
     673                {
     674                    pDevLnx->fUsingSysfs = fUsingSysfs;
     675                    memcpy(&pDevLnx->szPath[0], pszPath, cchPath);
     676                    pDevLnx->szPath[cchPath] = '\0';
     677                    pDevLnx->hFile = hFile;
     678                    rc = RTCritSectInit(&pDevLnx->CritSect);
     679                    if (RT_SUCCESS(rc))
     680                    {
     681                        pProxyDev->Backend.pv = pDevLnx;
     682
     683                        LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n",
     684                                 pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg));
     685
     686                        return VINF_SUCCESS;
     687                    }
     688                    RTPipeClose(pDevLnx->hPipeWakeupR);
     689                    RTPipeClose(pDevLnx->hPipeWakeupW);
     690                }
     691
     692                RTMemFree(pDevLnx);
    678693            }
    679 
    680             RTMemFree(pDevLnx);
    681         }
    682         else
    683             rc = VERR_NO_MEMORY;
     694            else
     695                rc = VERR_NO_MEMORY;
     696
    684697        RTFileClose(hFile);
    685698    }
     
    814827    RTFileClose(pDevLnx->hFile);
    815828    pDevLnx->hFile = NIL_RTFILE;
     829
     830    RTPipeClose(pDevLnx->hPipeWakeupR);
     831    RTPipeClose(pDevLnx->hPipeWakeupW);
    816832
    817833    RTMemFree(pDevLnx);
     
    17451761         */
    17461762        if (!pDevLnx->pInFlightHead)
     1763        {
     1764            int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies;
     1765
     1766            LogFlow(("Nothing in flight, going to sleep\n"));
     1767
     1768            struct pollfd pfd;
     1769
     1770            pfd.fd = RTPipeToNative(pDevLnx->hPipeWakeupR);
     1771            pfd.events = POLLIN | POLLHUP;
     1772            pfd.revents = 0;
     1773
     1774            int rc = poll(&pfd, 1, cMilliesWait);
     1775            Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc));
     1776            if (rc >= 1)
     1777            {
     1778                /* Drain pipe. */
     1779               uint8_t bRead;
     1780               size_t cbIgnored = 0;
     1781               RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored);
     1782            }
    17471783            return NULL;
     1784        }
    17481785
    17491786        /*
     
    17561793        if (cMillies)
    17571794        {
     1795            int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies;
    17581796
    17591797            for (;;)
    17601798            {
    1761                 struct pollfd pfd;
    1762                 pfd.fd = RTFileToNative(pDevLnx->hFile);
    1763                 pfd.events = POLLOUT | POLLWRNORM /* completed async */
    1764                            | POLLERR | POLLHUP    /* disconnected */;
    1765                 pfd.revents = 0;
    1766                 int rc = poll(&pfd, 1, cMillies);
     1799                struct pollfd pfd[2];
     1800                pfd[0].fd = RTFileToNative(pDevLnx->hFile);
     1801                pfd[0].events = POLLOUT | POLLWRNORM /* completed async */
     1802                              | POLLERR | POLLHUP    /* disconnected */;
     1803                pfd[0].revents = 0;
     1804
     1805                pfd[1].fd = RTPipeToNative(pDevLnx->hPipeWakeupR);
     1806                pfd[1].events = POLLIN | POLLHUP;
     1807                pfd[1].revents = 0;
     1808
     1809                int rc = poll(&pfd[0], 2, cMilliesWait);
    17671810                Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc));
    17681811                if (rc >= 1)
     1812                {
     1813                    /* If the pipe caused the return drain it. */
     1814                    if (pfd[1].revents & POLLIN)
     1815                    {
     1816                        uint8_t bRead;
     1817                        size_t cbIgnored = 0;
     1818                        RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored);
     1819                    }
    17691820                    break;
     1821                }
    17701822                if (rc >= 0 /*|| errno == ETIMEOUT*/)
    17711823                {
     
    19471999
    19482000
     2001static DECLCALLBACK(int) usbProxyLinuxWakeup(PUSBPROXYDEV pProxyDev)
     2002{
     2003    PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     2004    size_t cbIgnored;
     2005
     2006    LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
     2007
     2008    return RTPipeWrite(pDevLnx->hPipeWakeupW, "", 1, &cbIgnored);
     2009}
     2010
    19492011/**
    19502012 * The Linux USB Proxy Backend.
     
    19652027    usbProxyLinuxUrbCancel,
    19662028    usbProxyLinuxUrbReap,
     2029    usbProxyLinuxWakeup,
    19672030    0
    19682031};
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