1 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms 2 2023-03-05 : Igor Pavlov : Public domain */ 3 4 #ifndef ZIP7_INC_LZ_FIND_MT_H 5 #define ZIP7_INC_LZ_FIND_MT_H 6 7 #include "LzFind.h" 8 #include "Threads.h" 9 10 EXTERN_C_BEGIN 11 12 typedef struct 13 { 14 UInt32 numProcessedBlocks; 15 CThread thread; 16 UInt64 affinity; 17 18 BoolInt wasCreated; 19 BoolInt needStart; 20 BoolInt csWasInitialized; 21 BoolInt csWasEntered; 22 23 BoolInt exit; 24 BoolInt stopWriting; 25 26 CAutoResetEvent canStart; 27 CAutoResetEvent wasStopped; 28 CSemaphore freeSemaphore; 29 CSemaphore filledSemaphore; 30 CCriticalSection cs; 31 // UInt32 numBlocks_Sent; 32 } CMtSync; 33 34 typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 35 36 /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 37 #define kMtCacheLineDummy 128 38 39 typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, 40 UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); 41 42 typedef struct 43 { 44 /* LZ */ 45 const Byte *pointerToCurPos; 46 UInt32 *btBuf; 47 const UInt32 *btBufPos; 48 const UInt32 *btBufPosLimit; 49 UInt32 lzPos; 50 UInt32 btNumAvailBytes; 51 52 UInt32 *hash; 53 UInt32 fixedHashSize; 54 // UInt32 hash4Mask; 55 UInt32 historySize; 56 const UInt32 *crc; 57 58 Mf_Mix_Matches MixMatchesFunc; 59 UInt32 failure_LZ_BT; // failure in BT transfered to LZ 60 // UInt32 failure_LZ_LZ; // failure in LZ tables 61 UInt32 failureBuf[1]; 62 // UInt32 crc[256]; 63 64 /* LZ + BT */ 65 CMtSync btSync; 66 Byte btDummy[kMtCacheLineDummy]; 67 68 /* BT */ 69 UInt32 *hashBuf; 70 UInt32 hashBufPos; 71 UInt32 hashBufPosLimit; 72 UInt32 hashNumAvail; 73 UInt32 failure_BT; 74 75 76 CLzRef *son; 77 UInt32 matchMaxLen; 78 UInt32 numHashBytes; 79 UInt32 pos; 80 const Byte *buffer; 81 UInt32 cyclicBufferPos; 82 UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 83 UInt32 cutValue; 84 85 /* BT + Hash */ 86 CMtSync hashSync; 87 /* Byte hashDummy[kMtCacheLineDummy]; */ 88 89 /* Hash */ 90 Mf_GetHeads GetHeadsFunc; 91 CMatchFinder *MatchFinder; 92 // CMatchFinder MatchFinder; 93 } CMatchFinderMt; 94 95 // only for Mt part 96 void MatchFinderMt_Construct(CMatchFinderMt *p); 97 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc); 98 99 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 100 UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc); 101 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable); 102 103 /* call MatchFinderMt_InitMt() before IMatchFinder::Init() */ 104 SRes MatchFinderMt_InitMt(CMatchFinderMt *p); 105 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 106 107 EXTERN_C_END 108 109 #endif 110