summaryrefslogtreecommitdiffstats
path: root/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@nokia.com>2011-02-21 16:30:31 +0100
committerTim Jenssen <tim.jenssen@nokia.com>2011-02-21 16:41:32 +0100
commit8457830abdca9d5769e2ec1bdbfb793a05e6c5dd (patch)
tree4c9e87efd34104ec59ae31efd0394e998a2434f7 /installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h
init commit
Diffstat (limited to 'installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h')
-rw-r--r--installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h
new file mode 100644
index 000000000..f23852fbd
--- /dev/null
+++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/Common/MemBlocks.h
@@ -0,0 +1,71 @@
+// 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::CSemaphoreWFMO Semaphore;
+
+ CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {}
+ ~CMemBlockManagerMt() { FreeSpace(); }
+
+ HRes AllocateSpace(NWindows::NSynchronization::CSynchro *sync, size_t numBlocks, size_t numNoLockBlocks = 0);
+ HRes AllocateSpaceAlways(NWindows::NSynchronization::CSynchro *sync, 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