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