diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2007-06-26 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:52 +0300 |
commit | fd8b1d78b496fe38193bf8c5e86af3b43f0b022d (patch) | |
tree | 5b1e3812ed4d8b6037e5035faf3b638849f618e2 /CPP/7zip/Archive/Common/CoderMixerMT.cpp | |
parent | 0b33f700a66fcf7f55f92b92e0b3e5c7014d769a (diff) |
4.48 beta
Diffstat (limited to 'CPP/7zip/Archive/Common/CoderMixerMT.cpp')
-rwxr-xr-x | CPP/7zip/Archive/Common/CoderMixerMT.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.cpp b/CPP/7zip/Archive/Common/CoderMixerMT.cpp new file mode 100755 index 00000000..ad6e12d8 --- /dev/null +++ b/CPP/7zip/Archive/Common/CoderMixerMT.cpp @@ -0,0 +1,97 @@ +// CoderMixerMT.cpp + +#include "StdAfx.h" + +#include "CoderMixerMT.h" + +namespace NCoderMixer { + +void CCoder::Execute() { Code(NULL); } + +void CCoder::Code(ICompressProgressInfo *progress) +{ + Result = Coder->Code(InStream, OutStream, + InSizeAssigned ? &InSizeValue : NULL, + OutSizeAssigned ? &OutSizeValue : NULL, + progress); + InStream.Release(); + OutStream.Release(); +} + +void CCoderMixerMT::AddCoder(ICompressCoder *coder) +{ + _coders.Add(CCoder()); + _coders.Back().Coder = coder; +} + +void CCoderMixerMT::ReInit() +{ + for(int i = 0; i < _coders.Size(); i++) + _coders[i].ReInit(); +} + +STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream, + ISequentialOutStream *outStream, + const UInt64 * /* inSize */, const UInt64 * /* outSize */, + ICompressProgressInfo *progress) +{ + _coders.Front().InStream = inStream; + int i; + _coders.Back().OutStream = outStream; + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + { + RINOK(_coders[i].Create()); + } + + while (_streamBinders.Size() + 1 < _coders.Size()) + { + _streamBinders.Add(CStreamBinder()); + int i = _streamBinders.Size() - 1; + CStreamBinder &sb = _streamBinders.Back(); + RINOK(sb.CreateEvents()); + sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream); + } + + for(i = 0; i < _streamBinders.Size(); i++) + _streamBinders[i].ReInit(); + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].Start(); + + _coders[_progressCoderIndex].Code(progress); + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].WaitFinish(); + + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result == E_ABORT) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result == S_FALSE) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result != S_OK && result != E_FAIL) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result != S_OK) + return result; + } + return S_OK; +} + +} |