Lines Matching refs:p
26 void MtProgress_Init(CMtProgress *p, ICompressProgress *progress) in MtProgress_Init() argument
28 p->progress = progress; in MtProgress_Init()
29 p->res = SZ_OK; in MtProgress_Init()
30 p->totalInSize = 0; in MtProgress_Init()
31 p->totalOutSize = 0; in MtProgress_Init()
35 SRes MtProgress_Progress_ST(CMtProgress *p) in MtProgress_Progress_ST() argument
37 if (p->res == SZ_OK && p->progress) in MtProgress_Progress_ST()
38 if (ICompressProgress_Progress(p->progress, p->totalInSize, p->totalOutSize) != SZ_OK) in MtProgress_Progress_ST()
39 p->res = SZ_ERROR_PROGRESS; in MtProgress_Progress_ST()
40 return p->res; in MtProgress_Progress_ST()
44 SRes MtProgress_ProgressAdd(CMtProgress *p, UInt64 inSize, UInt64 outSize) in MtProgress_ProgressAdd() argument
47 CriticalSection_Enter(&p->cs); in MtProgress_ProgressAdd()
49 p->totalInSize += inSize; in MtProgress_ProgressAdd()
50 p->totalOutSize += outSize; in MtProgress_ProgressAdd()
51 if (p->res == SZ_OK && p->progress) in MtProgress_ProgressAdd()
52 if (ICompressProgress_Progress(p->progress, p->totalInSize, p->totalOutSize) != SZ_OK) in MtProgress_ProgressAdd()
53 p->res = SZ_ERROR_PROGRESS; in MtProgress_ProgressAdd()
54 res = p->res; in MtProgress_ProgressAdd()
56 CriticalSection_Leave(&p->cs); in MtProgress_ProgressAdd()
61 SRes MtProgress_GetError(CMtProgress *p) in MtProgress_GetError() argument
64 CriticalSection_Enter(&p->cs); in MtProgress_GetError()
65 res = p->res; in MtProgress_GetError()
66 CriticalSection_Leave(&p->cs); in MtProgress_GetError()
71 void MtProgress_SetError(CMtProgress *p, SRes res) in MtProgress_SetError() argument
73 CriticalSection_Enter(&p->cs); in MtProgress_SetError()
74 if (p->res == SZ_OK) in MtProgress_SetError()
75 p->res = res; in MtProgress_SetError()
76 CriticalSection_Leave(&p->cs); in MtProgress_SetError()
83 static WRes ArEvent_OptCreate_And_Reset(CEvent *p) in ArEvent_OptCreate_And_Reset() argument
85 if (Event_IsCreated(p)) in ArEvent_OptCreate_And_Reset()
86 return Event_Reset(p); in ArEvent_OptCreate_And_Reset()
87 return AutoResetEvent_CreateNotSignaled(p); in ArEvent_OptCreate_And_Reset()
166 static void MtDec_CloseThreads(CMtDec *p) in MtDec_CloseThreads() argument
170 MtDecThread_CloseThread(&p->threads[i]); in MtDec_CloseThreads()
200 static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, BoolInt *wasInterrupted) in MtDec_GetError_Spec() argument
203 CriticalSection_Enter(&p->mtProgress.cs); in MtDec_GetError_Spec()
204 *wasInterrupted = (p->needInterrupt && interruptIndex > p->interruptIndex); in MtDec_GetError_Spec()
205 res = p->mtProgress.res; in MtDec_GetError_Spec()
206 CriticalSection_Leave(&p->mtProgress.cs); in MtDec_GetError_Spec()
210 static SRes MtDec_Progress_GetError_Spec(CMtDec *p, UInt64 inSize, UInt64 outSize, UInt64 interrupt… in MtDec_Progress_GetError_Spec() argument
213 CriticalSection_Enter(&p->mtProgress.cs); in MtDec_Progress_GetError_Spec()
215 p->mtProgress.totalInSize += inSize; in MtDec_Progress_GetError_Spec()
216 p->mtProgress.totalOutSize += outSize; in MtDec_Progress_GetError_Spec()
217 if (p->mtProgress.res == SZ_OK && p->mtProgress.progress) in MtDec_Progress_GetError_Spec()
218 …if (ICompressProgress_Progress(p->mtProgress.progress, p->mtProgress.totalInSize, p->mtProgress.to… in MtDec_Progress_GetError_Spec()
219 p->mtProgress.res = SZ_ERROR_PROGRESS; in MtDec_Progress_GetError_Spec()
221 *wasInterrupted = (p->needInterrupt && interruptIndex > p->interruptIndex); in MtDec_Progress_GetError_Spec()
222 res = p->mtProgress.res; in MtDec_Progress_GetError_Spec()
224 CriticalSection_Leave(&p->mtProgress.cs); in MtDec_Progress_GetError_Spec()
229 static void MtDec_Interrupt(CMtDec *p, UInt64 interruptIndex) in MtDec_Interrupt() argument
231 CriticalSection_Enter(&p->mtProgress.cs); in MtDec_Interrupt()
232 if (!p->needInterrupt || interruptIndex < p->interruptIndex) in MtDec_Interrupt()
234 p->interruptIndex = interruptIndex; in MtDec_Interrupt()
235 p->needInterrupt = True; in MtDec_Interrupt()
237 CriticalSection_Leave(&p->mtProgress.cs); in MtDec_Interrupt()
240 Byte *MtDec_GetCrossBuff(CMtDec *p) in MtDec_GetCrossBuff() argument
242 Byte *cr = p->crossBlock; in MtDec_GetCrossBuff()
245 cr = (Byte *)ISzAlloc_Alloc(p->alloc, MTDEC__LINK_DATA_OFFSET + p->inBufSize); in MtDec_GetCrossBuff()
248 p->crossBlock = cr; in MtDec_GetCrossBuff()
265 CMtDec *p = t->mtDec; in ThreadFunc2() local
299 if (p->exitThread) in ThreadFunc2()
306 blockIndex = p->blockIndex++; in ThreadFunc2()
310 res = MtDec_Progress_GetError_Spec(p, 0, 0, blockIndex, &wasInterrupted); in ThreadFunc2()
312 finish = p->readWasFinished; in ThreadFunc2()
328 size_t crossSize = p->crossEnd - p->crossStart; in ThreadFunc2()
336 … link = (CMtDecBufLink *)ISzAlloc_Alloc(p->alloc, MTDEC__LINK_DATA_OFFSET + p->inBufSize); in ThreadFunc2()
366 parseData = MTDEC__DATA_PTR_FROM_LINK(p->crossBlock) + p->crossStart; in ThreadFunc2()
368 (int)p->crossStart, (int)p->crossEnd, (int)finish)); in ThreadFunc2()
372 size = p->inBufSize; in ThreadFunc2()
374 res = FullRead(p->inStream, data, &size); in ThreadFunc2()
383 p->readProcessed += size; in ThreadFunc2()
384 finish = (size != p->inBufSize); in ThreadFunc2()
386 p->readWasFinished = True; in ThreadFunc2()
394 p->readRes = res; in ThreadFunc2()
396 p->readWasFinished = True; in ThreadFunc2()
404 res = MtDec_Progress_GetError_Spec(p, 0, 0, blockIndex, &wasInterrupted); in ThreadFunc2()
422 p->mtCallback->Parse(p->mtCallbackObject, t->index, &parse); in ThreadFunc2()
449 p->crossStart = 0; in ThreadFunc2()
450 p->crossEnd = 0; in ThreadFunc2()
457 p->crossStart += parse.srcSize; in ThreadFunc2()
473 p->crossStart = 0; in ThreadFunc2()
474 p->crossEnd = 0; in ThreadFunc2()
480 p->crossStart = 0; in ThreadFunc2()
481 p->crossEnd = 0; in ThreadFunc2()
502 Byte *cr = MtDec_GetCrossBuff(p); in ThreadFunc2()
518 p->crossEnd = crSize; in ThreadFunc2()
519 p->crossStart = 0; in ThreadFunc2()
548 p->crossStart = 0; in ThreadFunc2()
549 p->crossEnd = 0; in ThreadFunc2()
555 res = MtDec_GetError_Spec(p, blockIndex, &wasInterrupted); in ThreadFunc2()
562 codeRes = p->mtCallback->PreCode(p->mtCallbackObject, t->index); in ThreadFunc2()
581 if (p->numStartedThreads < p->numStartedThreads_Limit && canCreateNewThread) in ThreadFunc2()
583 SRes res2 = MtDecThread_CreateAndStart(&p->threads[p->numStartedThreads]); in ThreadFunc2()
587 p->numStartedThreads++; in ThreadFunc2()
591 PRF(printf("\nERROR: numStartedThreads=%d\n", p->numStartedThreads)); in ThreadFunc2()
592 if (p->numStartedThreads == 1) in ThreadFunc2()
600 p->numStartedThreads_Limit = p->numStartedThreads; in ThreadFunc2()
607 nextThread = &p->threads[nextIndex >= p->numStartedThreads ? 0 : nextIndex]; in ThreadFunc2()
645 inSize = p->inBufSize; in ThreadFunc2()
653 codeRes = p->mtCallback->Code(p->mtCallbackObject, t->index, in ThreadFunc2()
662 MtDec_Interrupt(p, blockIndex); in ThreadFunc2()
675 res = MtDec_Progress_GetError_Spec(p, inDelta, outDelta, blockIndex, &wasInterrupted); in ThreadFunc2()
698 if (p->exitThread) return 0; // it's never executed in normal cases in ThreadFunc2()
700 if (p->wasInterrupted) in ThreadFunc2()
706 p->wasInterrupted = True; in ThreadFunc2()
707 p->codeRes = codeRes; in ThreadFunc2()
714 p->wasInterrupted = True; in ThreadFunc2()
715 p->threadingErrorSRes = threadingErrorSRes; in ThreadFunc2()
720 p->wasInterrupted = True; in ThreadFunc2()
721 p->isAllocError = True; in ThreadFunc2()
726 p->wasInterrupted = True; in ThreadFunc2()
727 p->overflow = True; in ThreadFunc2()
743 res = MtProgress_ProgressAdd(&p->mtProgress, inDelta, outDelta); in ThreadFunc2()
754 res = p->mtCallback->Write(p->mtCallbackObject, t->index, in ThreadFunc2()
763 PRF(printf("\nprocessed = %d\n", (unsigned)p->inProcessed)); in ThreadFunc2()
769 p->wasInterrupted = True; in ThreadFunc2()
775 MtDec_Interrupt(p, blockIndex); in ThreadFunc2()
782 || p->wasInterrupted in ThreadFunc2()
785 || p->numFilledThreads != 0 in ThreadFunc2()
788 if (p->numFilledThreads == 0) in ThreadFunc2()
789 p->filledThreadStart = t->index; in ThreadFunc2()
794 p->numFilledThreads++; in ThreadFunc2()
796 PRF(printf("\np->numFilledThreads = %d\n", p->numFilledThreads)); in ThreadFunc2()
797 PRF(printf("p->filledThreadStart = %d\n", p->filledThreadStart)); in ThreadFunc2()
809 RINOK_THREAD(Event_Set(&p->threads[0].canWrite)); in ThreadFunc2()
816 p->exitThread = True; in ThreadFunc2()
818 RINOK_THREAD(Event_Set(&p->threads[0].canRead)); in ThreadFunc2()
842 CMtDec *p; in ThreadFunc1() local
847 p = t->mtDec; in ThreadFunc1()
849 return p->exitThreadWRes; in ThreadFunc1()
852 if (p->exitThreadWRes == 0) in ThreadFunc1()
853 p->exitThreadWRes = res; in ThreadFunc1()
855 p->exitThread = True; in ThreadFunc1()
856 Event_Set(&p->threads[0].canRead); in ThreadFunc1()
857 Event_Set(&p->threads[0].canWrite); in ThreadFunc1()
858 MtProgress_SetError(&p->mtProgress, MY_SRes_HRESULT_FROM_WRes(res)); in ThreadFunc1()
875 int MtDec_PrepareRead(CMtDec *p) in MtDec_PrepareRead() argument
877 if (p->crossBlock && p->crossStart == p->crossEnd) in MtDec_PrepareRead()
879 ISzAlloc_Free(p->alloc, p->crossBlock); in MtDec_PrepareRead()
880 p->crossBlock = NULL; in MtDec_PrepareRead()
886 if (i > p->numStartedThreads in MtDec_PrepareRead()
887 || p->numFilledThreads <= in MtDec_PrepareRead()
888 (i >= p->filledThreadStart ? in MtDec_PrepareRead()
889 i - p->filledThreadStart : in MtDec_PrepareRead()
890 i + p->numStartedThreads - p->filledThreadStart)) in MtDec_PrepareRead()
891 MtDecThread_FreeInBufs(&p->threads[i]); in MtDec_PrepareRead()
894 return (p->numFilledThreads != 0) || (p->crossStart != p->crossEnd); in MtDec_PrepareRead()
898 const Byte *MtDec_Read(CMtDec *p, size_t *inLim) in MtDec_Read() argument
900 while (p->numFilledThreads != 0) in MtDec_Read()
902 CMtDecThread *t = &p->threads[p->filledThreadStart]; in MtDec_Read()
909 ISzAlloc_Free(p->alloc, link); in MtDec_Read()
916 if (--p->numFilledThreads == 0) in MtDec_Read()
918 if (++p->filledThreadStart == p->numStartedThreads) in MtDec_Read()
919 p->filledThreadStart = 0; in MtDec_Read()
920 t = &p->threads[p->filledThreadStart]; in MtDec_Read()
931 lim = p->inBufSize; in MtDec_Read()
942 size_t crossSize = p->crossEnd - p->crossStart; in MtDec_Read()
945 const Byte *data = MTDEC__DATA_PTR_FROM_LINK(p->crossBlock) + p->crossStart; in MtDec_Read()
947 p->crossStart = 0; in MtDec_Read()
948 p->crossEnd = 0; in MtDec_Read()
952 if (p->crossBlock) in MtDec_Read()
954 ISzAlloc_Free(p->alloc, p->crossBlock); in MtDec_Read()
955 p->crossBlock = NULL; in MtDec_Read()
962 void MtDec_Construct(CMtDec *p) in MtDec_Construct() argument
966 p->inBufSize = (size_t)1 << 18; in MtDec_Construct()
968 p->numThreadsMax = 0; in MtDec_Construct()
970 p->inStream = NULL; in MtDec_Construct()
975 p->crossBlock = NULL; in MtDec_Construct()
976 p->crossStart = 0; in MtDec_Construct()
977 p->crossEnd = 0; in MtDec_Construct()
979 p->numFilledThreads = 0; in MtDec_Construct()
981 p->progress = NULL; in MtDec_Construct()
982 p->alloc = NULL; in MtDec_Construct()
984 p->mtCallback = NULL; in MtDec_Construct()
985 p->mtCallbackObject = NULL; in MtDec_Construct()
987 p->allocatedBufsSize = 0; in MtDec_Construct()
991 CMtDecThread *t = &p->threads[i]; in MtDec_Construct()
992 t->mtDec = p; in MtDec_Construct()
1002 CriticalSection_Init(&p->mtProgress.cs); in MtDec_Construct()
1006 static void MtDec_Free(CMtDec *p) in MtDec_Free() argument
1010 p->exitThread = True; in MtDec_Free()
1013 MtDecThread_Destruct(&p->threads[i]); in MtDec_Free()
1017 if (p->crossBlock) in MtDec_Free()
1019 ISzAlloc_Free(p->alloc, p->crossBlock); in MtDec_Free()
1020 p->crossBlock = NULL; in MtDec_Free()
1025 void MtDec_Destruct(CMtDec *p) in MtDec_Destruct() argument
1027 MtDec_Free(p); in MtDec_Destruct()
1029 CriticalSection_Delete(&p->mtProgress.cs); in MtDec_Destruct()
1033 SRes MtDec_Code(CMtDec *p) in MtDec_Code() argument
1037 p->inProcessed = 0; in MtDec_Code()
1039 p->blockIndex = 1; // it must be larger than not_defined index (0) in MtDec_Code()
1040 p->isAllocError = False; in MtDec_Code()
1041 p->overflow = False; in MtDec_Code()
1042 p->threadingErrorSRes = SZ_OK; in MtDec_Code()
1044 p->needContinue = True; in MtDec_Code()
1046 p->readWasFinished = False; in MtDec_Code()
1047 p->needInterrupt = False; in MtDec_Code()
1048 p->interruptIndex = (UInt64)(Int64)-1; in MtDec_Code()
1050 p->readProcessed = 0; in MtDec_Code()
1051 p->readRes = SZ_OK; in MtDec_Code()
1052 p->codeRes = SZ_OK; in MtDec_Code()
1053 p->wasInterrupted = False; in MtDec_Code()
1055 p->crossStart = 0; in MtDec_Code()
1056 p->crossEnd = 0; in MtDec_Code()
1058 p->filledThreadStart = 0; in MtDec_Code()
1059 p->numFilledThreads = 0; in MtDec_Code()
1062 unsigned numThreads = p->numThreadsMax; in MtDec_Code()
1065 p->numStartedThreads_Limit = numThreads; in MtDec_Code()
1066 p->numStartedThreads = 0; in MtDec_Code()
1069 if (p->inBufSize != p->allocatedBufsSize) in MtDec_Code()
1073 CMtDecThread *t = &p->threads[i]; in MtDec_Code()
1077 if (p->crossBlock) in MtDec_Code()
1079 ISzAlloc_Free(p->alloc, p->crossBlock); in MtDec_Code()
1080 p->crossBlock = NULL; in MtDec_Code()
1083 p->allocatedBufsSize = p->inBufSize; in MtDec_Code()
1086 MtProgress_Init(&p->mtProgress, p->progress); in MtDec_Code()
1089 p->exitThread = False; in MtDec_Code()
1090 p->exitThreadWRes = 0; in MtDec_Code()
1095 CMtDecThread *nextThread = &p->threads[p->numStartedThreads++]; in MtDec_Code()
1103 p->needContinue = False; in MtDec_Code()
1104 MtDec_CloseThreads(p); in MtDec_Code()
1113 p->threadingErrorSRes = sres; in MtDec_Code()
1119 p->isAllocError in MtDec_Code()
1120 || p->threadingErrorSRes != SZ_OK in MtDec_Code()
1121 || p->overflow) in MtDec_Code()
1126 p->needContinue = False; in MtDec_Code()
1128 if (p->needContinue) in MtDec_Code()