- Timestamp:
- Aug 4, 2011 8:18:54 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/circbuf.cpp
r37210 r38305 5 5 6 6 /* 7 * Copyright (C) 201 0Oracle Corporation7 * Copyright (C) 2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 39 39 * Structures and Typedefs * 40 40 *******************************************************************************/ 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. */ 43 42 typedef struct RTCIRCBUF 44 43 { 45 44 /** The current read position in the buffer. */ 46 size_t uReadPos;45 size_t offRead; 47 46 /** The current write position in the buffer. */ 48 size_t uWritePos;47 size_t offWrite; 49 48 /** How much space of the buffer is currently in use. */ 50 volatile size_t cb BufUsed;49 volatile size_t cbUsed; 51 50 /** How big is the buffer. */ 52 size_t cbBuf Size;51 size_t cbBuf; 53 52 /** The buffer itself. */ 54 53 void *pvBuf; 55 } RTCIRCBUF; 56 54 } RTCIRCBUF, *PRTCIRCBUF; 57 55 58 56 … … 71 69 if (pTmpBuf->pvBuf) 72 70 { 73 pTmpBuf->cbBuf Size= cbSize;71 pTmpBuf->cbBuf = cbSize; 74 72 *ppBuf = pTmpBuf; 75 73 return VINF_SUCCESS; … … 97 95 AssertPtr(pBuf); 98 96 99 pBuf-> uReadPos= 0;100 pBuf-> uWritePos= 0;101 pBuf->cb BufUsed = 0;97 pBuf->offRead = 0; 98 pBuf->offWrite = 0; 99 pBuf->cbUsed = 0; 102 100 } 103 101 … … 108 106 AssertPtrReturn(pBuf, 0); 109 107 110 return pBuf->cbBuf Size - ASMAtomicReadZ(&pBuf->cbBufUsed);108 return pBuf->cbBuf - ASMAtomicReadZ(&pBuf->cbUsed); 111 109 } 112 110 … … 117 115 AssertPtrReturn(pBuf, 0); 118 116 119 return ASMAtomicReadZ(&pBuf->cb BufUsed);117 return ASMAtomicReadZ(&pBuf->cbUsed); 120 118 } 121 119 … … 126 124 AssertPtrReturn(pBuf, 0); 127 125 128 return pBuf->cbBuf Size;126 return pBuf->cbBuf; 129 127 } 130 128 … … 142 140 143 141 /* How much is in use? */ 144 size_t cbUsed = ASMAtomicReadZ(&pBuf->cb BufUsed);142 size_t cbUsed = ASMAtomicReadZ(&pBuf->cbUsed); 145 143 if (cbUsed > 0) 146 144 { 147 145 /* Get the size out of the requested size, the read block till the end 148 146 * of the buffer & the currently used size. */ 149 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf Size - pBuf->uReadPos, cbUsed));147 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf - pBuf->offRead, cbUsed)); 150 148 if (cbSize > 0) 151 149 { 152 150 /* Return the pointer address which point to the current read 153 151 * position. */ 154 *ppvStart = (char *)pBuf->pvBuf + pBuf-> uReadPos;152 *ppvStart = (char *)pBuf->pvBuf + pBuf->offRead; 155 153 *pcbSize = cbSize; 156 154 } … … 165 163 166 164 /* Split at the end of the buffer. */ 167 pBuf-> uReadPos = (pBuf->uReadPos + cbSize) % pBuf->cbBufSize;168 169 ASMAtomicSubZ(&pBuf->cb BufUsed, cbSize);165 pBuf->offRead = (pBuf->offRead + cbSize) % pBuf->cbBuf; 166 167 ASMAtomicSubZ(&pBuf->cbUsed, cbSize); 170 168 } 171 169 … … 183 181 184 182 /* How much is free? */ 185 size_t cbFree = pBuf->cbBuf Size - ASMAtomicReadZ(&pBuf->cbBufUsed);183 size_t cbFree = pBuf->cbBuf - ASMAtomicReadZ(&pBuf->cbUsed); 186 184 if (cbFree > 0) 187 185 { 188 186 /* Get the size out of the requested size, the write block till the end 189 187 * of the buffer & the currently free size. */ 190 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf Size - pBuf->uWritePos, cbFree));188 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBuf - pBuf->offWrite, cbFree)); 191 189 if (cbSize > 0) 192 190 { 193 191 /* Return the pointer address which point to the current write 194 192 * position. */ 195 *ppvStart = (char*)pBuf->pvBuf + pBuf-> uWritePos;193 *ppvStart = (char*)pBuf->pvBuf + pBuf->offWrite; 196 194 *pcbSize = cbSize; 197 195 } … … 206 204 207 205 /* Split at the end of the buffer. */ 208 pBuf-> uWritePos = (pBuf->uWritePos + cbSize) % pBuf->cbBufSize;206 pBuf->offWrite = (pBuf->offWrite + cbSize) % pBuf->cbBuf; 209 207 210 208 size_t cbOldIgnored = 0; 211 ASMAtomicAddZ(&pBuf->cb BufUsed, cbSize);212 } 213 209 ASMAtomicAddZ(&pBuf->cbUsed, cbSize); 210 } 211
Note:
See TracChangeset
for help on using the changeset viewer.