mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 11:14:58 -06:00
18.03
This commit is contained in:
89
C/MtCoder.c
89
C/MtCoder.c
@@ -1,85 +1,28 @@
|
||||
/* MtCoder.c -- Multi-thread Coder
|
||||
2017-07-17 : Igor Pavlov : Public domain */
|
||||
2018-02-21 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "MtCoder.h"
|
||||
|
||||
static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)
|
||||
{
|
||||
unsigned i;
|
||||
#ifndef _7ZIP_ST
|
||||
|
||||
p->progress = progress;
|
||||
p->res = SZ_OK;
|
||||
p->totalInSize = 0;
|
||||
p->totalOutSize = 0;
|
||||
|
||||
for (i = 0; i < MTCODER__THREADS_MAX; i++)
|
||||
SRes MtProgressThunk_Progress(const ICompressProgress *pp, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
CMtProgressThunk *thunk = CONTAINER_FROM_VTBL(pp, CMtProgressThunk, vt);
|
||||
UInt64 inSize2 = 0;
|
||||
UInt64 outSize2 = 0;
|
||||
if (inSize != (UInt64)(Int64)-1)
|
||||
{
|
||||
CMtProgressSizes *pair = &p->sizes[i];
|
||||
pair->inSize = 0;
|
||||
pair->outSize = 0;
|
||||
inSize2 = inSize - thunk->inSize;
|
||||
thunk->inSize = inSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void MtProgress_Reinit(CMtProgress *p, unsigned index)
|
||||
{
|
||||
CMtProgressSizes *pair = &p->sizes[index];
|
||||
pair->inSize = 0;
|
||||
pair->outSize = 0;
|
||||
}
|
||||
|
||||
|
||||
#define UPDATE_PROGRESS(size, prev, total) \
|
||||
if (size != (UInt64)(Int64)-1) { total += size - prev; prev = size; }
|
||||
|
||||
SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
SRes res;
|
||||
CMtProgressSizes *pair;
|
||||
|
||||
CriticalSection_Enter(&p->cs);
|
||||
|
||||
pair = &p->sizes[index];
|
||||
UPDATE_PROGRESS(inSize, pair->inSize, p->totalInSize)
|
||||
UPDATE_PROGRESS(outSize, pair->outSize, p->totalOutSize)
|
||||
if (p->res == SZ_OK && p->progress)
|
||||
if (outSize != (UInt64)(Int64)-1)
|
||||
{
|
||||
if (ICompressProgress_Progress(p->progress, p->totalInSize, p->totalOutSize) != SZ_OK)
|
||||
p->res = SZ_ERROR_PROGRESS;
|
||||
outSize2 = outSize - thunk->outSize;
|
||||
thunk->outSize = outSize;
|
||||
}
|
||||
res = p->res;
|
||||
|
||||
CriticalSection_Leave(&p->cs);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static SRes MtProgress_GetError(CMtProgress *p)
|
||||
{
|
||||
SRes res;
|
||||
CriticalSection_Enter(&p->cs);
|
||||
res = p->res;
|
||||
CriticalSection_Leave(&p->cs);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void MtProgress_SetError(CMtProgress *p, SRes res)
|
||||
{
|
||||
CriticalSection_Enter(&p->cs);
|
||||
if (p->res == SZ_OK)
|
||||
p->res = res;
|
||||
CriticalSection_Leave(&p->cs);
|
||||
}
|
||||
|
||||
|
||||
static SRes MtProgressThunk_Progress(const ICompressProgress *pp, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
CMtProgressThunk *p = CONTAINER_FROM_VTBL(pp, CMtProgressThunk, vt);
|
||||
return MtProgress_Set(p->mtProgress, p->index, inSize, outSize);
|
||||
return MtProgress_ProgressAdd(thunk->mtProgress, inSize2, outSize2);
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +241,7 @@ static SRes ThreadFunc2(CMtCoderThread *t)
|
||||
res = mtc->mtCallback->Code(mtc->mtCallbackObject, t->index, bufIndex,
|
||||
mtc->inStream ? t->inBuf : inData, size, finished);
|
||||
|
||||
MtProgress_Reinit(&mtc->mtProgress, t->index);
|
||||
// MtProgress_Reinit(&mtc->mtProgress, t->index);
|
||||
|
||||
if (res != SZ_OK)
|
||||
MtProgress_SetError(&mtc->mtProgress, res);
|
||||
@@ -654,3 +597,5 @@ SRes MtCoder_Code(CMtCoder *p)
|
||||
MtCoder_Free(p);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user