Lines Matching refs:p
8 void LoopThread_Construct(CLoopThread *p) in LoopThread_Construct() argument
10 Thread_Construct(&p->thread); in LoopThread_Construct()
11 Event_Construct(&p->startEvent); in LoopThread_Construct()
12 Event_Construct(&p->finishedEvent); in LoopThread_Construct()
15 void LoopThread_Close(CLoopThread *p) in LoopThread_Close() argument
17 Thread_Close(&p->thread); in LoopThread_Close()
18 Event_Close(&p->startEvent); in LoopThread_Close()
19 Event_Close(&p->finishedEvent); in LoopThread_Close()
24 CLoopThread *p = (CLoopThread *)pp; in LoopThreadFunc() local
27 if (Event_Wait(&p->startEvent) != 0) in LoopThreadFunc()
29 if (p->stop) in LoopThreadFunc()
31 p->res = p->func(p->param); in LoopThreadFunc()
32 if (Event_Set(&p->finishedEvent) != 0) in LoopThreadFunc()
37 WRes LoopThread_Create(CLoopThread *p) in LoopThread_Create() argument
39 p->stop = 0; in LoopThread_Create()
40 RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent)); in LoopThread_Create()
41 RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent)); in LoopThread_Create()
42 return Thread_Create(&p->thread, LoopThreadFunc, p); in LoopThread_Create()
45 WRes LoopThread_StopAndWait(CLoopThread *p) in LoopThread_StopAndWait() argument
47 p->stop = 1; in LoopThread_StopAndWait()
48 if (Event_Set(&p->startEvent) != 0) in LoopThread_StopAndWait()
50 return Thread_Wait(&p->thread); in LoopThread_StopAndWait()
53 WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); } in LoopThread_StartSubThread() argument
54 WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); } in LoopThread_WaitSubThread() argument
56 static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) in Progress() argument
58 return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; in Progress()
61 static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress) in MtProgress_Init() argument
65 p->inSizes[i] = p->outSizes[i] = 0; in MtProgress_Init()
66 p->totalInSize = p->totalOutSize = 0; in MtProgress_Init()
67 p->progress = progress; in MtProgress_Init()
68 p->res = SZ_OK; in MtProgress_Init()
71 static void MtProgress_Reinit(CMtProgress *p, unsigned index) in MtProgress_Reinit() argument
73 p->inSizes[index] = 0; in MtProgress_Reinit()
74 p->outSizes[index] = 0; in MtProgress_Reinit()
80 SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize) in MtProgress_Set() argument
83 CriticalSection_Enter(&p->cs); in MtProgress_Set()
84 UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize) in MtProgress_Set()
85 UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize) in MtProgress_Set()
86 if (p->res == SZ_OK) in MtProgress_Set()
87 p->res = Progress(p->progress, p->totalInSize, p->totalOutSize); in MtProgress_Set()
88 res = p->res; in MtProgress_Set()
89 CriticalSection_Leave(&p->cs); in MtProgress_Set()
93 static void MtProgress_SetError(CMtProgress *p, SRes res) in MtProgress_SetError() argument
95 CriticalSection_Enter(&p->cs); in MtProgress_SetError()
96 if (p->res == SZ_OK) in MtProgress_SetError()
97 p->res = res; in MtProgress_SetError()
98 CriticalSection_Leave(&p->cs); in MtProgress_SetError()
101 static void MtCoder_SetError(CMtCoder* p, SRes res) in MtCoder_SetError() argument
103 CriticalSection_Enter(&p->cs); in MtCoder_SetError()
104 if (p->res == SZ_OK) in MtCoder_SetError()
105 p->res = res; in MtCoder_SetError()
106 CriticalSection_Leave(&p->cs); in MtCoder_SetError()
111 void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder) in CMtThread_Construct() argument
113 p->mtCoder = mtCoder; in CMtThread_Construct()
114 p->outBuf = 0; in CMtThread_Construct()
115 p->inBuf = 0; in CMtThread_Construct()
116 Event_Construct(&p->canRead); in CMtThread_Construct()
117 Event_Construct(&p->canWrite); in CMtThread_Construct()
118 LoopThread_Construct(&p->thread); in CMtThread_Construct()
123 static void CMtThread_CloseEvents(CMtThread *p) in CMtThread_CloseEvents() argument
125 Event_Close(&p->canRead); in CMtThread_CloseEvents()
126 Event_Close(&p->canWrite); in CMtThread_CloseEvents()
129 static void CMtThread_Destruct(CMtThread *p) in CMtThread_Destruct() argument
131 CMtThread_CloseEvents(p); in CMtThread_Destruct()
133 if (Thread_WasCreated(&p->thread.thread)) in CMtThread_Destruct()
135 LoopThread_StopAndWait(&p->thread); in CMtThread_Destruct()
136 LoopThread_Close(&p->thread); in CMtThread_Destruct()
139 if (p->mtCoder->alloc) in CMtThread_Destruct()
140 IAlloc_Free(p->mtCoder->alloc, p->outBuf); in CMtThread_Destruct()
141 p->outBuf = 0; in CMtThread_Destruct()
143 if (p->mtCoder->alloc) in CMtThread_Destruct()
144 IAlloc_Free(p->mtCoder->alloc, p->inBuf); in CMtThread_Destruct()
145 p->inBuf = 0; in CMtThread_Destruct()
150 { IAlloc_Free(p->mtCoder->alloc, buf); \
151 size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \
154 static SRes CMtThread_Prepare(CMtThread *p) in CMtThread_Prepare() argument
156 MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize) in CMtThread_Prepare()
157 MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize) in CMtThread_Prepare()
159 p->stopReading = False; in CMtThread_Prepare()
160 p->stopWriting = False; in CMtThread_Prepare()
161 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead)); in CMtThread_Prepare()
162 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite)); in CMtThread_Prepare()
185 #define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads - 1 ? 0 : p->in… argument
187 static SRes MtThread_Process(CMtThread *p, Bool *stop) in MtThread_Process() argument
191 if (Event_Wait(&p->canRead) != 0) in MtThread_Process()
194 next = GET_NEXT_THREAD(p); in MtThread_Process()
196 if (p->stopReading) in MtThread_Process()
203 size_t size = p->mtCoder->blockSize; in MtThread_Process()
204 size_t destSize = p->outBufSize; in MtThread_Process()
206 RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size)); in MtThread_Process()
207 next->stopReading = *stop = (size != p->mtCoder->blockSize); in MtThread_Process()
211 RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index, in MtThread_Process()
212 p->outBuf, &destSize, p->inBuf, size, *stop)); in MtThread_Process()
214 MtProgress_Reinit(&p->mtCoder->mtProgress, p->index); in MtThread_Process()
216 if (Event_Wait(&p->canWrite) != 0) in MtThread_Process()
218 if (p->stopWriting) in MtThread_Process()
220 if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize) in MtThread_Process()
228 CMtThread *p = (CMtThread *)pp; in ThreadFunc() local
232 CMtThread *next = GET_NEXT_THREAD(p); in ThreadFunc()
233 SRes res = MtThread_Process(p, &stop); in ThreadFunc()
236 MtCoder_SetError(p->mtCoder, res); in ThreadFunc()
237 MtProgress_SetError(&p->mtCoder->mtProgress, res); in ThreadFunc()
249 void MtCoder_Construct(CMtCoder* p) in MtCoder_Construct() argument
252 p->alloc = 0; in MtCoder_Construct()
255 CMtThread *t = &p->threads[i]; in MtCoder_Construct()
257 CMtThread_Construct(t, p); in MtCoder_Construct()
259 CriticalSection_Init(&p->cs); in MtCoder_Construct()
260 CriticalSection_Init(&p->mtProgress.cs); in MtCoder_Construct()
263 void MtCoder_Destruct(CMtCoder* p) in MtCoder_Destruct() argument
267 CMtThread_Destruct(&p->threads[i]); in MtCoder_Destruct()
268 CriticalSection_Delete(&p->cs); in MtCoder_Destruct()
269 CriticalSection_Delete(&p->mtProgress.cs); in MtCoder_Destruct()
272 SRes MtCoder_Code(CMtCoder *p) in MtCoder_Code() argument
274 unsigned i, numThreads = p->numThreads; in MtCoder_Code()
276 p->res = SZ_OK; in MtCoder_Code()
278 MtProgress_Init(&p->mtProgress, p->progress); in MtCoder_Code()
282 RINOK(CMtThread_Prepare(&p->threads[i])); in MtCoder_Code()
287 CMtThread *t = &p->threads[i]; in MtCoder_Code()
308 CMtThread *t = &p->threads[i]; in MtCoder_Code()
312 p->threads[0].stopReading = True; in MtCoder_Code()
317 Event_Set(&p->threads[0].canWrite); in MtCoder_Code()
318 Event_Set(&p->threads[0].canRead); in MtCoder_Code()
321 LoopThread_WaitSubThread(&p->threads[j].thread); in MtCoder_Code()
325 CMtThread_CloseEvents(&p->threads[i]); in MtCoder_Code()
326 return (res == SZ_OK) ? p->res : res; in MtCoder_Code()