mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-12 07:09:54 -06:00
Initialer Commit
This commit is contained in:
71
CPP/7zip/Common/MemBlocks.h
Normal file
71
CPP/7zip/Common/MemBlocks.h
Normal file
@@ -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::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
|
||||
Reference in New Issue
Block a user