- 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
This commit is contained in:
kichik 2003-11-30 16:02:48 +00:00
parent 164f6462b3
commit 58ea8200ba
2 changed files with 35 additions and 40 deletions

View file

@ -140,15 +140,14 @@ int __stdcall lzmaDecompress(CLZMAStateP lzmaState)
EnterCriticalSection(&lzmaState->cs); EnterCriticalSection(&lzmaState->cs);
lzmaState->it_locked = TRUE; lzmaState->it_locked = TRUE;
while (lzmaState->dt_locked)
{
if (lzmaState->finished) if (lzmaState->finished)
{ {
LeaveCriticalSection(&lzmaState->cs); LeaveCriticalSection(&lzmaState->cs);
return lzmaState->res; return lzmaState->res;
} }
while (lzmaState->dt_locked)
Sleep(0); Sleep(0);
}
return 0; return 0;
} }

View file

@ -31,7 +31,6 @@ private:
BOOL finish; BOOL finish;
CRITICAL_SECTION cs; CRITICAL_SECTION cs;
BOOL cs_initialized;
BOOL nt_locked; /* nsis thread locked */ BOOL nt_locked; /* nsis thread locked */
BOOL ct_locked; /* compression thread locked */ BOOL ct_locked; /* compression thread locked */
BOOL compressor_finished; BOOL compressor_finished;
@ -43,20 +42,17 @@ public:
{ {
_encoder = new NCompress::NLZMA::CEncoder(); _encoder = new NCompress::NLZMA::CEncoder();
_encoder->SetWriteEndMarkerMode(true); _encoder->SetWriteEndMarkerMode(true);
cs_initialized = FALSE;
hCompressionThread = NULL; hCompressionThread = NULL;
compressor_finished = FALSE; compressor_finished = FALSE;
finish = FALSE; finish = FALSE;
End(); End();
InitializeCriticalSection(&cs);
} }
~CLZMA() ~CLZMA()
{ {
End(); End();
if (cs_initialized)
{
DeleteCriticalSection(&cs); DeleteCriticalSection(&cs);
}
if (_encoder) if (_encoder)
{ {
delete _encoder; delete _encoder;
@ -68,12 +64,6 @@ public:
{ {
End(); End();
if (!cs_initialized)
{
InitializeCriticalSection(&cs);
cs_initialized = TRUE;
}
nt_locked = TRUE; nt_locked = TRUE;
ct_locked = FALSE; ct_locked = FALSE;
@ -130,6 +120,8 @@ public:
while (nt_locked) while (nt_locked)
Sleep(0); Sleep(0);
try
{
if (_encoder->WriteCoderProperties(this) == S_OK) if (_encoder->WriteCoderProperties(this) == S_OK)
{ {
while (true) while (true)
@ -152,6 +144,11 @@ public:
{ {
res = -2; res = -2;
} }
}
catch (...)
{
res = -3;
}
compressor_finished = TRUE; compressor_finished = TRUE;
LeaveCriticalSection(&cs); LeaveCriticalSection(&cs);
@ -185,15 +182,14 @@ public:
EnterCriticalSection(&cs); EnterCriticalSection(&cs);
nt_locked = TRUE; nt_locked = TRUE;
while (ct_locked)
{
if (compressor_finished) if (compressor_finished)
{ {
LeaveCriticalSection(&cs); LeaveCriticalSection(&cs);
return res; return res;
} }
while (ct_locked)
Sleep(0); Sleep(0);
}
return C_OK; return C_OK;
} }