Lines Matching defs:pCtxInt

73 # define rtFileAioCtxDump(pCtxInt) do {} while (0)
103 struct RTFILEAIOCTXINTERNAL *pCtxInt;
157 static void rtFileAioCtxWakeup(PRTFILEAIOCTXINTERNAL pCtxInt)
169 ASMAtomicReadHandle(&pCtxInt->hThreadWait, &hThread);
170 bool fWaiting = ASMAtomicReadBool(&pCtxInt->fWaiting);
192 static int rtFileAioCtxProcessEvents(PRTFILEAIOCTXINTERNAL pCtxInt)
197 bool fWokenUp = ASMAtomicXchgBool(&pCtxInt->fWokenUpInternal, false);
200 for (unsigned iSlot = 0; iSlot < RT_ELEMENTS(pCtxInt->apReqsNewHead); iSlot++)
202 PRTFILEAIOREQINTERNAL pReqHead = ASMAtomicXchgPtrT(&pCtxInt->apReqsNewHead[iSlot], NULL, PRTFILEAIOREQINTERNAL);
204 while ( (pCtxInt->iFirstFree < pCtxInt->cReqsWaitMax)
208 pCtxInt->apReqs[pCtxInt->iFirstFree] = pReqHead;
209 pReqHead->iWaitingList = pCtxInt->iFirstFree;
213 pCtxInt->apReqs[pCtxInt->iFirstFree]->pNext = NULL;
214 pCtxInt->apReqs[pCtxInt->iFirstFree]->pPrev = NULL;
215 pCtxInt->iFirstFree++;
217 Assert( (pCtxInt->iFirstFree <= pCtxInt->cMaxRequests)
218 && (pCtxInt->iFirstFree <= pCtxInt->cReqsWaitMax));
225 if (!pCtxInt->pReqsWaitHead)
227 Assert(!pCtxInt->pReqsWaitTail);
228 pCtxInt->pReqsWaitHead = pReqHead;
233 AssertPtr(pCtxInt->pReqsWaitTail);
235 pCtxInt->pReqsWaitTail->pNext = pReqHead;
236 pReqHead->pPrev = pCtxInt->pReqsWaitTail;
246 pCtxInt->pReqsWaitTail = pReqHead;
247 pCtxInt->pReqsWaitTail->pNext = NULL;
252 PRTFILEAIOREQINTERNAL pReqToCancel = ASMAtomicReadPtrT(&pCtxInt->pReqToCancel, PRTFILEAIOREQINTERNAL);
259 pCtxInt->apReqs[pReqToCancel->iWaitingList] = pCtxInt->apReqs[--pCtxInt->iFirstFree];
260 pCtxInt->apReqs[pReqToCancel->iWaitingList]->iWaitingList = pReqToCancel->iWaitingList;
273 pCtxInt->pReqsWaitTail = pPrev;
281 pCtxInt->pReqsWaitHead = pNext;
285 ASMAtomicDecS32(&pCtxInt->cRequests);
286 AssertMsg(pCtxInt->cRequests >= 0, ("Canceled request not which is not in this context\n"));
287 RTSemEventSignal(pCtxInt->SemEventCancel);
292 if (ASMAtomicXchgBool(&pCtxInt->fWokenUp, false))
359 pReqInt->pCtxInt = NULL;
416 pReqInt->pCtxInt = NULL;
482 PRTFILEAIOCTXINTERNAL pCtxInt = pReqInt->pCtxInt;
486 AssertMsg(VALID_PTR(pCtxInt),
489 Assert(!pCtxInt->pReqToCancel);
490 ASMAtomicWritePtr(&pCtxInt->pReqToCancel, pReqInt);
491 rtFileAioCtxWakeup(pCtxInt);
494 int rc = RTSemEventWait(pCtxInt->SemEventCancel, RT_INDEFINITE_WAIT);
497 ASMAtomicWriteNullPtr(&pCtxInt->pReqToCancel);
530 PRTFILEAIOCTXINTERNAL pCtxInt;
541 pCtxInt = (PRTFILEAIOCTXINTERNAL)RTMemAllocZ( sizeof(RTFILEAIOCTXINTERNAL)
543 if (RT_UNLIKELY(!pCtxInt))
547 int rc = RTSemEventCreate(&pCtxInt->SemEventCancel);
550 RTMemFree(pCtxInt);
554 pCtxInt->u32Magic = RTFILEAIOCTX_MAGIC;
555 pCtxInt->cMaxRequests = cAioReqsMax;
556 pCtxInt->cReqsWaitMax = cReqsWaitMax;
557 pCtxInt->fFlags = fFlags;
558 *phAioCtx = (RTFILEAIOCTX)pCtxInt;
566 PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
568 AssertPtrReturn(pCtxInt, VERR_INVALID_HANDLE);
570 if (RT_UNLIKELY(pCtxInt->cRequests))
573 RTSemEventDestroy(pCtxInt->SemEventCancel);
574 RTMemFree(pCtxInt);
582 PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
586 return pCtxInt->cMaxRequests;
599 static void rtFileAioCtxDump(PRTFILEAIOCTXINTERNAL pCtxInt)
601 LogFlow(("cRequests=%d\n", pCtxInt->cRequests));
602 LogFlow(("cMaxRequests=%u\n", pCtxInt->cMaxRequests));
603 LogFlow(("hThreadWait=%#p\n", pCtxInt->hThreadWait));
604 LogFlow(("fWokenUp=%RTbool\n", pCtxInt->fWokenUp));
605 LogFlow(("fWaiting=%RTbool\n", pCtxInt->fWaiting));
606 LogFlow(("fWokenUpInternal=%RTbool\n", pCtxInt->fWokenUpInternal));
607 for (unsigned i = 0; i < RT_ELEMENTS(pCtxInt->apReqsNewHead); i++)
608 LogFlow(("apReqsNewHead[%u]=%#p\n", i, pCtxInt->apReqsNewHead[i]));
609 LogFlow(("pReqToCancel=%#p\n", pCtxInt->pReqToCancel));
610 LogFlow(("pReqsWaitHead=%#p\n", pCtxInt->pReqsWaitHead));
611 LogFlow(("pReqsWaitTail=%#p\n", pCtxInt->pReqsWaitTail));
612 LogFlow(("cReqsWaitMax=%u\n", pCtxInt->cReqsWaitMax));
613 LogFlow(("iFirstFree=%u\n", pCtxInt->iFirstFree));
614 for (unsigned i = 0; i < pCtxInt->cReqsWaitMax; i++)
615 LogFlow(("apReqs[%u]=%#p\n", i, pCtxInt->apReqs[i]));
622 PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
625 AssertPtrReturn(pCtxInt, VERR_INVALID_HANDLE);
629 rtFileAioCtxDump(pCtxInt);
632 if (ASMAtomicUoReadS32(&pCtxInt->cRequests) + cReqs > pCtxInt->cMaxRequests)
655 pReqInt->pCtxInt = NULL;
672 pReqInt->pCtxInt = pCtxInt;
754 ASMAtomicAddS32(&pCtxInt->cRequests, cReqsSubmitted);
755 AssertMsg(pCtxInt->cRequests >= 0, ("Adding requests resulted in overflow\n"));
759 ASMAtomicAddS32(&pCtxInt->cRequests, cReqsSubmit);
760 AssertMsg(pCtxInt->cRequests >= 0, ("Adding requests resulted in overflow\n"));
807 ASMAtomicIncS32(&pCtxInt->cRequests);
808 AssertMsg(pCtxInt->cRequests >= 0, ("Adding requests resulted in overflow\n"));
824 while ( (iSlot < RT_ELEMENTS(pCtxInt->apReqsNewHead))
825 && !ASMAtomicCmpXchgPtr(&pCtxInt->apReqsNewHead[iSlot], pHead, NULL))
828 if (iSlot == RT_ELEMENTS(pCtxInt->apReqsNewHead))
831 PRTFILEAIOREQINTERNAL pOldHead = ASMAtomicXchgPtrT(&pCtxInt->apReqsNewHead[0], NULL, PRTFILEAIOREQINTERNAL);
840 ASMAtomicWritePtr(&pCtxInt->apReqsNewHead[0], pHead);
844 bool fWokenUp = ASMAtomicXchgBool(&pCtxInt->fWokenUpInternal, true);
846 rtFileAioCtxWakeup(pCtxInt);
849 rtFileAioCtxDump(pCtxInt);
860 PRTFILEAIOCTXINTERNAL pCtxInt = (PRTFILEAIOCTXINTERNAL)hAioCtx;
869 AssertPtrReturn(pCtxInt, VERR_INVALID_HANDLE);
875 rtFileAioCtxDump(pCtxInt);
877 int32_t cRequestsWaiting = ASMAtomicReadS32(&pCtxInt->cRequests);
880 && !(pCtxInt->fFlags & RTFILEAIOCTX_FLAGS_WAIT_WITHOUT_PENDING_REQUESTS))
899 Assert(pCtxInt->hThreadWait == NIL_RTTHREAD);
900 ASMAtomicWriteHandle(&pCtxInt->hThreadWait, RTThreadSelf());
903 rc = rtFileAioCtxProcessEvents(pCtxInt);
909 if (RT_UNLIKELY(!pCtxInt->iFirstFree))
911 for (unsigned i = 0; i < pCtxInt->cReqsWaitMax; i++)
912 RTAssertMsg2Weak("wait[%d] = %#p\n", i, pCtxInt->apReqs[i]);
915 pCtxInt->pReqsWaitHead, pCtxInt->pReqsWaitTail));
919 LogFlow(("Waiting for %d requests to complete\n", pCtxInt->iFirstFree));
920 rtFileAioCtxDump(pCtxInt);
922 ASMAtomicXchgBool(&pCtxInt->fWaiting, true);
923 int rcPosix = aio_suspend((const struct aiocb * const *)pCtxInt->apReqs,
924 pCtxInt->iFirstFree, pTimeout);
925 ASMAtomicXchgBool(&pCtxInt->fWaiting, false);
928 LogFlow(("aio_suspend failed %d nent=%u\n", errno, pCtxInt->iFirstFree));
931 rc = rtFileAioCtxProcessEvents(pCtxInt);
942 while ( (iReqCurr < pCtxInt->iFirstFree)
945 PRTFILEAIOREQINTERNAL pReq = pCtxInt->apReqs[iReqCurr];
971 if (pCtxInt->pReqsWaitHead)
973 PRTFILEAIOREQINTERNAL pReqInsert = pCtxInt->pReqsWaitHead;
975 pCtxInt->pReqsWaitHead = pReqInsert->pNext;
976 if (!pCtxInt->pReqsWaitHead)
979 pCtxInt->pReqsWaitTail = NULL;
983 pCtxInt->apReqs[pReqInsert->iWaitingList] = pReqInsert;
992 if (pReq->iWaitingList < pCtxInt->iFirstFree - 1)
994 pCtxInt->apReqs[pReq->iWaitingList] = pCtxInt->apReqs[--pCtxInt->iFirstFree];
995 pCtxInt->apReqs[pReq->iWaitingList]->iWaitingList = pReq->iWaitingList;
998 pCtxInt->iFirstFree--;
1000 pCtxInt->apReqs[pCtxInt->iFirstFree] = NULL;
1015 ASMAtomicSubS32(&pCtxInt->cRequests, cDone);
1017 AssertMsg(pCtxInt->cRequests >= 0, ("Finished more requests than currently active\n"));
1033 rc = rtFileAioCtxProcessEvents(pCtxInt);
1038 Assert(pCtxInt->hThreadWait == RTThreadSelf());
1039 ASMAtomicWriteHandle(&pCtxInt->hThreadWait, NIL_RTTHREAD);
1041 rtFileAioCtxDump(pCtxInt);
1049 PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
1050 RTFILEAIOCTX_VALID_RETURN(pCtxInt);
1055 bool fWokenUp = ASMAtomicXchgBool(&pCtxInt->fWokenUp, true);
1057 rtFileAioCtxWakeup(pCtxInt);