Lines Matching refs:p

10 static void MtSync_Construct(CMtSync *p)  in MtSync_Construct()  argument
12 p->wasCreated = False; in MtSync_Construct()
13 p->csWasInitialized = False; in MtSync_Construct()
14 p->csWasEntered = False; in MtSync_Construct()
15 Thread_Construct(&p->thread); in MtSync_Construct()
16 Event_Construct(&p->canStart); in MtSync_Construct()
17 Event_Construct(&p->wasStarted); in MtSync_Construct()
18 Event_Construct(&p->wasStopped); in MtSync_Construct()
19 Semaphore_Construct(&p->freeSemaphore); in MtSync_Construct()
20 Semaphore_Construct(&p->filledSemaphore); in MtSync_Construct()
23 static void MtSync_GetNextBlock(CMtSync *p) in MtSync_GetNextBlock() argument
25 if (p->needStart) in MtSync_GetNextBlock()
27 p->numProcessedBlocks = 1; in MtSync_GetNextBlock()
28 p->needStart = False; in MtSync_GetNextBlock()
29 p->stopWriting = False; in MtSync_GetNextBlock()
30 p->exit = False; in MtSync_GetNextBlock()
31 Event_Reset(&p->wasStarted); in MtSync_GetNextBlock()
32 Event_Reset(&p->wasStopped); in MtSync_GetNextBlock()
34 Event_Set(&p->canStart); in MtSync_GetNextBlock()
35 Event_Wait(&p->wasStarted); in MtSync_GetNextBlock()
41 CriticalSection_Leave(&p->cs); in MtSync_GetNextBlock()
42 p->csWasEntered = False; in MtSync_GetNextBlock()
43 p->numProcessedBlocks++; in MtSync_GetNextBlock()
44 Semaphore_Release1(&p->freeSemaphore); in MtSync_GetNextBlock()
46 Semaphore_Wait(&p->filledSemaphore); in MtSync_GetNextBlock()
47 CriticalSection_Enter(&p->cs); in MtSync_GetNextBlock()
48 p->csWasEntered = True; in MtSync_GetNextBlock()
53 static void MtSync_StopWriting(CMtSync *p) in MtSync_StopWriting() argument
55 UInt32 myNumBlocks = p->numProcessedBlocks; in MtSync_StopWriting()
56 if (!Thread_WasCreated(&p->thread) || p->needStart) in MtSync_StopWriting()
58 p->stopWriting = True; in MtSync_StopWriting()
59 if (p->csWasEntered) in MtSync_StopWriting()
61 CriticalSection_Leave(&p->cs); in MtSync_StopWriting()
62 p->csWasEntered = False; in MtSync_StopWriting()
64 Semaphore_Release1(&p->freeSemaphore); in MtSync_StopWriting()
66 Event_Wait(&p->wasStopped); in MtSync_StopWriting()
68 while (myNumBlocks++ != p->numProcessedBlocks) in MtSync_StopWriting()
70 Semaphore_Wait(&p->filledSemaphore); in MtSync_StopWriting()
71 Semaphore_Release1(&p->freeSemaphore); in MtSync_StopWriting()
73 p->needStart = True; in MtSync_StopWriting()
76 static void MtSync_Destruct(CMtSync *p) in MtSync_Destruct() argument
78 if (Thread_WasCreated(&p->thread)) in MtSync_Destruct()
80 MtSync_StopWriting(p); in MtSync_Destruct()
81 p->exit = True; in MtSync_Destruct()
82 if (p->needStart) in MtSync_Destruct()
83 Event_Set(&p->canStart); in MtSync_Destruct()
84 Thread_Wait(&p->thread); in MtSync_Destruct()
85 Thread_Close(&p->thread); in MtSync_Destruct()
87 if (p->csWasInitialized) in MtSync_Destruct()
89 CriticalSection_Delete(&p->cs); in MtSync_Destruct()
90 p->csWasInitialized = False; in MtSync_Destruct()
93 Event_Close(&p->canStart); in MtSync_Destruct()
94 Event_Close(&p->wasStarted); in MtSync_Destruct()
95 Event_Close(&p->wasStopped); in MtSync_Destruct()
96 Semaphore_Close(&p->freeSemaphore); in MtSync_Destruct()
97 Semaphore_Close(&p->filledSemaphore); in MtSync_Destruct()
99 p->wasCreated = False; in MtSync_Destruct()
104 static SRes MtSync_Create2(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks) in MtSync_Create2() argument
106 if (p->wasCreated) in MtSync_Create2()
109 RINOK_THREAD(CriticalSection_Init(&p->cs)); in MtSync_Create2()
110 p->csWasInitialized = True; in MtSync_Create2()
112 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); in MtSync_Create2()
113 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); in MtSync_Create2()
114 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); in MtSync_Create2()
116 RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); in MtSync_Create2()
117 RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); in MtSync_Create2()
119 p->needStart = True; in MtSync_Create2()
121 RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); in MtSync_Create2()
122 p->wasCreated = True; in MtSync_Create2()
126 static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks) in MtSync_Create() argument
128 SRes res = MtSync_Create2(p, startAddress, obj, numBlocks); in MtSync_Create()
130 MtSync_Destruct(p); in MtSync_Create()
134 void MtSync_Init(CMtSync *p) { p->needStart = True; } in MtSync_Init() argument
139 static void GetHeads ## name(const Byte *p, UInt32 pos, \
142 const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
146 DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), UNUSED_VAR(hashMask); UNUSED_VAR(crc); )
147 DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
148 DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
149 DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
154 CMtSync *p = &mt->hashSync; in HashThreadFunc() local
158 Event_Wait(&p->canStart); in HashThreadFunc()
159 Event_Set(&p->wasStarted); in HashThreadFunc()
165 if (p->exit) in HashThreadFunc()
167 if (p->stopWriting) in HashThreadFunc()
169 p->numProcessedBlocks = numProcessedBlocks; in HashThreadFunc()
170 Event_Set(&p->wasStopped); in HashThreadFunc()
193 Semaphore_Wait(&p->freeSemaphore); in HashThreadFunc()
220 Semaphore_Release1(&p->filledSemaphore); in HashThreadFunc()
225 static void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p) in MatchFinderMt_GetNextBlock_Hash() argument
227 MtSync_GetNextBlock(&p->hashSync); in MatchFinderMt_GetNextBlock_Hash()
228p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask)… in MatchFinderMt_GetNextBlock_Hash()
229 p->hashBufPosLimit += p->hashBuf[p->hashBufPos++]; in MatchFinderMt_GetNextBlock_Hash()
230 p->hashNumAvail = p->hashBuf[p->hashBufPos++]; in MatchFinderMt_GetNextBlock_Hash()
349 static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances) in BtGetMatches() argument
353 UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); // * 2 in BtGetMatches()
355 distances[1] = p->hashNumAvail; in BtGetMatches()
359 if (p->hashBufPos == p->hashBufPosLimit) in BtGetMatches()
361 MatchFinderMt_GetNextBlock_Hash(p); in BtGetMatches()
362 distances[1] = numProcessed + p->hashNumAvail; in BtGetMatches()
363 if (p->hashNumAvail >= p->numHashBytes) in BtGetMatches()
365 distances[0] = curPos + p->hashNumAvail; in BtGetMatches()
367 for (; p->hashNumAvail != 0; p->hashNumAvail--) in BtGetMatches()
372 UInt32 size = p->hashBufPosLimit - p->hashBufPos; in BtGetMatches()
373 UInt32 lenLimit = p->matchMaxLen; in BtGetMatches()
374 UInt32 pos = p->pos; in BtGetMatches()
375 UInt32 cyclicBufferPos = p->cyclicBufferPos; in BtGetMatches()
376 if (lenLimit >= p->hashNumAvail) in BtGetMatches()
377 lenLimit = p->hashNumAvail; in BtGetMatches()
379 UInt32 size2 = p->hashNumAvail - lenLimit + 1; in BtGetMatches()
382 size2 = p->cyclicBufferSize - cyclicBufferPos; in BtGetMatches()
391 UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], in BtGetMatches()
392 pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, in BtGetMatches()
393 startDistances + 1, p->numHashBytes - 1) - startDistances); in BtGetMatches()
398 p->buffer++; in BtGetMatches()
403 …rPos = (UInt32)(GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBuffer… in BtGetMatches()
404 distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, in BtGetMatches()
407 p->hashBufPos += posRes - pos; in BtGetMatches()
409 p->buffer += posRes - pos; in BtGetMatches()
414 numProcessed += pos - p->pos; in BtGetMatches()
415 p->hashNumAvail -= pos - p->pos; in BtGetMatches()
416 p->pos = pos; in BtGetMatches()
417 if (cyclicBufferPos == p->cyclicBufferSize) in BtGetMatches()
419 p->cyclicBufferPos = cyclicBufferPos; in BtGetMatches()
426 static void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex) in BtFillBlock() argument
428 CMtSync *sync = &p->hashSync; in BtFillBlock()
435 BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); in BtFillBlock()
437 if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize) in BtFillBlock()
439 UInt32 subValue = p->pos - p->cyclicBufferSize; in BtFillBlock()
440 MatchFinder_Normalize3(subValue, p->son, (size_t)p->cyclicBufferSize * 2); in BtFillBlock()
441 p->pos -= subValue; in BtFillBlock()
453 CMtSync *p = &mt->btSync; in BtThreadFunc() local
457 Event_Wait(&p->canStart); in BtThreadFunc()
458 Event_Set(&p->wasStarted); in BtThreadFunc()
461 if (p->exit) in BtThreadFunc()
463 if (p->stopWriting) in BtThreadFunc()
465 p->numProcessedBlocks = blockIndex; in BtThreadFunc()
467 Event_Set(&p->wasStopped); in BtThreadFunc()
470 Semaphore_Wait(&p->freeSemaphore); in BtThreadFunc()
472 Semaphore_Release1(&p->filledSemaphore); in BtThreadFunc()
477 void MatchFinderMt_Construct(CMatchFinderMt *p) in MatchFinderMt_Construct() argument
479 p->hashBuf = NULL; in MatchFinderMt_Construct()
480 MtSync_Construct(&p->hashSync); in MatchFinderMt_Construct()
481 MtSync_Construct(&p->btSync); in MatchFinderMt_Construct()
484 static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAllocPtr alloc) in MatchFinderMt_FreeMem() argument
486 ISzAlloc_Free(alloc, p->hashBuf); in MatchFinderMt_FreeMem()
487 p->hashBuf = NULL; in MatchFinderMt_FreeMem()
490 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc) in MatchFinderMt_Destruct() argument
492 MtSync_Destruct(&p->hashSync); in MatchFinderMt_Destruct()
493 MtSync_Destruct(&p->btSync); in MatchFinderMt_Destruct()
494 MatchFinderMt_FreeMem(p, alloc); in MatchFinderMt_Destruct()
500 …UNC_RET_TYPE THREAD_FUNC_CALL_TYPE HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);… in HashThreadFunc2() argument
501 static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p) in BtThreadFunc2() argument
508 BtThreadFunc((CMatchFinderMt *)p); in BtThreadFunc2()
512 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, in MatchFinderMt_Create() argument
515 CMatchFinder *mf = p->MatchFinder; in MatchFinderMt_Create()
516 p->historySize = historySize; in MatchFinderMt_Create()
519 if (!p->hashBuf) in MatchFinderMt_Create()
521p->hashBuf = (UInt32 *)ISzAlloc_Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32)); in MatchFinderMt_Create()
522 if (!p->hashBuf) in MatchFinderMt_Create()
524 p->btBuf = p->hashBuf + kHashBufferSize; in MatchFinderMt_Create()
531 RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks)); in MatchFinderMt_Create()
532 RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks)); in MatchFinderMt_Create()
537 static void MatchFinderMt_Init(CMatchFinderMt *p) in MatchFinderMt_Init() argument
539 CMatchFinder *mf = p->MatchFinder; in MatchFinderMt_Init()
541 p->btBufPos = in MatchFinderMt_Init()
542 p->btBufPosLimit = 0; in MatchFinderMt_Init()
543 p->hashBufPos = in MatchFinderMt_Init()
544 p->hashBufPosLimit = 0; in MatchFinderMt_Init()
550 p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf); in MatchFinderMt_Init()
551 p->btNumAvailBytes = 0; in MatchFinderMt_Init()
552 p->lzPos = p->historySize + 1; in MatchFinderMt_Init()
554 p->hash = mf->hash; in MatchFinderMt_Init()
555 p->fixedHashSize = mf->fixedHashSize; in MatchFinderMt_Init()
556 p->crc = mf->crc; in MatchFinderMt_Init()
558 p->son = mf->son; in MatchFinderMt_Init()
559 p->matchMaxLen = mf->matchMaxLen; in MatchFinderMt_Init()
560 p->numHashBytes = mf->numHashBytes; in MatchFinderMt_Init()
561 p->pos = mf->pos; in MatchFinderMt_Init()
562 p->buffer = mf->buffer; in MatchFinderMt_Init()
563 p->cyclicBufferPos = mf->cyclicBufferPos; in MatchFinderMt_Init()
564 p->cyclicBufferSize = mf->cyclicBufferSize; in MatchFinderMt_Init()
565 p->cutValue = mf->cutValue; in MatchFinderMt_Init()
569 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p) in MatchFinderMt_ReleaseStream() argument
571 MtSync_StopWriting(&p->btSync); in MatchFinderMt_ReleaseStream()
575 static void MatchFinderMt_Normalize(CMatchFinderMt *p) in MatchFinderMt_Normalize() argument
577 MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize); in MatchFinderMt_Normalize()
578 p->lzPos = p->historySize + 1; in MatchFinderMt_Normalize()
581 static void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p) in MatchFinderMt_GetNextBlock_Bt() argument
584 MtSync_GetNextBlock(&p->btSync); in MatchFinderMt_GetNextBlock_Bt()
585 blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask); in MatchFinderMt_GetNextBlock_Bt()
586 p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize; in MatchFinderMt_GetNextBlock_Bt()
587 p->btBufPosLimit += p->btBuf[p->btBufPos++]; in MatchFinderMt_GetNextBlock_Bt()
588 p->btNumAvailBytes = p->btBuf[p->btBufPos++]; in MatchFinderMt_GetNextBlock_Bt()
589 if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) in MatchFinderMt_GetNextBlock_Bt()
590 MatchFinderMt_Normalize(p); in MatchFinderMt_GetNextBlock_Bt()
593 static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p) in MatchFinderMt_GetPointerToCurrentPos() argument
595 return p->pointerToCurPos; in MatchFinderMt_GetPointerToCurrentPos()
598 #define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_…
600 static UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p) in MatchFinderMt_GetNumAvailableBytes() argument
603 return p->btNumAvailBytes; in MatchFinderMt_GetNumAvailableBytes()
606 static UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) in MixMatches2() argument
609 UInt32 *hash = p->hash; in MixMatches2()
610 const Byte *cur = p->pointerToCurPos; in MixMatches2()
611 UInt32 lzPos = p->lzPos; in MixMatches2()
627 static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) in MixMatches3() argument
630 UInt32 *hash = p->hash; in MixMatches3()
631 const Byte *cur = p->pointerToCurPos; in MixMatches3()
632 UInt32 lzPos = p->lzPos; in MixMatches3()
717 #define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
719 static UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances) in MatchFinderMt2_GetMatches() argument
721 const UInt32 *btBuf = p->btBuf + p->btBufPos; in MatchFinderMt2_GetMatches()
723 p->btBufPos += 1 + len; in MatchFinderMt2_GetMatches()
724 p->btNumAvailBytes--; in MatchFinderMt2_GetMatches()
741 static UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances) in MatchFinderMt_GetMatches() argument
743 const UInt32 *btBuf = p->btBuf + p->btBufPos; in MatchFinderMt_GetMatches()
745 p->btBufPos += 1 + len; in MatchFinderMt_GetMatches()
750 if (p->btNumAvailBytes-- >= 4) in MatchFinderMt_GetMatches()
751 len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances)); in MatchFinderMt_GetMatches()
757 p->btNumAvailBytes--; in MatchFinderMt_GetMatches()
758 distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances); in MatchFinderMt_GetMatches()
776 …_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCur…
777 #define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num !…
779 static void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num) argument
781 SKIP_HEADER2_MT { p->btNumAvailBytes--;
785 static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
790 hash[h2] = p->lzPos;
794 static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
801 p->lzPos;
819 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
826 switch (p->MatchFinder->numHashBytes)
829 p->GetHeadsFunc = GetHeads2;
830 p->MixMatchesFunc = (Mf_Mix_Matches)NULL;
835 p->GetHeadsFunc = GetHeads3;
836 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
841 p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
842 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;