diff options
Diffstat (limited to 'src/libs/7zip/win/CPP/7zip/Common')
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/InMemStream.cpp | 222 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/InMemStream.h | 284 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/MemBlocks.cpp | 183 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/MemBlocks.h | 71 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/OutMemStream.cpp | 142 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/OutMemStream.h | 96 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/ProgressMt.cpp | 53 | ||||
-rw-r--r-- | src/libs/7zip/win/CPP/7zip/Common/ProgressMt.h | 46 |
8 files changed, 0 insertions, 1097 deletions
diff --git a/src/libs/7zip/win/CPP/7zip/Common/InMemStream.cpp b/src/libs/7zip/win/CPP/7zip/Common/InMemStream.cpp deleted file mode 100644 index 38c5c92c3..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/InMemStream.cpp +++ /dev/null @@ -1,222 +0,0 @@ -// InMemStream.cpp - -#include "StdAfx.h" - -#include <stdio.h> - -#include "Windows/Thread.h" - -#include "InMemStream.h" -#include "../../Common/Defs.h" - -void CStreamInfo::Free(IInMemStreamMtCallback *callback) -{ - for (int i = 0; i < Blocks.Size(); i++) - { - callback->FreeBlock(Blocks[i]); - Blocks[i] = 0; - } -} - -bool CInMemStreamMt::Create(int numSubStreams, UInt64 subStreamSize) -{ - Free(); - _subStreamSize = subStreamSize; - size_t blockSize = Callback->GetBlockSize(); - for (int i = 0; i < numSubStreams; i++) - { - _streams.Add(CStreamInfo()); - CStreamInfo &blocks = _streams.Back(); - blocks.Create(); - for (UInt64 j = 0; (UInt64)j * blockSize < _subStreamSize; j++) - blocks.Blocks.Add(0); - } - if (!_streamIndexAllocator.AllocateList(numSubStreams)) - return false; - return true; -} - -void CInMemStreamMt::Free() -{ - while(_streams.Size() > 0) - { - _streams.Back().Free(Callback); - _streams.DeleteBack(); - } -} - -HRESULT CInMemStreamMt::Read() -{ - for (;;) - { - // printf("\n_streamIndexAllocator.AllocateItem\n"); - int index = _streamIndexAllocator.AllocateItem(); - /* - if (_stopReading) - return E_ABORT; - */ - // printf("\nread Index = %d\n", index); - CStreamInfo &blocks = _streams[index]; - blocks.Init(); - Callback->AddStreamIndexToQueue(index); - - for (;;) - { - const Byte *p = (const Byte *)blocks.Blocks[blocks.LastBlockIndex]; - if (p == 0) - { - void **pp = &blocks.Blocks[blocks.LastBlockIndex]; - HRESULT res = Callback->AllocateBlock(pp); - p = (const Byte *)*pp; - RINOK(res); - if (p == 0) - return E_FAIL; - } - size_t blockSize = Callback->GetBlockSize(); - UInt32 curSize = (UInt32)(blockSize - blocks.LastBlockPos); - UInt32 realProcessedSize; - UInt64 pos64 = (UInt64)blocks.LastBlockIndex * blockSize + blocks.LastBlockPos; - if (curSize > _subStreamSize - pos64) - curSize = (UInt32)(_subStreamSize - pos64); - RINOK(_stream->Read((void *)(p + blocks.LastBlockPos), curSize, &realProcessedSize)); - - blocks.Cs->Enter(); - if (realProcessedSize == 0) - { - blocks.StreamWasFinished = true; - blocks.CanReadEvent->Set(); - blocks.Cs->Leave(); - - Callback->AddStreamIndexToQueue(-1); - return S_OK; - } - - blocks.LastBlockPos += realProcessedSize; - if (blocks.LastBlockPos == blockSize) - { - blocks.LastBlockPos = 0; - blocks.LastBlockIndex++; - } - pos64 += realProcessedSize; - if (pos64 >= _subStreamSize) - blocks.StreamWasFinished = true; - blocks.CanReadEvent->Set(); - blocks.Cs->Leave(); - if (pos64 >= _subStreamSize) - break; - } - } -} - -static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo) -{ - ((CInMemStreamMt *)threadCoderInfo)->ReadResult = ((CInMemStreamMt *)threadCoderInfo)->Read(); - return 0; -} - -HRes CInMemStreamMt::StartReadThread() -{ - // _stopReading = false; - NWindows::CThread Thread; - return Thread.Create(CoderThread, this); -} - -void CInMemStreamMt::FreeSubStream(int subStreamIndex) -{ - // printf("\nFreeSubStream\n"); - _streams[subStreamIndex].Free(Callback); - _streamIndexAllocator.FreeItem(subStreamIndex); - // printf("\nFreeSubStream end\n"); -} - -HRESULT CInMemStreamMt::ReadSubStream(int subStreamIndex, void *data, UInt32 size, UInt32 *processedSize, bool keepData) -{ - if (processedSize != NULL) - *processedSize = 0; - CStreamInfo &blocks = _streams[subStreamIndex]; - while (size > 0) - { - if (blocks.CurBlockPos == Callback->GetBlockSize()) - { - blocks.CurBlockPos = 0; - blocks.CurBlockIndex++; - } - UInt32 curSize; - UInt32 curPos = blocks.CurBlockPos; - - blocks.Cs->Enter(); - if (blocks.CurBlockIndex == blocks.LastBlockIndex) - { - curSize = blocks.LastBlockPos - curPos; - if (curSize == 0) - { - if (blocks.StreamWasFinished) - { - blocks.Cs->Leave(); - void *p = blocks.Blocks[blocks.CurBlockIndex]; - if (p != 0 && !keepData) - { - Callback->FreeBlock(p); - blocks.Blocks[blocks.CurBlockIndex] = 0; - } - return S_OK; - } - blocks.CanReadEvent->Reset(); - blocks.Cs->Leave(); - // printf("\nBlock Lock\n"); - blocks.CanReadEvent->Lock(); - // printf("\nAfter Lock\n"); - if (blocks.ExitResult != S_OK) - return blocks.ExitResult; - continue; - } - } - else - curSize = Callback->GetBlockSize() - curPos; - blocks.Cs->Leave(); - - if (curSize > size) - curSize = size; - void *p = blocks.Blocks[blocks.CurBlockIndex]; - memmove(data, (const Byte *)p + curPos, curSize); - data = (void *)((Byte *)data + curSize); - size -= curSize; - if (processedSize != NULL) - *processedSize += curSize; - curPos += curSize; - - bool needFree = false; - blocks.CurBlockPos = curPos; - - if (curPos == Callback->GetBlockSize()) - needFree = true; - blocks.Cs->Enter(); - if (blocks.CurBlockIndex == blocks.LastBlockIndex && - blocks.CurBlockPos == blocks.LastBlockPos && - blocks.StreamWasFinished) - needFree = true; - blocks.Cs->Leave(); - - if (needFree && !keepData) - { - Callback->FreeBlock(p); - blocks.Blocks[blocks.CurBlockIndex] = 0; - } - return S_OK; - } - return S_OK; -} - -STDMETHODIMP CInMemStream::Read(void *data, UInt32 size, UInt32 *processedSize) -{ - UInt32 realProcessedSize; - HRESULT result = mtStream->ReadSubStream(Index, data, size, &realProcessedSize, _keepData); - if (processedSize != NULL) - *processedSize = realProcessedSize; - if (realProcessedSize != 0) - { - // printf("\ns = %d\n", Index); - } - _size += realProcessedSize; - return result; -} diff --git a/src/libs/7zip/win/CPP/7zip/Common/InMemStream.h b/src/libs/7zip/win/CPP/7zip/Common/InMemStream.h deleted file mode 100644 index ec493977c..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/InMemStream.h +++ /dev/null @@ -1,284 +0,0 @@ -// InMemStream.h - -#ifndef __IN_MEM_STREAM_H -#define __IN_MEM_STREAM_H - -#include <stdio.h> - -#include "../../../C/Alloc.h" - -#include "../../Common/MyCom.h" - -#include "MemBlocks.h" - -class CIntListCheck -{ -protected: - int *_data; -public: - CIntListCheck(): _data(0) {} - ~CIntListCheck() { FreeList(); } - - bool AllocateList(int numItems) - { - FreeList(); - if (numItems == 0) - return true; - _data = (int *)::MyAlloc(numItems * sizeof(int)); - return (_data != 0); - } - - void FreeList() - { - ::MyFree(_data); - _data = 0; - } -}; - - -class CResourceList : public CIntListCheck -{ - int _headFree; -public: - CResourceList(): _headFree(-1) {} - - bool AllocateList(int numItems) - { - FreeList(); - if (numItems == 0) - return true; - if (!CIntListCheck::AllocateList(numItems)) - return false; - for (int i = 0; i < numItems; i++) - _data[i] = i + 1; - _data[numItems - 1] = -1; - _headFree = 0; - return true; - } - - void FreeList() - { - CIntListCheck::FreeList(); - _headFree = -1; - } - - int AllocateItem() - { - int res = _headFree; - if (res >= 0) - _headFree = _data[res]; - return res; - } - - void FreeItem(int index) - { - if (index < 0) - return; - _data[index] = _headFree; - _headFree = index; - } -}; - -class CResourceListMt: public CResourceList -{ - NWindows::NSynchronization::CCriticalSection _criticalSection; -public: - NWindows::NSynchronization::CSemaphore Semaphore; - - HRes AllocateList(int numItems) - { - if (!CResourceList::AllocateList(numItems)) - return E_OUTOFMEMORY; - Semaphore.Close(); - return Semaphore.Create(numItems, numItems); - } - - int AllocateItem() - { - Semaphore.Lock(); - _criticalSection.Enter(); - int res = CResourceList::AllocateItem(); - _criticalSection.Leave(); - return res; - } - - void FreeItem(int index) - { - if (index < 0) - return; - _criticalSection.Enter(); - CResourceList::FreeItem(index); - _criticalSection.Leave(); - Semaphore.Release(); - } -}; - -class CIntQueueMt: public CIntListCheck -{ - int _numItems; - int _head; - int _cur; -public: - CIntQueueMt(): _numItems(0), _head(0), _cur(0) {} - NWindows::NSynchronization::CSemaphore Semaphore; - - HRes AllocateList(int numItems) - { - FreeList(); - if (numItems == 0) - return S_OK; - if (!CIntListCheck::AllocateList(numItems)) - return E_OUTOFMEMORY; - _numItems = numItems; - return Semaphore.Create(0, numItems); - } - - void FreeList() - { - CIntListCheck::FreeList(); - _numItems = 0; - _head = 0; - _cur = 0; - } - - void AddItem(int value) - { - _data[_head++] = value; - if (_head == _numItems) - _head = 0; - Semaphore.Release(); - // printf("\nRelease prev = %d\n", previousCount); - } - - int GetItem() - { - // Semaphore.Lock(); - int res = _data[_cur++]; - if (_cur == _numItems) - _cur = 0; - return res; - } -}; - -struct IInMemStreamMtCallback -{ - // must be same for all calls - virtual size_t GetBlockSize() = 0; - - // Out: - // result != S_OK stops Reading - // if *p = 0, result must be != S_OK; - // Locking is allowed - virtual HRESULT AllocateBlock(void **p) = 0; - - virtual void FreeBlock(void *p) = 0; - - // It must allow to add at least numSubStreams + 1 , - // where numSubStreams is value from CInMemStreamMt::Create - // value -1 means End of stream - // Locking is not allowed - virtual void AddStreamIndexToQueue(int index) = 0; -}; - -struct CStreamInfo -{ - CRecordVector<void *> Blocks; - - int LastBlockIndex; - size_t LastBlockPos; - bool StreamWasFinished; - - int CurBlockIndex; - size_t CurBlockPos; - - NWindows::NSynchronization::CCriticalSection *Cs; - NWindows::NSynchronization::CManualResetEvent *CanReadEvent; - - HRESULT ExitResult; - - CStreamInfo(): Cs(0), CanReadEvent(0), StreamWasFinished(false) { } - ~CStreamInfo() - { - delete Cs; - delete CanReadEvent; - // Free(); - } - void Create() - { - Cs = new NWindows::NSynchronization::CCriticalSection; - CanReadEvent = new NWindows::NSynchronization::CManualResetEvent; - } - - void Free(IInMemStreamMtCallback *callback); - void Init() - { - LastBlockIndex = CurBlockIndex = 0; - CurBlockPos = LastBlockPos = 0; - StreamWasFinished = false; - ExitResult = S_OK; - } - - // res must be != S_OK - void Exit(HRESULT res) - { - ExitResult = res; - CanReadEvent->Set(); - } -}; - - -class CInMemStreamMt -{ - CMyComPtr<ISequentialInStream> _stream; - NWindows::NSynchronization::CCriticalSection CS; - CObjectVector<CStreamInfo> _streams; - int _nextFreeStreamIndex; - int _currentStreamIndex; - UInt64 _subStreamSize; - - CResourceListMt _streamIndexAllocator; - - // bool _stopReading; - -public: - HRESULT Read(); - HRESULT ReadResult; - IInMemStreamMtCallback *Callback; - void FreeSubStream(int subStreamIndex); - HRESULT ReadSubStream(int subStreamIndex, void *data, UInt32 size, UInt32 *processedSize, bool keepData); - - // numSubStreams: min = 1, good min = numThreads - bool Create(int numSubStreams, UInt64 subStreamSize); - ~CInMemStreamMt() { Free(); } - void SetStream(ISequentialInStream *stream) { _stream = stream; } - - // to stop reading you must implement - // returning Error in IInMemStreamMtCallback::AllocateBlock - // and then you must free at least one substream - HRes StartReadThread(); - - void Free(); - - // you must free at least one substream after that function to unlock waiting. - // void StopReading() { _stopReading = true; } -}; - -class CInMemStream: - public ISequentialInStream, - public CMyUnknownImp -{ - UInt64 _size; - bool _keepData; -public: - int Index; - CInMemStreamMt *mtStream; - void Init(bool keepData = false) - { - _size = 0; _keepData = keepData ; - } - MY_UNKNOWN_IMP - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); - UInt64 GetSize() const { return _size; } -}; - -#endif diff --git a/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.cpp b/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.cpp deleted file mode 100644 index a5b93b5e7..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// MemBlocks.cpp - -#include "StdAfx.h" - -#include "../../../C/Alloc.h" - -#include "MemBlocks.h" -#include "StreamUtils.h" - -bool CMemBlockManager::AllocateSpace(size_t numBlocks) -{ - FreeSpace(); - if (_blockSize < sizeof(void *) || numBlocks < 1) - return false; - size_t totalSize = numBlocks * _blockSize; - if (totalSize / _blockSize != numBlocks) - return false; - _data = ::MidAlloc(totalSize); - if (_data == 0) - return false; - Byte *p = (Byte *)_data; - for (size_t i = 0; i + 1 < numBlocks; i++, p += _blockSize) - *(Byte **)p = (p + _blockSize); - *(Byte **)p = 0; - _headFree = _data; - return true; -} - -void CMemBlockManager::FreeSpace() -{ - ::MidFree(_data); - _data = 0; - _headFree= 0; -} - -void *CMemBlockManager::AllocateBlock() -{ - if (_headFree == 0) - return 0; - void *p = _headFree; - _headFree = *(void **)_headFree; - return p; -} - -void CMemBlockManager::FreeBlock(void *p) -{ - if (p == 0) - return; - *(void **)p = _headFree; - _headFree = p; -} - - -HRes CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks) -{ - if (numNoLockBlocks > numBlocks) - return E_INVALIDARG; - if (!CMemBlockManager::AllocateSpace(numBlocks)) - return E_OUTOFMEMORY; - size_t numLockBlocks = numBlocks - numNoLockBlocks; - Semaphore.Close(); - return Semaphore.Create((LONG)numLockBlocks, (LONG)numLockBlocks); -} - -HRes CMemBlockManagerMt::AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks) -{ - if (numNoLockBlocks > desiredNumberOfBlocks) - return E_INVALIDARG; - for (;;) - { - if (AllocateSpace(desiredNumberOfBlocks, numNoLockBlocks) == 0) - return 0; - if (desiredNumberOfBlocks == numNoLockBlocks) - return E_OUTOFMEMORY; - desiredNumberOfBlocks = numNoLockBlocks + ((desiredNumberOfBlocks - numNoLockBlocks) >> 1); - } -} - -void CMemBlockManagerMt::FreeSpace() -{ - Semaphore.Close(); - CMemBlockManager::FreeSpace(); -} - -void *CMemBlockManagerMt::AllocateBlock() -{ - // Semaphore.Lock(); - NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); - return CMemBlockManager::AllocateBlock(); -} - -void CMemBlockManagerMt::FreeBlock(void *p, bool lockMode) -{ - if (p == 0) - return; - { - NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); - CMemBlockManager::FreeBlock(p); - } - if (lockMode) - Semaphore.Release(); -} - -void CMemBlocks::Free(CMemBlockManagerMt *manager) -{ - while(Blocks.Size() > 0) - { - manager->FreeBlock(Blocks.Back()); - Blocks.DeleteBack(); - } - TotalSize = 0; -} - -void CMemBlocks::FreeOpt(CMemBlockManagerMt *manager) -{ - Free(manager); - Blocks.ClearAndFree(); -} - -HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const -{ - UInt64 totalSize = TotalSize; - for (int blockIndex = 0; totalSize > 0; blockIndex++) - { - UInt32 curSize = (UInt32)blockSize; - if (totalSize < curSize) - curSize = (UInt32)totalSize; - if (blockIndex >= Blocks.Size()) - return E_FAIL; - RINOK(WriteStream(outStream, Blocks[blockIndex], curSize)); - totalSize -= curSize; - } - return S_OK; -} - - -void CMemLockBlocks::FreeBlock(int index, CMemBlockManagerMt *memManager) -{ - memManager->FreeBlock(Blocks[index], LockMode); - Blocks[index] = 0; -} - -void CMemLockBlocks::Free(CMemBlockManagerMt *memManager) -{ - while (Blocks.Size() > 0) - { - FreeBlock(Blocks.Size() - 1, memManager); - Blocks.DeleteBack(); - } - TotalSize = 0; -} - -HRes CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager) -{ - if (LockMode) - { - if (Blocks.Size() > 0) - { - RINOK(memManager->ReleaseLockedBlocks(Blocks.Size())); - } - LockMode = false; - } - return 0; -} - -void CMemLockBlocks::Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager) -{ - blocks.Free(memManager); - blocks.LockMode = LockMode; - UInt64 totalSize = 0; - size_t blockSize = memManager->GetBlockSize(); - for (int i = 0; i < Blocks.Size(); i++) - { - if (totalSize < TotalSize) - blocks.Blocks.Add(Blocks[i]); - else - FreeBlock(i, memManager); - Blocks[i] = 0; - totalSize += blockSize; - } - blocks.TotalSize = TotalSize; - Free(memManager); -} diff --git a/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.h b/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.h deleted file mode 100644 index e1058ae38..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/MemBlocks.h +++ /dev/null @@ -1,71 +0,0 @@ -// MemBlocks.h - -#ifndef __MEM_BLOCKS_H -#define __MEM_BLOCKS_H - -#include "Common/MyVector.h" - -#include "Windows/Synchronization.h" - -#include "../IStream.h" - -class CMemBlockManager -{ - void *_data; - size_t _blockSize; - void *_headFree; -public: - CMemBlockManager(size_t blockSize = (1 << 20)): _data(0), _blockSize(blockSize), _headFree(0) {} - ~CMemBlockManager() { FreeSpace(); } - - bool AllocateSpace(size_t numBlocks); - void FreeSpace(); - size_t GetBlockSize() const { return _blockSize; } - void *AllocateBlock(); - void FreeBlock(void *p); -}; - - -class CMemBlockManagerMt: public CMemBlockManager -{ - NWindows::NSynchronization::CCriticalSection _criticalSection; -public: - NWindows::NSynchronization::CSemaphore Semaphore; - - CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {} - ~CMemBlockManagerMt() { FreeSpace(); } - - HRes AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0); - HRes AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0); - void FreeSpace(); - void *AllocateBlock(); - void FreeBlock(void *p, bool lockMode = true); - HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); } -}; - - -class CMemBlocks -{ - void Free(CMemBlockManagerMt *manager); -public: - CRecordVector<void *> Blocks; - UInt64 TotalSize; - - CMemBlocks(): TotalSize(0) {} - - void FreeOpt(CMemBlockManagerMt *manager); - HRESULT WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const; -}; - -struct CMemLockBlocks: public CMemBlocks -{ - bool LockMode; - - CMemLockBlocks(): LockMode(true) {}; - void Free(CMemBlockManagerMt *memManager); - void FreeBlock(int index, CMemBlockManagerMt *memManager); - HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager); - void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager); -}; - -#endif diff --git a/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.cpp b/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.cpp deleted file mode 100644 index 2e92886b8..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// OutMemStream.cpp - -#include "StdAfx.h" - -#include "OutMemStream.h" - -void COutMemStream::Free() -{ - Blocks.Free(_memManager); - Blocks.LockMode = true; -} - -void COutMemStream::Init() -{ - WriteToRealStreamEvent.Reset(); - _unlockEventWasSent = false; - _realStreamMode = false; - Free(); - _curBlockPos = 0; - _curBlockIndex = 0; -} - -void COutMemStream::DetachData(CMemLockBlocks &blocks) -{ - Blocks.Detach(blocks, _memManager); - Free(); -} - - -HRESULT COutMemStream::WriteToRealStream() -{ - RINOK(Blocks.WriteToStream(_memManager->GetBlockSize(), OutSeqStream)); - Blocks.Free(_memManager); - return S_OK; -} - -STDMETHODIMP COutMemStream::Write(const void *data, UInt32 size, UInt32 *processedSize) -{ - if (_realStreamMode) - return OutSeqStream->Write(data, size, processedSize); - if (processedSize != 0) - *processedSize = 0; - while(size != 0) - { - if ((int)_curBlockIndex < Blocks.Blocks.Size()) - { - Byte *p = (Byte *)Blocks.Blocks[(int)_curBlockIndex] + _curBlockPos; - size_t curSize = _memManager->GetBlockSize() - _curBlockPos; - if (size < curSize) - curSize = size; - memmove(p, data, curSize); - if (processedSize != 0) - *processedSize += (UInt32)curSize; - data = (const void *)((const Byte *)data + curSize); - size -= (UInt32)curSize; - _curBlockPos += curSize; - - UInt64 pos64 = GetPos(); - if (pos64 > Blocks.TotalSize) - Blocks.TotalSize = pos64; - if (_curBlockPos == _memManager->GetBlockSize()) - { - _curBlockIndex++; - _curBlockPos = 0; - } - continue; - } - HANDLE events[3] = { StopWritingEvent, WriteToRealStreamEvent, /* NoLockEvent, */ _memManager->Semaphore }; - DWORD waitResult = ::WaitForMultipleObjects((Blocks.LockMode ? 3 : 2), events, FALSE, INFINITE); - switch (waitResult) - { - case (WAIT_OBJECT_0 + 0): - return StopWriteResult; - case (WAIT_OBJECT_0 + 1): - { - _realStreamMode = true; - RINOK(WriteToRealStream()); - UInt32 processedSize2; - HRESULT res = OutSeqStream->Write(data, size, &processedSize2); - if (processedSize != 0) - *processedSize += processedSize2; - return res; - } - /* - case (WAIT_OBJECT_0 + 2): - { - // it has bug: no write. - if (!Blocks.SwitchToNoLockMode(_memManager)) - return E_FAIL; - break; - } - */ - case (WAIT_OBJECT_0 + 2): - break; - default: - return E_FAIL; - } - Blocks.Blocks.Add(_memManager->AllocateBlock()); - if (Blocks.Blocks.Back() == 0) - return E_FAIL; - } - return S_OK; -} - -STDMETHODIMP COutMemStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) -{ - if (_realStreamMode) - { - if (!OutStream) - return E_FAIL; - return OutStream->Seek(offset, seekOrigin, newPosition); - } - if (seekOrigin == STREAM_SEEK_CUR) - { - if (offset != 0) - return E_NOTIMPL; - } - else if (seekOrigin == STREAM_SEEK_SET) - { - if (offset != 0) - return E_NOTIMPL; - _curBlockIndex = 0; - _curBlockPos = 0; - } - else - return E_NOTIMPL; - if (newPosition != 0) - *newPosition = GetPos(); - return S_OK; -} - -STDMETHODIMP COutMemStream::SetSize(UInt64 newSize) -{ - if (_realStreamMode) - { - if (!OutStream) - return E_FAIL; - return OutStream->SetSize(newSize); - } - Blocks.TotalSize = newSize; - return S_OK; -} diff --git a/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.h b/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.h deleted file mode 100644 index b47f339e9..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/OutMemStream.h +++ /dev/null @@ -1,96 +0,0 @@ -// OutMemStream.h - -#ifndef __OUTMEMSTREAM_H -#define __OUTMEMSTREAM_H - -#include "Common/MyCom.h" -#include "MemBlocks.h" - -class COutMemStream: - public IOutStream, - public CMyUnknownImp -{ - CMemBlockManagerMt *_memManager; - size_t _curBlockIndex; - size_t _curBlockPos; - bool _realStreamMode; - - bool _unlockEventWasSent; - NWindows::NSynchronization::CAutoResetEvent StopWritingEvent; - NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent; - // NWindows::NSynchronization::CAutoResetEvent NoLockEvent; - - HRESULT StopWriteResult; - CMemLockBlocks Blocks; - - UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; } - - CMyComPtr<ISequentialOutStream> OutSeqStream; - CMyComPtr<IOutStream> OutStream; - -public: - - HRes CreateEvents() - { - RINOK(StopWritingEvent.CreateIfNotCreated()); - return WriteToRealStreamEvent.CreateIfNotCreated(); - } - - void SetOutStream(IOutStream *outStream) - { - OutStream = outStream; - OutSeqStream = outStream; - } - - void SetSeqOutStream(ISequentialOutStream *outStream) - { - OutStream = NULL; - OutSeqStream = outStream; - } - - void ReleaseOutStream() - { - OutStream.Release(); - OutSeqStream.Release(); - } - - COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager) { } - - ~COutMemStream() { Free(); } - void Free(); - - void Init(); - HRESULT WriteToRealStream(); - - void DetachData(CMemLockBlocks &blocks); - - bool WasUnlockEventSent() const { return _unlockEventWasSent; } - - void SetRealStreamMode() - { - _unlockEventWasSent = true; - WriteToRealStreamEvent.Set(); - } - - /* - void SetNoLockMode() - { - _unlockEventWasSent = true; - NoLockEvent.Set(); - } - */ - - void StopWriting(HRESULT res) - { - StopWriteResult = res; - StopWritingEvent.Set(); - } - - MY_UNKNOWN_IMP - - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); - STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); - STDMETHOD(SetSize)(UInt64 newSize); -}; - -#endif diff --git a/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.cpp b/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.cpp deleted file mode 100644 index 319bd241b..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// ProgressMt.h - -#include "StdAfx.h" - -#include "ProgressMt.h" - -void CMtCompressProgressMixer::Init(int numItems, ICompressProgressInfo *progress) -{ - NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); - InSizes.Clear(); - OutSizes.Clear(); - for (int i = 0; i < numItems; i++) - { - InSizes.Add(0); - OutSizes.Add(0); - } - TotalInSize = 0; - TotalOutSize = 0; - _progress = progress; -} - -void CMtCompressProgressMixer::Reinit(int index) -{ - NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); - InSizes[index] = 0; - OutSizes[index] = 0; -} - -HRESULT CMtCompressProgressMixer::SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize) -{ - NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); - if (inSize != 0) - { - UInt64 diff = *inSize - InSizes[index]; - InSizes[index] = *inSize; - TotalInSize += diff; - } - if (outSize != 0) - { - UInt64 diff = *outSize - OutSizes[index]; - OutSizes[index] = *outSize; - TotalOutSize += diff; - } - if (_progress) - return _progress->SetRatioInfo(&TotalInSize, &TotalOutSize); - return S_OK; -} - - -STDMETHODIMP CMtCompressProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) -{ - return _progress->SetRatioInfo(_index, inSize, outSize); -} diff --git a/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.h b/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.h deleted file mode 100644 index 26079d4e9..000000000 --- a/src/libs/7zip/win/CPP/7zip/Common/ProgressMt.h +++ /dev/null @@ -1,46 +0,0 @@ -// ProgressMt.h - -#ifndef __PROGRESSMT_H -#define __PROGRESSMT_H - -#include "../../Common/MyCom.h" -#include "../../Common/MyVector.h" -#include "../../Windows/Synchronization.h" - -#include "../ICoder.h" -#include "../IProgress.h" - -class CMtCompressProgressMixer -{ - CMyComPtr<ICompressProgressInfo> _progress; - CRecordVector<UInt64> InSizes; - CRecordVector<UInt64> OutSizes; - UInt64 TotalInSize; - UInt64 TotalOutSize; -public: - NWindows::NSynchronization::CCriticalSection CriticalSection; - void Init(int numItems, ICompressProgressInfo *progress); - void Reinit(int index); - HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize); -}; - -class CMtCompressProgress: - public ICompressProgressInfo, - public CMyUnknownImp -{ - CMtCompressProgressMixer *_progress; - int _index; -public: - void Init(CMtCompressProgressMixer *progress, int index) - { - _progress = progress; - _index = index; - } - void Reinit() { _progress->Reinit(_index); } - - MY_UNKNOWN_IMP - - STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); -}; - -#endif |