diff options
Diffstat (limited to 'CPP/7zip/Compress/BZip2')
-rwxr-xr-x | CPP/7zip/Compress/BZip2/BZip2Decoder.cpp | 53 | ||||
-rwxr-xr-x | CPP/7zip/Compress/BZip2/BZip2Decoder.h | 8 | ||||
-rwxr-xr-x | CPP/7zip/Compress/BZip2/BZip2Encoder.cpp | 57 | ||||
-rwxr-xr-x | CPP/7zip/Compress/BZip2/BZip2Encoder.h | 10 |
4 files changed, 75 insertions, 53 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(); diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.h b/CPP/7zip/Compress/BZip2/BZip2Decoder.h index f7a1c6bb..d38ababe 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.h @@ -53,6 +53,12 @@ struct CState void FinishStream(); void ThreadFunc(); + HRes Create() + { + RINOK(StreamWasFinishedEvent.CreateIfNotCreated()); + RINOK(WaitingWasStartedEvent.CreateIfNotCreated()); + return CanWriteEvent.CreateIfNotCreated(); + } #endif CState(): Counters(0) {} @@ -125,7 +131,7 @@ public: UInt32 BlockSizeMax; CDecoder(); ~CDecoder(); - bool Create(); + HRes Create(); void Free(); #else diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp index 5e555813..f1e53cd6 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp @@ -26,14 +26,14 @@ const int kMaxHuffmanLenForEncoding = 16; // it must be < kMaxHuffmanLen = 20 static const UInt32 kBufferSize = (1 << 17); static const int kNumHuffPasses = 4; -bool CThreadInfo::Create() +bool CThreadInfo::Alloc() { - if (m_BlockSorterIndex != 0) - return true; - m_BlockSorterIndex = (UInt32 *)::BigAlloc(BLOCK_SORT_BUF_SIZE(kBlockSizeMax) * sizeof(UInt32)); if (m_BlockSorterIndex == 0) - return false; - + { + m_BlockSorterIndex = (UInt32 *)::BigAlloc(BLOCK_SORT_BUF_SIZE(kBlockSizeMax) * sizeof(UInt32)); + if (m_BlockSorterIndex == 0) + return false; + } if (m_Block == 0) { @@ -111,7 +111,7 @@ DWORD CThreadInfo::ThreadFunc() } } -static DWORD WINAPI MFThread(void *threadCoderInfo) +static THREAD_FUNC_DECL MFThread(void *threadCoderInfo) { return ((CThreadInfo *)threadCoderInfo)->ThreadFunc(); } @@ -135,33 +135,38 @@ CEncoder::~CEncoder() Free(); } -bool CEncoder::Create() +HRes CEncoder::Create() { + RINOK(CanProcessEvent.CreateIfNotCreated()); + RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) + return S_OK; try { - if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) - return true; Free(); MtMode = (NumThreads > 1); m_NumThreadsPrev = NumThreads; ThreadsInfo = new CThreadInfo[NumThreads]; if (ThreadsInfo == 0) - return false; - for (UInt32 t = 0; t < NumThreads; t++) + return E_OUTOFMEMORY; + } + catch(...) { return E_OUTOFMEMORY; } + for (UInt32 t = 0; t < NumThreads; t++) + { + CThreadInfo &ti = ThreadsInfo[t]; + ti.Encoder = this; + if (MtMode) { - CThreadInfo &ti = ThreadsInfo[t]; - ti.Encoder = 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; + } } } - catch(...) { return false; } - return true; + return S_OK; } void CEncoder::Free() @@ -712,8 +717,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, { #ifdef COMPRESS_BZIP2_MT Progress = progress; - if (!Create()) - return E_FAIL; + RINOK(Create()); for (UInt32 t = 0; t < NumThreads; t++) #endif { @@ -729,8 +733,9 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, ti.m_OptimizeNumTables = m_OptimizeNumTables; - if (!ti.Create()) + if (!ti.Alloc()) return E_OUTOFMEMORY; + RINOK(ti.Create()); } diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.h b/CPP/7zip/Compress/BZip2/BZip2Encoder.h index c05a0481..eff93bc7 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.h @@ -130,11 +130,17 @@ public: UInt64 m_PackSize; Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size. + HRes Create() + { + RINOK(StreamWasFinishedEvent.Create()); + RINOK(WaitingWasStartedEvent.Create()); + return CanWriteEvent.Create(); + } #endif CThreadInfo(): m_BlockSorterIndex(0), m_Block(0) {} ~CThreadInfo() { Free(); } - bool Create(); + bool Alloc(); void Free(); HRESULT EncodeBlock3(UInt32 blockSize); @@ -189,7 +195,7 @@ public: void WriteCRC(UInt32 v); #ifdef COMPRESS_BZIP2_MT - bool Create(); + HRes Create(); void Free(); #endif |