VirtualBox

Ignore:
Timestamp:
Sep 8, 2011 9:30:17 AM (13 years ago)
Author:
vboxsync
Message:

Runtime/Sg: Leave early if there is no memory left in the S/G buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/sg.cpp

    r38539 r38686  
    3636static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData)
    3737{
    38     size_t cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft);
    39     void *pvBuf = pSgBuf->pvSegCur;
     38    size_t cbData;
     39    void *pvBuf;
     40
     41    /* Check that the S/G buffer has memory left. */
     42    if (RT_UNLIKELY(   pSgBuf->idxSeg == pSgBuf->cSegs
     43                    && !pSgBuf->cbSegLeft))
     44    {
     45        *pcbData = 0;
     46        return NULL;
     47    }
    4048
    4149    AssertReleaseMsg(      pSgBuf->cbSegLeft <= 5 * _1M
     
    4654                      pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg, pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg));
    4755
     56    cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft);
     57    pvBuf  = pSgBuf->pvSegCur;
    4858    pSgBuf->cbSegLeft -= cbData;
    4959
     
    5363        pSgBuf->idxSeg++;
    5464
    55         if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSegs))
    56         {
    57             pSgBuf->cbSegLeft = 0;
    58             pSgBuf->pvSegCur  = NULL;
    59         }
    60         else
     65        if (pSgBuf->idxSeg < pSgBuf->cSegs)
    6166        {
    6267            pSgBuf->pvSegCur  = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg;
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