From 58ea8200baf1b2312cbf2cf29221900c26d9fd2e Mon Sep 17 00:00:00 2001 From: kichik Date: Sun, 30 Nov 2003 16:02:48 +0000 Subject: [PATCH] - Fixed a race condition that happened when LZMA compression finished and occasionally deadlocked the next call (solid installers weren't affected, just the compiler) - Added try and catch for LZMA just in case one of the rare exceptions will be thrown (just compiler) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3233 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/7zip/lzmaNSIS.cpp | 13 ++++----- Source/clzma.h | 62 +++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Source/7zip/lzmaNSIS.cpp b/Source/7zip/lzmaNSIS.cpp index 1abe3f18..12daa4f3 100644 --- a/Source/7zip/lzmaNSIS.cpp +++ b/Source/7zip/lzmaNSIS.cpp @@ -139,16 +139,15 @@ int __stdcall lzmaDecompress(CLZMAStateP lzmaState) EnterCriticalSection(&lzmaState->cs); lzmaState->it_locked = TRUE; + + if (lzmaState->finished) + { + LeaveCriticalSection(&lzmaState->cs); + return lzmaState->res; + } while (lzmaState->dt_locked) - { - if (lzmaState->finished) - { - LeaveCriticalSection(&lzmaState->cs); - return lzmaState->res; - } Sleep(0); - } return 0; } diff --git a/Source/clzma.h b/Source/clzma.h index d6ff0fbd..78aada53 100644 --- a/Source/clzma.h +++ b/Source/clzma.h @@ -31,7 +31,6 @@ private: BOOL finish; CRITICAL_SECTION cs; - BOOL cs_initialized; BOOL nt_locked; /* nsis thread locked */ BOOL ct_locked; /* compression thread locked */ BOOL compressor_finished; @@ -43,20 +42,17 @@ public: { _encoder = new NCompress::NLZMA::CEncoder(); _encoder->SetWriteEndMarkerMode(true); - cs_initialized = FALSE; hCompressionThread = NULL; compressor_finished = FALSE; finish = FALSE; End(); + InitializeCriticalSection(&cs); } ~CLZMA() { End(); - if (cs_initialized) - { - DeleteCriticalSection(&cs); - } + DeleteCriticalSection(&cs); if (_encoder) { delete _encoder; @@ -68,12 +64,6 @@ public: { End(); - if (!cs_initialized) - { - InitializeCriticalSection(&cs); - cs_initialized = TRUE; - } - nt_locked = TRUE; ct_locked = FALSE; @@ -130,27 +120,34 @@ public: while (nt_locked) Sleep(0); - if (_encoder->WriteCoderProperties(this) == S_OK) + try { - while (true) + if (_encoder->WriteCoderProperties(this) == S_OK) { - UINT64 inSize, outSize; - INT32 finished; - if (_encoder->CodeOneBlock(&inSize, &outSize, &finished)) + while (true) { - res = -2; - break; - } - if (finished) - { - res = C_OK; - break; + UINT64 inSize, outSize; + INT32 finished; + if (_encoder->CodeOneBlock(&inSize, &outSize, &finished)) + { + res = -2; + break; + } + if (finished) + { + res = C_OK; + break; + } } } + else + { + res = -2; + } } - else + catch (...) { - res = -2; + res = -3; } compressor_finished = TRUE; @@ -185,16 +182,15 @@ public: EnterCriticalSection(&cs); nt_locked = TRUE; - while (ct_locked) + if (compressor_finished) { - if (compressor_finished) - { - LeaveCriticalSection(&cs); - return res; - } - Sleep(0); + LeaveCriticalSection(&cs); + return res; } + while (ct_locked) + Sleep(0); + return C_OK; }