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