diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2007-05-25 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:51 +0300 |
commit | c574fc0f4bba94e693b0e22f730d355b75d4f4ce (patch) | |
tree | da4ebd90c776d508ac679d50492f29461db80be0 /CPP/7zip/Compress/BZip2/BZip2Decoder.cpp | |
parent | a145bfc7cf17f7bbcfae8f0064333c8ea75b455c (diff) |
4.46 beta
Diffstat (limited to 'CPP/7zip/Compress/BZip2/BZip2Decoder.cpp')
-rwxr-xr-x | CPP/7zip/Compress/BZip2/BZip2Decoder.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp index 703d528b..354ed03e 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp @@ -420,7 +420,7 @@ static UInt32 NO_INLINE DecodeBlock2Rand(const UInt32 *tt, UInt32 blockSize, UIn #ifdef COMPRESS_BZIP2_MT -static DWORD WINAPI MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; } +static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; } CDecoder::CDecoder(): m_States(0) @@ -434,35 +434,40 @@ CDecoder::~CDecoder() Free(); } -bool CDecoder::Create() +HRes CDecoder::Create() { + RINOK(CanProcessEvent.CreateIfNotCreated()); + RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + if (m_States != 0 && m_NumThreadsPrev == NumThreads) + return true; + Free(); + MtMode = (NumThreads > 1); + m_NumThreadsPrev = NumThreads; try { - if (m_States != 0 && m_NumThreadsPrev == NumThreads) - return true; - Free(); - MtMode = (NumThreads > 1); - m_NumThreadsPrev = NumThreads; m_States = new CState[NumThreads]; if (m_States == 0) - return false; - #ifdef COMPRESS_BZIP2_MT - for (UInt32 t = 0; t < NumThreads; t++) + return E_OUTOFMEMORY; + } + catch(...) { return E_OUTOFMEMORY; } + #ifdef COMPRESS_BZIP2_MT + for (UInt32 t = 0; t < NumThreads; t++) + { + CState &ti = m_States[t]; + ti.Decoder = this; + if (MtMode) { - CState &ti = m_States[t]; - ti.Decoder = this; - if (MtMode) - if (!ti.Thread.Create(MFThread, &ti)) - { - NumThreads = t; - Free(); - return false; - } + HRes res = ti.Thread.Create(MFThread, &ti); + if (res != S_OK) + { + NumThreads = t; + Free(); + return res; + } } - #endif } - catch(...) { return false; } - return true; + #endif + return S_OK; } void CDecoder::Free() @@ -517,13 +522,13 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress) { #ifdef COMPRESS_BZIP2_MT Progress = progress; - if (!Create()) - return E_FAIL; + RINOK(Create()); for (UInt32 t = 0; t < NumThreads; t++) { CState &s = m_States[t]; if (!s.Alloc()) return E_OUTOFMEMORY; + RINOK(s.Create()); s.StreamWasFinishedEvent.Reset(); s.WaitingWasStartedEvent.Reset(); s.CanWriteEvent.Reset(); |