Changeset 37208 in vbox for trunk/src/VBox
- Timestamp:
- May 25, 2011 9:22:18 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/circbuf.cpp
r33286 r37208 26 26 27 27 28 /****************************************************************************** 29 * Header Files*30 28 /******************************************************************************* 29 * Header Files * 30 *******************************************************************************/ 31 31 #include <iprt/circbuf.h> 32 32 #include <iprt/mem.h> … … 35 35 #include <iprt/err.h> 36 36 37 /******************************************************************************38 * Public Functions *39 ******************************************************************************/40 37 41 38 RTDECL(int) RTCircBufCreate(PRTCIRCBUF *ppBuf, size_t cbSize) … … 50 47 return VERR_NO_MEMORY; 51 48 52 int rc = VINF_SUCCESS;53 do49 pTmpBuf->pvBuf = RTMemAlloc(cbSize); 50 if (pTmpBuf->pvBuf) 54 51 { 55 pTmpBuf->pvBuf = RTMemAlloc(cbSize);56 if (!pTmpBuf)57 {58 rc = VERR_NO_MEMORY;59 break;60 }61 62 52 pTmpBuf->cbBufSize = cbSize; 63 53 *ppBuf = pTmpBuf; 64 }while (0);65 66 if (RT_FAILURE(rc)) 67 68 69 return rc; 70 } 54 return VINF_SUCCESS; 55 } 56 57 RTMemFree(pTmpBuf); 58 return VERR_NO_MEMORY; 59 } 60 71 61 72 62 RTDECL(void) RTCircBufDestroy(PRTCIRCBUF pBuf) 73 63 { 74 64 /* Validate input. */ 75 AssertPtrNull(pBuf); 76 77 if (pBuf) 78 { 79 if (pBuf->pvBuf) 80 RTMemFree(pBuf->pvBuf); 81 RTMemFree(pBuf); 82 } 83 } 65 if (!pBuf) 66 return; 67 AssertPtr(pBuf); 68 RTMemFree(pBuf->pvBuf); 69 RTMemFree(pBuf); 70 } 71 84 72 85 73 RTDECL(void) RTCircBufReset(PRTCIRCBUF pBuf) … … 88 76 AssertPtr(pBuf); 89 77 90 pBuf->uReadPos = 0;78 pBuf->uReadPos = 0; 91 79 pBuf->uWritePos = 0; 92 80 pBuf->cbBufUsed = 0; 93 81 } 82 94 83 95 84 RTDECL(size_t) RTCircBufFree(PRTCIRCBUF pBuf) … … 103 92 } 104 93 94 105 95 RTDECL(size_t) RTCircBufUsed(PRTCIRCBUF pBuf) 106 96 { … … 113 103 } 114 104 105 115 106 RTDECL(size_t) RTCircBufSize(PRTCIRCBUF pBuf) 116 107 { … … 120 111 return pBuf->cbBufSize; 121 112 } 113 122 114 123 115 RTDECL(void) RTCircBufAcquireReadBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize) … … 146 138 /* Return the pointer address which point to the current read 147 139 * position. */ 148 *ppvStart = (char *)pBuf->pvBuf + pBuf->uReadPos;140 *ppvStart = (char *)pBuf->pvBuf + pBuf->uReadPos; 149 141 *pcbSize = uSize; 150 142 } … … 152 144 } 153 145 146 154 147 RTDECL(void) RTCircBufReleaseReadBlock(PRTCIRCBUF pBuf, size_t cbSize) 155 148 { … … 163 156 ASMAtomicSubSize(&pBuf->cbBufUsed, cbSize, &cbOld); 164 157 } 158 165 159 166 160 RTDECL(void) RTCircBufAcquireWriteBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize) … … 172 166 AssertPtr(pcbSize); 173 167 174 size_t uFree;175 size_t uSize;176 177 168 *ppvStart = 0; 178 169 *pcbSize = 0; … … 181 172 size_t cbSize = 0; 182 173 ASMAtomicReadSize(&pBuf->cbBufUsed, &cbSize); 183 uFree = pBuf->cbBufSize - cbSize;174 size_t uFree = pBuf->cbBufSize - cbSize; 184 175 if (uFree > 0) 185 176 { 186 177 /* Get the size out of the requested size, the write block till the end 187 178 * of the buffer & the currently free size. */ 188 uSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uWritePos, uFree));179 size_t uSize = RT_MIN(cbReqSize, RT_MIN(pBuf->cbBufSize - pBuf->uWritePos, uFree)); 189 180 if (uSize > 0) 190 181 { … … 197 188 } 198 189 190 199 191 RTDECL(void) RTCircBufReleaseWriteBlock(PRTCIRCBUF pBuf, size_t cbSize) 200 192 { … … 205 197 pBuf->uWritePos = (pBuf->uWritePos + cbSize) % pBuf->cbBufSize; 206 198 207 size_t cbOld = 0;208 ASMAtomicAddSize(&pBuf->cbBufUsed, cbSize, &cbOld );209 } 210 199 size_t cbOldIgnored = 0; 200 ASMAtomicAddSize(&pBuf->cbBufUsed, cbSize, &cbOldIgnored); 201 } 202
Note:
See TracChangeset
for help on using the changeset viewer.