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