xref: /aosp_15_r20/external/lzma/CPP/7zip/Common/ProgressMt.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // ProgressMt.h
2 
3 #include "StdAfx.h"
4 
5 #include "ProgressMt.h"
6 
Init(unsigned numItems,ICompressProgressInfo * progress)7 void CMtCompressProgressMixer::Init(unsigned numItems, ICompressProgressInfo *progress)
8 {
9   NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
10   InSizes.Clear();
11   OutSizes.Clear();
12   for (unsigned i = 0; i < numItems; i++)
13   {
14     InSizes.Add(0);
15     OutSizes.Add(0);
16   }
17   TotalInSize = 0;
18   TotalOutSize = 0;
19   _progress = progress;
20 }
21 
Reinit(unsigned index)22 void CMtCompressProgressMixer::Reinit(unsigned index)
23 {
24   NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
25   InSizes[index] = 0;
26   OutSizes[index] = 0;
27 }
28 
SetRatioInfo(unsigned index,const UInt64 * inSize,const UInt64 * outSize)29 HRESULT CMtCompressProgressMixer::SetRatioInfo(unsigned index, const UInt64 *inSize, const UInt64 *outSize)
30 {
31   NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
32   if (inSize)
33   {
34     const UInt64 diff = *inSize - InSizes[index];
35     InSizes[index] = *inSize;
36     TotalInSize += diff;
37   }
38   if (outSize)
39   {
40     const UInt64 diff = *outSize - OutSizes[index];
41     OutSizes[index] = *outSize;
42     TotalOutSize += diff;
43   }
44   if (_progress)
45     return _progress->SetRatioInfo(&TotalInSize, &TotalOutSize);
46   return S_OK;
47 }
48 
49 
Z7_COM7F_IMF(CMtCompressProgress::SetRatioInfo (const UInt64 * inSize,const UInt64 * outSize))50 Z7_COM7F_IMF(CMtCompressProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
51 {
52   return _progress->SetRatioInfo(_index, inSize, outSize);
53 }
54