Lines Matching refs:p
10 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 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()
39 CriticalSection_Leave(&p->cs); in MtSync_GetNextBlock()
40 p->csWasEntered = False; in MtSync_GetNextBlock()
41 p->numProcessedBlocks++; in MtSync_GetNextBlock()
42 Semaphore_Release1(&p->freeSemaphore); in MtSync_GetNextBlock()
44 Semaphore_Wait(&p->filledSemaphore); in MtSync_GetNextBlock()
45 CriticalSection_Enter(&p->cs); in MtSync_GetNextBlock()
46 p->csWasEntered = True; in MtSync_GetNextBlock()
51 void MtSync_StopWriting(CMtSync *p) in MtSync_StopWriting() argument
53 UInt32 myNumBlocks = p->numProcessedBlocks; in MtSync_StopWriting()
54 if (!Thread_WasCreated(&p->thread) || p->needStart) in MtSync_StopWriting()
56 p->stopWriting = True; in MtSync_StopWriting()
57 if (p->csWasEntered) in MtSync_StopWriting()
59 CriticalSection_Leave(&p->cs); in MtSync_StopWriting()
60 p->csWasEntered = False; in MtSync_StopWriting()
62 Semaphore_Release1(&p->freeSemaphore); in MtSync_StopWriting()
64 Event_Wait(&p->wasStopped); in MtSync_StopWriting()
66 while (myNumBlocks++ != p->numProcessedBlocks) in MtSync_StopWriting()
68 Semaphore_Wait(&p->filledSemaphore); in MtSync_StopWriting()
69 Semaphore_Release1(&p->freeSemaphore); in MtSync_StopWriting()
71 p->needStart = True; in MtSync_StopWriting()
74 void MtSync_Destruct(CMtSync *p) in MtSync_Destruct() argument
76 if (Thread_WasCreated(&p->thread)) in MtSync_Destruct()
78 MtSync_StopWriting(p); in MtSync_Destruct()
79 p->exit = True; in MtSync_Destruct()
80 if (p->needStart) in MtSync_Destruct()
81 Event_Set(&p->canStart); in MtSync_Destruct()
82 Thread_Wait(&p->thread); in MtSync_Destruct()
83 Thread_Close(&p->thread); in MtSync_Destruct()
85 if (p->csWasInitialized) in MtSync_Destruct()
87 CriticalSection_Delete(&p->cs); in MtSync_Destruct()
88 p->csWasInitialized = False; in MtSync_Destruct()
91 Event_Close(&p->canStart); in MtSync_Destruct()
92 Event_Close(&p->wasStarted); in MtSync_Destruct()
93 Event_Close(&p->wasStopped); in MtSync_Destruct()
94 Semaphore_Close(&p->freeSemaphore); in MtSync_Destruct()
95 Semaphore_Close(&p->filledSemaphore); in MtSync_Destruct()
97 p->wasCreated = False; in MtSync_Destruct()
102 static SRes MtSync_Create2(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks) in MtSync_Create2() argument
104 if (p->wasCreated) in MtSync_Create2()
107 RINOK_THREAD(CriticalSection_Init(&p->cs)); in MtSync_Create2()
108 p->csWasInitialized = True; in MtSync_Create2()
110 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); in MtSync_Create2()
111 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); in MtSync_Create2()
112 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); in MtSync_Create2()
114 RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); in MtSync_Create2()
115 RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); in MtSync_Create2()
117 p->needStart = True; in MtSync_Create2()
119 RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); in MtSync_Create2()
120 p->wasCreated = True; in MtSync_Create2()
124 static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks) in MtSync_Create() argument
126 SRes res = MtSync_Create2(p, startAddress, obj, numBlocks); in MtSync_Create()
128 MtSync_Destruct(p); in MtSync_Create()
132 void MtSync_Init(CMtSync *p) { p->needStart = True; } in MtSync_Init() argument
137 static void GetHeads ## name(const Byte *p, UInt32 pos, \
140 const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
144 DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
145 DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
146 DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
147 DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
152 CMtSync *p = &mt->hashSync; in HashThreadFunc() local
156 Event_Wait(&p->canStart); in HashThreadFunc()
157 Event_Set(&p->wasStarted); in HashThreadFunc()
160 if (p->exit) in HashThreadFunc()
162 if (p->stopWriting) in HashThreadFunc()
164 p->numProcessedBlocks = numProcessedBlocks; in HashThreadFunc()
165 Event_Set(&p->wasStopped); in HashThreadFunc()
188 Semaphore_Wait(&p->freeSemaphore); in HashThreadFunc()
215 Semaphore_Release1(&p->filledSemaphore); in HashThreadFunc()
220 void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p) in MatchFinderMt_GetNextBlock_Hash() argument
222 MtSync_GetNextBlock(&p->hashSync); in MatchFinderMt_GetNextBlock_Hash()
223 …p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask)… in MatchFinderMt_GetNextBlock_Hash()
224 p->hashBufPosLimit += p->hashBuf[p->hashBufPos++]; in MatchFinderMt_GetNextBlock_Hash()
225 p->hashNumAvail = p->hashBuf[p->hashBufPos++]; in MatchFinderMt_GetNextBlock_Hash()
313 void BtGetMatches(CMatchFinderMt *p, UInt32 *distances) in BtGetMatches() argument
317 UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); in BtGetMatches()
318 distances[1] = p->hashNumAvail; in BtGetMatches()
321 if (p->hashBufPos == p->hashBufPosLimit) in BtGetMatches()
323 MatchFinderMt_GetNextBlock_Hash(p); in BtGetMatches()
324 distances[1] = numProcessed + p->hashNumAvail; in BtGetMatches()
325 if (p->hashNumAvail >= p->numHashBytes) in BtGetMatches()
327 for (; p->hashNumAvail != 0; p->hashNumAvail--) in BtGetMatches()
332 UInt32 size = p->hashBufPosLimit - p->hashBufPos; in BtGetMatches()
333 UInt32 lenLimit = p->matchMaxLen; in BtGetMatches()
334 UInt32 pos = p->pos; in BtGetMatches()
335 UInt32 cyclicBufferPos = p->cyclicBufferPos; in BtGetMatches()
336 if (lenLimit >= p->hashNumAvail) in BtGetMatches()
337 lenLimit = p->hashNumAvail; in BtGetMatches()
339 UInt32 size2 = p->hashNumAvail - lenLimit + 1; in BtGetMatches()
342 size2 = p->cyclicBufferSize - cyclicBufferPos; in BtGetMatches()
350 UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], in BtGetMatches()
351 pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, in BtGetMatches()
352 startDistances + 1, p->numHashBytes - 1) - startDistances); in BtGetMatches()
357 p->buffer++; in BtGetMatches()
362 …urPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBuffer… in BtGetMatches()
363 …distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , siz… in BtGetMatches()
364 p->hashBufPos += posRes - pos; in BtGetMatches()
366 p->buffer += posRes - pos; in BtGetMatches()
371 numProcessed += pos - p->pos; in BtGetMatches()
372 p->hashNumAvail -= pos - p->pos; in BtGetMatches()
373 p->pos = pos; in BtGetMatches()
374 if (cyclicBufferPos == p->cyclicBufferSize) in BtGetMatches()
376 p->cyclicBufferPos = cyclicBufferPos; in BtGetMatches()
382 void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex) in BtFillBlock() argument
384 CMtSync *sync = &p->hashSync; in BtFillBlock()
391 BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); in BtFillBlock()
393 if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize) in BtFillBlock()
395 UInt32 subValue = p->pos - p->cyclicBufferSize; in BtFillBlock()
396 MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2); in BtFillBlock()
397 p->pos -= subValue; in BtFillBlock()
409 CMtSync *p = &mt->btSync; in BtThreadFunc() local
413 Event_Wait(&p->canStart); in BtThreadFunc()
414 Event_Set(&p->wasStarted); in BtThreadFunc()
417 if (p->exit) in BtThreadFunc()
419 if (p->stopWriting) in BtThreadFunc()
421 p->numProcessedBlocks = blockIndex; in BtThreadFunc()
423 Event_Set(&p->wasStopped); in BtThreadFunc()
426 Semaphore_Wait(&p->freeSemaphore); in BtThreadFunc()
428 Semaphore_Release1(&p->filledSemaphore); in BtThreadFunc()
433 void MatchFinderMt_Construct(CMatchFinderMt *p) in MatchFinderMt_Construct() argument
435 p->hashBuf = 0; in MatchFinderMt_Construct()
436 MtSync_Construct(&p->hashSync); in MatchFinderMt_Construct()
437 MtSync_Construct(&p->btSync); in MatchFinderMt_Construct()
440 void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc) in MatchFinderMt_FreeMem() argument
442 alloc->Free(alloc, p->hashBuf); in MatchFinderMt_FreeMem()
443 p->hashBuf = 0; in MatchFinderMt_FreeMem()
446 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc) in MatchFinderMt_Destruct() argument
448 MtSync_Destruct(&p->hashSync); in MatchFinderMt_Destruct()
449 MtSync_Destruct(&p->btSync); in MatchFinderMt_Destruct()
450 MatchFinderMt_FreeMem(p, alloc); in MatchFinderMt_Destruct()
456 …UNC_RET_TYPE THREAD_FUNC_CALL_TYPE HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);… in HashThreadFunc2() argument
457 static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p) in BtThreadFunc2() argument
462 BtThreadFunc((CMatchFinderMt *)p); in BtThreadFunc2()
466 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, in MatchFinderMt_Create() argument
469 CMatchFinder *mf = p->MatchFinder; in MatchFinderMt_Create()
470 p->historySize = historySize; in MatchFinderMt_Create()
473 if (p->hashBuf == 0) in MatchFinderMt_Create()
475 p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32)); in MatchFinderMt_Create()
476 if (p->hashBuf == 0) in MatchFinderMt_Create()
478 p->btBuf = p->hashBuf + kHashBufferSize; in MatchFinderMt_Create()
485 RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks)); in MatchFinderMt_Create()
486 RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks)); in MatchFinderMt_Create()
491 void MatchFinderMt_Init(CMatchFinderMt *p) in MatchFinderMt_Init() argument
493 CMatchFinder *mf = p->MatchFinder; in MatchFinderMt_Init()
494 p->btBufPos = p->btBufPosLimit = 0; in MatchFinderMt_Init()
495 p->hashBufPos = p->hashBufPosLimit = 0; in MatchFinderMt_Init()
497 p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf); in MatchFinderMt_Init()
498 p->btNumAvailBytes = 0; in MatchFinderMt_Init()
499 p->lzPos = p->historySize + 1; in MatchFinderMt_Init()
501 p->hash = mf->hash; in MatchFinderMt_Init()
502 p->fixedHashSize = mf->fixedHashSize; in MatchFinderMt_Init()
503 p->crc = mf->crc; in MatchFinderMt_Init()
505 p->son = mf->son; in MatchFinderMt_Init()
506 p->matchMaxLen = mf->matchMaxLen; in MatchFinderMt_Init()
507 p->numHashBytes = mf->numHashBytes; in MatchFinderMt_Init()
508 p->pos = mf->pos; in MatchFinderMt_Init()
509 p->buffer = mf->buffer; in MatchFinderMt_Init()
510 p->cyclicBufferPos = mf->cyclicBufferPos; in MatchFinderMt_Init()
511 p->cyclicBufferSize = mf->cyclicBufferSize; in MatchFinderMt_Init()
512 p->cutValue = mf->cutValue; in MatchFinderMt_Init()
516 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p) in MatchFinderMt_ReleaseStream() argument
518 MtSync_StopWriting(&p->btSync); in MatchFinderMt_ReleaseStream()
522 void MatchFinderMt_Normalize(CMatchFinderMt *p) in MatchFinderMt_Normalize() argument
524 MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize); in MatchFinderMt_Normalize()
525 p->lzPos = p->historySize + 1; in MatchFinderMt_Normalize()
528 void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p) in MatchFinderMt_GetNextBlock_Bt() argument
531 MtSync_GetNextBlock(&p->btSync); in MatchFinderMt_GetNextBlock_Bt()
532 blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask); in MatchFinderMt_GetNextBlock_Bt()
533 p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize; in MatchFinderMt_GetNextBlock_Bt()
534 p->btBufPosLimit += p->btBuf[p->btBufPos++]; in MatchFinderMt_GetNextBlock_Bt()
535 p->btNumAvailBytes = p->btBuf[p->btBufPos++]; in MatchFinderMt_GetNextBlock_Bt()
536 if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) in MatchFinderMt_GetNextBlock_Bt()
537 MatchFinderMt_Normalize(p); in MatchFinderMt_GetNextBlock_Bt()
540 const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p) in MatchFinderMt_GetPointerToCurrentPos() argument
542 return p->pointerToCurPos; in MatchFinderMt_GetPointerToCurrentPos()
545 #define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_…
547 UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p) in MatchFinderMt_GetNumAvailableBytes() argument
550 return p->btNumAvailBytes; in MatchFinderMt_GetNumAvailableBytes()
553 Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index) in MatchFinderMt_GetIndexByte() argument
555 return p->pointerToCurPos[index]; in MatchFinderMt_GetIndexByte()
558 UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) in MixMatches2() argument
561 UInt32 *hash = p->hash; in MixMatches2()
562 const Byte *cur = p->pointerToCurPos; in MixMatches2()
563 UInt32 lzPos = p->lzPos; in MixMatches2()
578 UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) in MixMatches3() argument
581 UInt32 *hash = p->hash; in MixMatches3()
582 const Byte *cur = p->pointerToCurPos; in MixMatches3()
583 UInt32 lzPos = p->lzPos; in MixMatches3()
666 #define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
668 UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances) in MatchFinderMt2_GetMatches() argument
670 const UInt32 *btBuf = p->btBuf + p->btBufPos; in MatchFinderMt2_GetMatches()
672 p->btBufPos += 1 + len; in MatchFinderMt2_GetMatches()
673 p->btNumAvailBytes--; in MatchFinderMt2_GetMatches()
686 UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances) in MatchFinderMt_GetMatches() argument
688 const UInt32 *btBuf = p->btBuf + p->btBufPos; in MatchFinderMt_GetMatches()
690 p->btBufPos += 1 + len; in MatchFinderMt_GetMatches()
694 if (p->btNumAvailBytes-- >= 4) in MatchFinderMt_GetMatches()
695 len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances)); in MatchFinderMt_GetMatches()
701 p->btNumAvailBytes--; in MatchFinderMt_GetMatches()
702 distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances); in MatchFinderMt_GetMatches()
716 …_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCur…
717 #define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num !…
719 void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num) argument
721 SKIP_HEADER2_MT { p->btNumAvailBytes--;
725 void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
730 hash[hash2Value] = p->lzPos;
734 void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
741 p->lzPos;
759 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
766 switch(p->MatchFinder->numHashBytes)
769 p->GetHeadsFunc = GetHeads2;
770 p->MixMatchesFunc = (Mf_Mix_Matches)0;
775 p->GetHeadsFunc = GetHeads3;
776 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
781 p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
783 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;