VirtualBox

Changeset 38305 in vbox for trunk


Ignore:
Timestamp:
Aug 4, 2011 8:18:54 AM (13 years ago)
Author:
vboxsync
Message:

Addressed some todos.

File:
1 edited

Legend:

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

    r37210 r38305  
    55
    66/*
    7  * Copyright (C) 2010 Oracle Corporation
     7 * Copyright (C) 2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3939*   Structures and Typedefs                                                    *
    4040*******************************************************************************/
    41 /** @todo r=bird: this is missing docs and magic. uXPos should be offX.
    42  *        cbBufSize should be cbBuf. */
     41/** @todo r=bird: this is missing docs and magic. */
    4342typedef struct RTCIRCBUF
    4443{
    4544    /** The current read position in the buffer. */
    46     size_t          uReadPos;
     45    size_t          offRead;
    4746    /** The current write position in the buffer. */
    48     size_t          uWritePos;
     47    size_t          offWrite;
    4948    /** How much space of the buffer is currently in use. */
    50     volatile size_t cbBufUsed;
     49    volatile size_t cbUsed;
    5150    /** How big is the buffer. */
    52     size_t          cbBufSize;
     51    size_t          cbBuf;
    5352    /** The buffer itself. */
    5453    void           *pvBuf;
    55 } RTCIRCBUF;
    56 
     54} RTCIRCBUF, *PRTCIRCBUF;
    5755
    5856
     
    7169    if (pTmpBuf->pvBuf)
    7270    {
    73         pTmpBuf->cbBufSize = cbSize;
     71        pTmpBuf->cbBuf = cbSize;
    7472        *ppBuf = pTmpBuf;
    7573        return VINF_SUCCESS;
     
    9795    AssertPtr(pBuf);
    9896
    99     pBuf->uReadPos  = 0;
    100     pBuf->uWritePos = 0;
    101     pBuf->cbBufUsed = 0;
     97    pBuf->offRead  = 0;
     98    pBuf->offWrite = 0;
     99    pBuf->cbUsed = 0;
    102100}
    103101
     
    108106    AssertPtrReturn(pBuf, 0);
    109107
    110     return pBuf->cbBufSize - ASMAtomicReadZ(&pBuf->cbBufUsed);
     108    return pBuf->cbBuf - ASMAtomicReadZ(&pBuf->cbUsed);
    111109}
    112110
     
    117115    AssertPtrReturn(pBuf, 0);
    118116
    119     return ASMAtomicReadZ(&pBuf->cbBufUsed);
     117    return ASMAtomicReadZ(&pBuf->cbUsed);
    120118}
    121119
     
    126124    AssertPtrReturn(pBuf, 0);
    127125
    128     return pBuf->cbBufSize;
     126    return pBuf->cbBuf;
    129127}
    130128
     
    142140
    143141    /* How much is in use? */
    144     size_t cbUsed = ASMAtomicReadZ(&pBuf->cbBufUsed);
     142    size_t cbUsed = ASMAtomicReadZ(&pBuf->cbUsed);
    145143    if (cbUsed > 0)
    146144    {
    147145        /* Get the size out of the requested size, the read block till the end
    148146         * of the buffer & the currently used size. */
    149         size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uReadPos, cbUsed));
     147        size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf - pBuf->offRead, cbUsed));
    150148        if (cbSize > 0)
    151149        {
    152150            /* Return the pointer address which point to the current read
    153151             * position. */
    154             *ppvStart = (char *)pBuf->pvBuf + pBuf->uReadPos;
     152            *ppvStart = (char *)pBuf->pvBuf + pBuf->offRead;
    155153            *pcbSize = cbSize;
    156154        }
     
    165163
    166164    /* Split at the end of the buffer. */
    167     pBuf->uReadPos = (pBuf->uReadPos + cbSize) % pBuf->cbBufSize;
    168 
    169     ASMAtomicSubZ(&pBuf->cbBufUsed, cbSize);
     165    pBuf->offRead = (pBuf->offRead + cbSize) % pBuf->cbBuf;
     166
     167    ASMAtomicSubZ(&pBuf->cbUsed, cbSize);
    170168}
    171169
     
    183181
    184182    /* How much is free? */
    185     size_t cbFree = pBuf->cbBufSize - ASMAtomicReadZ(&pBuf->cbBufUsed);
     183    size_t cbFree = pBuf->cbBuf - ASMAtomicReadZ(&pBuf->cbUsed);
    186184    if (cbFree > 0)
    187185    {
    188186        /* Get the size out of the requested size, the write block till the end
    189187         * of the buffer & the currently free size. */
    190         size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uWritePos, cbFree));
     188        size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf - pBuf->offWrite, cbFree));
    191189        if (cbSize > 0)
    192190        {
    193191            /* Return the pointer address which point to the current write
    194192             * position. */
    195             *ppvStart = (char*)pBuf->pvBuf + pBuf->uWritePos;
     193            *ppvStart = (char*)pBuf->pvBuf + pBuf->offWrite;
    196194            *pcbSize = cbSize;
    197195        }
     
    206204
    207205    /* Split at the end of the buffer. */
    208     pBuf->uWritePos = (pBuf->uWritePos + cbSize) % pBuf->cbBufSize;
     206    pBuf->offWrite = (pBuf->offWrite + cbSize) % pBuf->cbBuf;
    209207
    210208    size_t cbOldIgnored = 0;
    211     ASMAtomicAddZ(&pBuf->cbBufUsed, cbSize);
    212 }
    213 
     209    ASMAtomicAddZ(&pBuf->cbUsed, cbSize);
     210}
     211
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