Lines Matching refs:p

10 void LoopThread_Construct(CLoopThread *p)  in LoopThread_Construct()  argument
12 Thread_Construct(&p->thread); in LoopThread_Construct()
13 Event_Construct(&p->startEvent); in LoopThread_Construct()
14 Event_Construct(&p->finishedEvent); in LoopThread_Construct()
17 void LoopThread_Close(CLoopThread *p) in LoopThread_Close() argument
19 Thread_Close(&p->thread); in LoopThread_Close()
20 Event_Close(&p->startEvent); in LoopThread_Close()
21 Event_Close(&p->finishedEvent); in LoopThread_Close()
26 CLoopThread *p = (CLoopThread *)pp; in LoopThreadFunc() local
29 if (Event_Wait(&p->startEvent) != 0) in LoopThreadFunc()
31 if (p->stop) in LoopThreadFunc()
33 p->res = p->func(p->param); in LoopThreadFunc()
34 if (Event_Set(&p->finishedEvent) != 0) in LoopThreadFunc()
39 WRes LoopThread_Create(CLoopThread *p) in LoopThread_Create() argument
41 p->stop = 0; in LoopThread_Create()
42 RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent)); in LoopThread_Create()
43 RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent)); in LoopThread_Create()
44 return Thread_Create(&p->thread, LoopThreadFunc, p); in LoopThread_Create()
47 WRes LoopThread_StopAndWait(CLoopThread *p) in LoopThread_StopAndWait() argument
49 p->stop = 1; in LoopThread_StopAndWait()
50 if (Event_Set(&p->startEvent) != 0) in LoopThread_StopAndWait()
52 return Thread_Wait(&p->thread); in LoopThread_StopAndWait()
55 WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); } in LoopThread_StartSubThread() argument
56 WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); } in LoopThread_WaitSubThread() argument
58 static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) in Progress() argument
60 return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; in Progress()
63 static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress) in MtProgress_Init() argument
67 p->inSizes[i] = p->outSizes[i] = 0; in MtProgress_Init()
68 p->totalInSize = p->totalOutSize = 0; in MtProgress_Init()
69 p->progress = progress; in MtProgress_Init()
70 p->res = SZ_OK; in MtProgress_Init()
73 static void MtProgress_Reinit(CMtProgress *p, unsigned index) in MtProgress_Reinit() argument
75 p->inSizes[index] = 0; in MtProgress_Reinit()
76 p->outSizes[index] = 0; in MtProgress_Reinit()
82 SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize) in MtProgress_Set() argument
85 CriticalSection_Enter(&p->cs); in MtProgress_Set()
86 UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize) in MtProgress_Set()
87 UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize) in MtProgress_Set()
88 if (p->res == SZ_OK) in MtProgress_Set()
89 p->res = Progress(p->progress, p->totalInSize, p->totalOutSize); in MtProgress_Set()
90 res = p->res; in MtProgress_Set()
91 CriticalSection_Leave(&p->cs); in MtProgress_Set()
95 static void MtProgress_SetError(CMtProgress *p, SRes res) in MtProgress_SetError() argument
97 CriticalSection_Enter(&p->cs); in MtProgress_SetError()
98 if (p->res == SZ_OK) in MtProgress_SetError()
99 p->res = res; in MtProgress_SetError()
100 CriticalSection_Leave(&p->cs); in MtProgress_SetError()
103 static void MtCoder_SetError(CMtCoder* p, SRes res) in MtCoder_SetError() argument
105 CriticalSection_Enter(&p->cs); in MtCoder_SetError()
106 if (p->res == SZ_OK) in MtCoder_SetError()
107 p->res = res; in MtCoder_SetError()
108 CriticalSection_Leave(&p->cs); in MtCoder_SetError()
113 void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder) in CMtThread_Construct() argument
115 p->mtCoder = mtCoder; in CMtThread_Construct()
116 p->outBuf = 0; in CMtThread_Construct()
117 p->inBuf = 0; in CMtThread_Construct()
118 Event_Construct(&p->canRead); in CMtThread_Construct()
119 Event_Construct(&p->canWrite); in CMtThread_Construct()
120 LoopThread_Construct(&p->thread); in CMtThread_Construct()
125 static void CMtThread_CloseEvents(CMtThread *p) in CMtThread_CloseEvents() argument
127 Event_Close(&p->canRead); in CMtThread_CloseEvents()
128 Event_Close(&p->canWrite); in CMtThread_CloseEvents()
131 static void CMtThread_Destruct(CMtThread *p) in CMtThread_Destruct() argument
133 CMtThread_CloseEvents(p); in CMtThread_Destruct()
135 if (Thread_WasCreated(&p->thread.thread)) in CMtThread_Destruct()
137 LoopThread_StopAndWait(&p->thread); in CMtThread_Destruct()
138 LoopThread_Close(&p->thread); in CMtThread_Destruct()
141 if (p->mtCoder->alloc) in CMtThread_Destruct()
142 IAlloc_Free(p->mtCoder->alloc, p->outBuf); in CMtThread_Destruct()
143 p->outBuf = 0; in CMtThread_Destruct()
145 if (p->mtCoder->alloc) in CMtThread_Destruct()
146 IAlloc_Free(p->mtCoder->alloc, p->inBuf); in CMtThread_Destruct()
147 p->inBuf = 0; in CMtThread_Destruct()
152 { IAlloc_Free(p->mtCoder->alloc, buf); \
153 size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \
156 static SRes CMtThread_Prepare(CMtThread *p) in CMtThread_Prepare() argument
158 MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize) in CMtThread_Prepare()
159 MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize) in CMtThread_Prepare()
161 p->stopReading = False; in CMtThread_Prepare()
162 p->stopWriting = False; in CMtThread_Prepare()
163 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead)); in CMtThread_Prepare()
164 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite)); in CMtThread_Prepare()
187 #define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads - 1 ? 0 : p->in… argument
189 static SRes MtThread_Process(CMtThread *p, Bool *stop) in MtThread_Process() argument
193 if (Event_Wait(&p->canRead) != 0) in MtThread_Process()
196 next = GET_NEXT_THREAD(p); in MtThread_Process()
198 if (p->stopReading) in MtThread_Process()
205 size_t size = p->mtCoder->blockSize; in MtThread_Process()
206 size_t destSize = p->outBufSize; in MtThread_Process()
208 RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size)); in MtThread_Process()
209 next->stopReading = *stop = (size != p->mtCoder->blockSize); in MtThread_Process()
213 RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index, in MtThread_Process()
214 p->outBuf, &destSize, p->inBuf, size, *stop)); in MtThread_Process()
216 MtProgress_Reinit(&p->mtCoder->mtProgress, p->index); in MtThread_Process()
218 if (Event_Wait(&p->canWrite) != 0) in MtThread_Process()
220 if (p->stopWriting) in MtThread_Process()
222 if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize) in MtThread_Process()
230 CMtThread *p = (CMtThread *)pp; in ThreadFunc() local
234 CMtThread *next = GET_NEXT_THREAD(p); in ThreadFunc()
235 SRes res = MtThread_Process(p, &stop); in ThreadFunc()
238 MtCoder_SetError(p->mtCoder, res); in ThreadFunc()
239 MtProgress_SetError(&p->mtCoder->mtProgress, res); in ThreadFunc()
251 void MtCoder_Construct(CMtCoder* p) in MtCoder_Construct() argument
254 p->alloc = 0; in MtCoder_Construct()
257 CMtThread *t = &p->threads[i]; in MtCoder_Construct()
259 CMtThread_Construct(t, p); in MtCoder_Construct()
261 CriticalSection_Init(&p->cs); in MtCoder_Construct()
262 CriticalSection_Init(&p->mtProgress.cs); in MtCoder_Construct()
265 void MtCoder_Destruct(CMtCoder* p) in MtCoder_Destruct() argument
269 CMtThread_Destruct(&p->threads[i]); in MtCoder_Destruct()
270 CriticalSection_Delete(&p->cs); in MtCoder_Destruct()
271 CriticalSection_Delete(&p->mtProgress.cs); in MtCoder_Destruct()
274 SRes MtCoder_Code(CMtCoder *p) in MtCoder_Code() argument
276 unsigned i, numThreads = p->numThreads; in MtCoder_Code()
278 p->res = SZ_OK; in MtCoder_Code()
280 MtProgress_Init(&p->mtProgress, p->progress); in MtCoder_Code()
284 RINOK(CMtThread_Prepare(&p->threads[i])); in MtCoder_Code()
289 CMtThread *t = &p->threads[i]; in MtCoder_Code()
310 CMtThread *t = &p->threads[i]; in MtCoder_Code()
314 p->threads[0].stopReading = True; in MtCoder_Code()
319 Event_Set(&p->threads[0].canWrite); in MtCoder_Code()
320 Event_Set(&p->threads[0].canRead); in MtCoder_Code()
323 LoopThread_WaitSubThread(&p->threads[j].thread); in MtCoder_Code()
327 CMtThread_CloseEvents(&p->threads[i]); in MtCoder_Code()
328 return (res == SZ_OK) ? p->res : res; in MtCoder_Code()