Changeset 59729 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Feb 19, 2016 12:31:35 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/vfs/vfsreadahead.cpp
r59706 r59729 52 52 #include <iprt/err.h> 53 53 #include <iprt/mem.h> 54 #include <iprt/sempahore.h>55 54 #include <iprt/thread.h> 56 57 58 /*********************************************************************************************************************************59 * Defined Constants And Macros *60 *********************************************************************************************************************************/61 55 62 56 … … 79 73 uint32_t volatile fReserved; 80 74 /** Pointer to the buffer. */ 81 uint8_t *pbBuffer 75 uint8_t *pbBuffer; 82 76 } RTVFSREADAHEADBUFDESC; 83 77 /** Pointer to a memory file extent. */ … … 163 157 RTVfsIoStrmRelease(pThis->hIos); 164 158 pThis->hIos = NIL_RTVFSIOSTREAM; 165 RTVfsFileRel ase(pThis->hFile);159 RTVfsFileRelease(pThis->hFile); 166 160 pThis->hFile = NIL_RTVFSFILE; 167 161 … … 195 189 { 196 190 PRTVFSREADAHEAD pThis = (PRTVFSREADAHEAD)pvThis; 197 return RTVfsIoStrmQueryInfo(pThis->h Vfs, pObjInfo, enmAddAttr);191 return RTVfsIoStrmQueryInfo(pThis->hIos, pObjInfo, enmAddAttr); 198 192 } 199 193 … … 215 209 * section, just in case a buffer got inserted while we were waiting for it. 216 210 */ 217 int rc ;211 int rc = VINF_SUCCESS; 218 212 size_t cbTotalRead = 0; 219 213 bool fPokeReader = false; … … 232 226 } 233 227 234 RTListForEach(&pThis->ConsumerList, pCurBufDesc, Type, ListEntry) 228 PRTVFSREADAHEADBUFDESC pCurBufDesc; 229 RTListForEach(&pThis->ConsumerList, pCurBufDesc, RTVFSREADAHEADBUFDESC, ListEntry) 235 230 { 236 231 if (pThis->offConsumer) … … 258 253 * Do a direct read of the remaining data. 259 254 */ 260 size_t cbDirectRead;255 //size_t cbDirectRead; 261 256 262 257 … … 307 302 return VERR_NOT_IMPLEMENTED; 308 303 } 309 return RTVfsIoStrmPoll(pThis->h Vfs, fEvents, cMillies, fIntr, pfRetEvents);304 return RTVfsIoStrmPoll(pThis->hIos, fEvents, cMillies, fIntr, pfRetEvents); 310 305 } 311 306 … … 534 529 { 535 530 do 536 pAfter = RTListGetPrev(&pThis->ConsumerList, &pAfter->ListEntry, RTVFSREADAHEADBUFDESC, ListEntry);531 pAfter = RTListGetPrev(&pThis->ConsumerList, pAfter, RTVFSREADAHEADBUFDESC, ListEntry); 537 532 while (pAfter && pAfter->off > pBufDesc->off); 538 533 if (!pAfter) … … 580 575 */ 581 576 int rc = VINF_SUCCESS; 582 AssertStmt(cBuffers < _ 8K, rc = VERR_OUT_OF_RANGE);577 AssertStmt(cBuffers < _4K, rc = VERR_OUT_OF_RANGE); 583 578 if (cBuffers == 0) 584 579 cBuffers = 4; 585 AssertStmt(cbBuffer < 580 AssertStmt(cbBuffer <= _512K, rc = VERR_OUT_OF_RANGE); 586 581 if (cbBuffer == 0) 587 582 cbBuffer = _256K / cBuffers; … … 597 592 PRTVFSREADAHEAD pThis; 598 593 size_t cbThis = RT_OFFSETOF(RTVFSREADAHEAD, aBufDescs[cBuffers]); 599 if (hVfsFile != NIL_RTVFSFILE)594 if (hVfsFileSrc != NIL_RTVFSFILE) 600 595 rc = RTVfsNewFile(&g_VfsReadAheadFileOps, cbThis, RTFILE_O_READ, NIL_RTVFS, NIL_RTVFSLOCK, 601 596 &hVfsFileReadAhead, (void **)&pThis); … … 615 610 pThis->cbBuffer = cbBuffer; 616 611 pThis->offConsumer = RTVfsIoStrmTell(hVfsIosSrc); 617 pThis->offActual = pThis->offConsumer;618 612 if ((RTFOFF)pThis->offConsumer >= 0) 619 613 { 620 rc = RTCritSectInit(&pThis-> BufferCritSect);614 rc = RTCritSectInit(&pThis->IoCritSect); 621 615 if (RT_SUCCESS(rc)) 622 rc = RTCritSectInit(&pThis-> ConsumerList);616 rc = RTCritSectInit(&pThis->BufferCritSect); 623 617 if (RT_SUCCESS(rc)) 624 618 { 625 pThis->pbAllBuffers = RTMemPageAlloc(pThis->cbBuffer * pThis->cBuffers);619 pThis->pbAllBuffers = (uint8_t *)RTMemPageAlloc(pThis->cbBuffer * pThis->cBuffers); 626 620 if (pThis->pbAllBuffers) 627 621 { … … 646 640 if (phVfsFile) 647 641 *phVfsFile = hVfsFileReadAhead; 648 else if (hVfsFileReadAhead == NIL_RT FILE)642 else if (hVfsFileReadAhead == NIL_RTVFSFILE) 649 643 *phVfsIos = hVfsIosReadAhead; 650 644 else … … 674 668 { 675 669 AssertPtrReturn(phVfsIos, VERR_INVALID_POINTER); 676 phVfsIos = NIL_RTVFSIOSTREAM;670 *phVfsIos = NIL_RTVFSIOSTREAM; 677 671 678 672 /* … … 684 678 RTVFSFILE hVfsFile = RTVfsIoStrmToFile(hVfsIos); 685 679 686 return rtVfsCreateReadAheadInstance(hVfsIos, hVfsFile, fFlags, cBuffers, cbBuffer, phVfsIos); 680 /* 681 * Do the job. (This always consumes the above retained references.) 682 */ 683 return rtVfsCreateReadAheadInstance(hVfsIos, hVfsFile, fFlags, cBuffers, cbBuffer, phVfsIos, NULL); 687 684 } 688 685 … … 691 688 PRTVFSFILE phVfsFile) 692 689 { 693 AssertPtrReturn(phVfs Ios, VERR_INVALID_POINTER);690 AssertPtrReturn(phVfsFile, VERR_INVALID_POINTER); 694 691 *phVfsFile = NIL_RTVFSFILE; 695 692 … … 699 696 RTVFSIOSTREAM hVfsIos = RTVfsFileToIoStream(hVfsFile); 700 697 AssertReturn(hVfsIos != NIL_RTVFSIOSTREAM, VERR_INVALID_HANDLE); 701 uint32_t cRefs = RTVfsFileRetain(hVfs Ios);698 uint32_t cRefs = RTVfsFileRetain(hVfsFile); 702 699 AssertReturnStmt(cRefs != UINT32_MAX, RTVfsIoStrmRelease(hVfsIos), VERR_INVALID_HANDLE); 703 700 704 701 /* 705 * Create a read ahead instance and cast it to a file before returning. 706 */ 707 RTVFSIOSTREAM hVfsIosReadAhead; 708 int rc = rtVfsCreateReadAheadInstance(hVfsIos, hVfsFile, fFlags, cBuffers, cbBuffer, &hVfsIosReadAhead); 709 if (RT_SUCCESS(rc)) 710 { 711 *phVfsFile = RTVfsIoStrmToFile(hVfsIosReadAhead); 712 RTVfsIoStrmRelease(hVfsIosReadAhead); 713 AssertReturn(*phVfsFile != NIL_RTVFSFILE, VERR_INTERNAL_ERROR_5); 714 } 715 716 return rc; 717 } 718 702 * Do the job. (This always consumes the above retained references.) 703 */ 704 return rtVfsCreateReadAheadInstance(hVfsIos, hVfsFile, fFlags, cBuffers, cbBuffer, NULL, phVfsFile); 705 } 706
Note:
See TracChangeset
for help on using the changeset viewer.