Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.3 KiB

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