Changeset 37209 in vbox for trunk/src/VBox
- Timestamp:
- May 25, 2011 9:33:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/circbuf.cpp
r37208 r37209 87 87 AssertPtrReturn(pBuf, 0); 88 88 89 size_t cbSize = 0; 90 ASMAtomicReadSize(&pBuf->cbBufUsed, &cbSize); 91 return pBuf->cbBufSize - cbSize; 89 return pBuf->cbBufSize - ASMAtomicReadZ(&pBuf->cbBufUsed); 92 90 } 93 91 … … 98 96 AssertPtrReturn(pBuf, 0); 99 97 100 size_t cbSize = 0; 101 ASMAtomicReadSize(&pBuf->cbBufUsed, &cbSize); 102 return cbSize; 98 return ASMAtomicReadZ(&pBuf->cbBufUsed); 103 99 } 104 100 … … 121 117 AssertPtr(pcbSize); 122 118 123 size_t uUsed = 0;124 size_t uSize = 0;125 126 119 *ppvStart = 0; 127 120 *pcbSize = 0; 128 121 129 122 /* How much is in use? */ 130 ASMAtomicReadSize(&pBuf->cbBufUsed, &uUsed);131 if ( uUsed > 0)123 size_t cbUsed = ASMAtomicReadZ(&pBuf->cbBufUsed); 124 if (cbUsed > 0) 132 125 { 133 126 /* Get the size out of the requested size, the read block till the end 134 127 * of the buffer & the currently used size. */ 135 uSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uReadPos, uUsed));136 if ( uSize > 0)128 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uReadPos, cbUsed)); 129 if (cbSize > 0) 137 130 { 138 131 /* Return the pointer address which point to the current read 139 132 * position. */ 140 133 *ppvStart = (char *)pBuf->pvBuf + pBuf->uReadPos; 141 *pcbSize = uSize;134 *pcbSize = cbSize; 142 135 } 143 136 } … … 153 146 pBuf->uReadPos = (pBuf->uReadPos + cbSize) % pBuf->cbBufSize; 154 147 155 size_t cbOld = 0; 156 ASMAtomicSubSize(&pBuf->cbBufUsed, cbSize, &cbOld); 148 ASMAtomicSubZ(&pBuf->cbBufUsed, cbSize); 157 149 } 158 150 … … 170 162 171 163 /* How much is free? */ 172 size_t cbSize = 0; 173 ASMAtomicReadSize(&pBuf->cbBufUsed, &cbSize); 174 size_t uFree = pBuf->cbBufSize - cbSize; 175 if (uFree > 0) 164 size_t cbFree = pBuf->cbBufSize - ASMAtomicReadZ(&pBuf->cbBufUsed); 165 if (cbFree > 0) 176 166 { 177 167 /* Get the size out of the requested size, the write block till the end 178 168 * of the buffer & the currently free size. */ 179 size_t uSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uWritePos, uFree));180 if ( uSize > 0)169 size_t cbSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uWritePos, cbFree)); 170 if (cbSize > 0) 181 171 { 182 172 /* Return the pointer address which point to the current write 183 173 * position. */ 184 174 *ppvStart = (char*)pBuf->pvBuf + pBuf->uWritePos; 185 *pcbSize = uSize;175 *pcbSize = cbSize; 186 176 } 187 177 } … … 198 188 199 189 size_t cbOldIgnored = 0; 200 ASMAtomicAdd Size(&pBuf->cbBufUsed, cbSize, &cbOldIgnored);190 ASMAtomicAddZ(&pBuf->cbBufUsed, cbSize); 201 191 } 202 192
Note:
See TracChangeset
for help on using the changeset viewer.