Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/Common')
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2.h2
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2MT.cpp54
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2MT.h21
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2ST.cpp3
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2ST.h2
-rwxr-xr-xCPP/7zip/Archive/Common/CrossThreadProgress.h6
6 files changed, 46 insertions, 42 deletions
diff --git a/CPP/7zip/Archive/Common/CoderMixer2.h b/CPP/7zip/Archive/Common/CoderMixer2.h
index 78a3f280..597a7b60 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2.h
+++ b/CPP/7zip/Archive/Common/CoderMixer2.h
@@ -158,7 +158,7 @@ struct CCoderInfo
class CCoderMixer2
{
public:
- virtual void SetBindInfo(const CBindInfo &bindInfo) = 0;
+ virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
virtual void ReInit() = 0;
virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
};
diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
index c3b37f2d..8a37a10d 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
+++ b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
@@ -12,8 +12,6 @@ namespace NCoderMixer2 {
CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams):
ExitEvent(NULL),
- CompressEvent(NULL),
- CompressionCompletedEvent(NULL),
CCoderInfo(numInStreams, numOutStreams)
{
InStreams.Reserve(NumInStreams);
@@ -22,20 +20,6 @@ CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams):
OutStreamPointers.Reserve(NumOutStreams);
}
-void CThreadCoderInfo::CreateEvents()
-{
- CompressEvent = new CAutoResetEvent(false);
- CompressionCompletedEvent = new CAutoResetEvent(false);
-}
-
-CThreadCoderInfo::~CThreadCoderInfo()
-{
- if (CompressEvent != NULL)
- delete CompressEvent;
- if (CompressionCompletedEvent != NULL)
- delete CompressionCompletedEvent;
-}
-
class CCoderInfoFlusher2
{
CThreadCoderInfo *m_CoderInfo;
@@ -48,13 +32,13 @@ public:
m_CoderInfo->InStreams[i].Release();
for (i = 0; i < m_CoderInfo->OutStreams.Size(); i++)
m_CoderInfo->OutStreams[i].Release();
- m_CoderInfo->CompressionCompletedEvent->Set();
+ m_CoderInfo->CompressionCompletedEvent.Set();
}
};
bool CThreadCoderInfo::WaitAndCode()
{
- HANDLE events[2] = { ExitEvent, *CompressEvent };
+ HANDLE events[2] = { ExitEvent, CompressEvent };
DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
if (waitResult == WAIT_OBJECT_0 + 0)
return false;
@@ -123,7 +107,7 @@ void CThreadCoderInfo::SetCoderInfo(const UInt64 **inSizes,
SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
}
-static DWORD WINAPI CoderThread(void *threadCoderInfo)
+static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo)
{
for (;;)
{
@@ -135,7 +119,7 @@ static DWORD WINAPI CoderThread(void *threadCoderInfo)
//////////////////////////////////////
// CCoderMixer2MT
-static DWORD WINAPI MainCoderThread(void *threadCoderInfo)
+static THREAD_FUNC_DECL MainCoderThread(void *threadCoderInfo)
{
for (;;)
{
@@ -146,7 +130,9 @@ static DWORD WINAPI MainCoderThread(void *threadCoderInfo)
CCoderMixer2MT::CCoderMixer2MT()
{
- if (!_mainThread.Create(MainCoderThread, this))
+ if (CreateEvents() != S_OK)
+ throw 271824;
+ if (_mainThread.Create(MainCoderThread, this) != S_OK)
throw 271825;
}
@@ -161,15 +147,16 @@ CCoderMixer2MT::~CCoderMixer2MT()
}
}
-void CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)
+HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)
{
_bindInfo = bindInfo;
_streamBinders.Clear();
for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)
{
_streamBinders.Add(CStreamBinder());
- _streamBinders.Back().CreateEvents();
+ RINOK(_streamBinders.Back().CreateEvents());
}
+ return S_OK;
}
void CCoderMixer2MT::AddCoderCommon()
@@ -180,13 +167,13 @@ void CCoderMixer2MT::AddCoderCommon()
CThreadCoderInfo threadCoderInfo(CoderStreamsInfo.NumInStreams,
CoderStreamsInfo.NumOutStreams);
_coderInfoVector.Add(threadCoderInfo);
- _coderInfoVector.Back().CreateEvents();
- _coderInfoVector.Back().ExitEvent = _exitEvent;
- _compressingCompletedEvents.Add(*_coderInfoVector.Back().CompressionCompletedEvent);
+ CThreadCoderInfo *tci = &_coderInfoVector.Back();
+ tci->CreateEvents();
+ tci->ExitEvent = _exitEvent;
NWindows::CThread newThread;
_threads.Add(newThread);
- if (!_threads.Back().Create(CoderThread, &_coderInfoVector.Back()))
+ if (_threads.Back().Create(CoderThread, tci) != S_OK)
throw 271824;
}
@@ -282,13 +269,13 @@ bool CCoderMixer2MT::MyCode()
if (waitResult == WAIT_OBJECT_0 + 0)
return false;
- for(int i = 0; i < _coderInfoVector.Size(); i++)
- _coderInfoVector[i].CompressEvent->Set();
- /* DWORD result = */ ::WaitForMultipleObjects(_compressingCompletedEvents.Size(),
- &_compressingCompletedEvents.Front(), TRUE, INFINITE);
-
- _compressingFinishedEvent.Set();
+ int i;
+ for(i = 0; i < _coderInfoVector.Size(); i++)
+ _coderInfoVector[i].CompressEvent.Set();
+ for (i = 0; i < _coderInfoVector.Size(); i++)
+ _coderInfoVector[i].CompressionCompletedEvent.Lock();
+ _compressingFinishedEvent.Set();
return true;
}
@@ -311,6 +298,7 @@ STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,
CCrossThreadProgress *progressSpec = new CCrossThreadProgress;
CMyComPtr<ICompressProgressInfo> crossProgress = progressSpec;
+ RINOK(progressSpec->Create());
progressSpec->Init();
_coderInfoVector[_progressCoderIndex].Progress = crossProgress;
diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.h b/CPP/7zip/Archive/Common/CoderMixer2MT.h
index 78d752de..67c0c8a5 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2MT.h
+++ b/CPP/7zip/Archive/Common/CoderMixer2MT.h
@@ -20,9 +20,9 @@ namespace NCoderMixer2 {
struct CThreadCoderInfo: public CCoderInfo
{
- NWindows::NSynchronization::CAutoResetEvent *CompressEvent;
+ NWindows::NSynchronization::CAutoResetEvent CompressEvent;
HANDLE ExitEvent;
- NWindows::NSynchronization::CAutoResetEvent *CompressionCompletedEvent;
+ NWindows::NSynchronization::CAutoResetEvent CompressionCompletedEvent;
CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
@@ -35,9 +35,12 @@ struct CThreadCoderInfo: public CCoderInfo
CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams);
void SetCoderInfo(const UInt64 **inSizes,
const UInt64 **outSizes, ICompressProgressInfo *progress);
- ~CThreadCoderInfo();
bool WaitAndCode();
- void CreateEvents();
+ HRes CreateEvents()
+ {
+ RINOK(CompressEvent.CreateIfNotCreated());
+ return CompressionCompletedEvent.CreateIfNotCreated();
+ }
};
@@ -105,14 +108,20 @@ private:
NWindows::CThread _mainThread;
NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent;
- CRecordVector<HANDLE> _compressingCompletedEvents;
NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent;
NWindows::NSynchronization::CManualResetEvent _exitEvent;
UInt32 _progressCoderIndex;
+ HRes CreateEvents()
+ {
+ RINOK(_startCompressingEvent.CreateIfNotCreated());
+ RINOK(_compressingFinishedEvent.CreateIfNotCreated());
+ return _exitEvent.CreateIfNotCreated();
+ }
+
public:
- void SetBindInfo(const CBindInfo &bindInfo);
+ HRESULT SetBindInfo(const CBindInfo &bindInfo);
};
diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp b/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
index c01b776d..6bcab0dd 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
+++ b/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
@@ -10,9 +10,10 @@ CCoderMixer2ST::CCoderMixer2ST() {}
CCoderMixer2ST::~CCoderMixer2ST(){ }
-void CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo)
+HRESULT CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo)
{
_bindInfo = bindInfo;
+ return S_OK;
}
void CCoderMixer2ST::AddCoderCommon(bool isMain)
diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.h b/CPP/7zip/Archive/Common/CoderMixer2ST.h
index 3144918b..ea5a53e3 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2ST.h
+++ b/CPP/7zip/Archive/Common/CoderMixer2ST.h
@@ -79,7 +79,7 @@ private:
CObjectVector<CSTCoderInfo> _coders;
int _mainCoderIndex;
public:
- void SetBindInfo(const CBindInfo &bindInfo);
+ HRESULT SetBindInfo(const CBindInfo &bindInfo);
};
diff --git a/CPP/7zip/Archive/Common/CrossThreadProgress.h b/CPP/7zip/Archive/Common/CrossThreadProgress.h
index 5dd339dc..b5422a31 100755
--- a/CPP/7zip/Archive/Common/CrossThreadProgress.h
+++ b/CPP/7zip/Archive/Common/CrossThreadProgress.h
@@ -17,6 +17,12 @@ public:
HRESULT Result;
NWindows::NSynchronization::CAutoResetEvent ProgressEvent;
NWindows::NSynchronization::CAutoResetEvent WaitEvent;
+
+ HRes Create()
+ {
+ RINOK(ProgressEvent.CreateIfNotCreated());
+ return WaitEvent.CreateIfNotCreated();
+ }
void Init()
{
ProgressEvent.Reset();