rlm@1: /* LzFindMt.h -- multithreaded Match finder for LZ algorithms rlm@1: 2008-10-04 : Igor Pavlov : Public domain */ rlm@1: rlm@1: #ifndef __LZFINDMT_H rlm@1: #define __LZFINDMT_H rlm@1: rlm@1: #include "Threads.h" rlm@1: #include "LzFind.h" rlm@1: rlm@1: #define kMtHashBlockSize (1 << 13) rlm@1: #define kMtHashNumBlocks (1 << 3) rlm@1: #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) rlm@1: rlm@1: #define kMtBtBlockSize (1 << 14) rlm@1: #define kMtBtNumBlocks (1 << 6) rlm@1: #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) rlm@1: rlm@1: typedef struct _CMtSync rlm@1: { rlm@1: Bool wasCreated; rlm@1: Bool needStart; rlm@1: Bool exit; rlm@1: Bool stopWriting; rlm@1: rlm@1: CThread thread; rlm@1: CAutoResetEvent canStart; rlm@1: CAutoResetEvent wasStarted; rlm@1: CAutoResetEvent wasStopped; rlm@1: CSemaphore freeSemaphore; rlm@1: CSemaphore filledSemaphore; rlm@1: Bool csWasInitialized; rlm@1: Bool csWasEntered; rlm@1: CCriticalSection cs; rlm@1: UInt32 numProcessedBlocks; rlm@1: } CMtSync; rlm@1: rlm@1: typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); rlm@1: rlm@1: /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ rlm@1: #define kMtCacheLineDummy 128 rlm@1: rlm@1: typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, rlm@1: UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); rlm@1: rlm@1: typedef struct _CMatchFinderMt rlm@1: { rlm@1: /* LZ */ rlm@1: const Byte *pointerToCurPos; rlm@1: UInt32 *btBuf; rlm@1: UInt32 btBufPos; rlm@1: UInt32 btBufPosLimit; rlm@1: UInt32 lzPos; rlm@1: UInt32 btNumAvailBytes; rlm@1: rlm@1: UInt32 *hash; rlm@1: UInt32 fixedHashSize; rlm@1: UInt32 historySize; rlm@1: const UInt32 *crc; rlm@1: rlm@1: Mf_Mix_Matches MixMatchesFunc; rlm@1: rlm@1: /* LZ + BT */ rlm@1: CMtSync btSync; rlm@1: Byte btDummy[kMtCacheLineDummy]; rlm@1: rlm@1: /* BT */ rlm@1: UInt32 *hashBuf; rlm@1: UInt32 hashBufPos; rlm@1: UInt32 hashBufPosLimit; rlm@1: UInt32 hashNumAvail; rlm@1: rlm@1: CLzRef *son; rlm@1: UInt32 matchMaxLen; rlm@1: UInt32 numHashBytes; rlm@1: UInt32 pos; rlm@1: Byte *buffer; rlm@1: UInt32 cyclicBufferPos; rlm@1: UInt32 cyclicBufferSize; /* it must be historySize + 1 */ rlm@1: UInt32 cutValue; rlm@1: rlm@1: /* BT + Hash */ rlm@1: CMtSync hashSync; rlm@1: /* Byte hashDummy[kMtCacheLineDummy]; */ rlm@1: rlm@1: /* Hash */ rlm@1: Mf_GetHeads GetHeadsFunc; rlm@1: CMatchFinder *MatchFinder; rlm@1: } CMatchFinderMt; rlm@1: rlm@1: void MatchFinderMt_Construct(CMatchFinderMt *p); rlm@1: void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); rlm@1: SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, rlm@1: UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); rlm@1: void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); rlm@1: void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); rlm@1: rlm@1: #endif