Skip to content

Commit

Permalink
[core] Fixed CUnitQueue::getNextAvailUnit(..)
Browse files Browse the repository at this point in the history
Refers to issue Haivision#486 getting available uit to receive a packet
  • Loading branch information
maxsharabayko committed Jun 9, 2020
1 parent 7841768 commit 57d8352
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,28 @@ CUnit *CUnitQueue::getNextAvailUnit()
if (m_iCount >= m_iSize)
return NULL;

CQEntry *entrance = m_pCurrQueue;

int units_checked = 0;
do
{
for (CUnit *sentinel = m_pCurrQueue->m_pUnit + m_pCurrQueue->m_iSize - 1; m_pAvailUnit != sentinel;
++m_pAvailUnit)
CUnit *lastunit = m_pCurrQueue->m_pUnit + m_pCurrQueue->m_iSize - 1;
for (; m_pAvailUnit != lastunit; ++m_pAvailUnit, ++units_checked)
{
if (m_pAvailUnit->m_iFlag == CUnit::FREE)
{
return m_pAvailUnit;
}
}

if (m_pCurrQueue->m_pUnit->m_iFlag == CUnit::FREE)
if (lastunit->m_iFlag == CUnit::FREE)
{
m_pAvailUnit = m_pCurrQueue->m_pUnit;
m_pAvailUnit = lastunit;
return m_pAvailUnit;
}

++units_checked;
m_pCurrQueue = m_pCurrQueue->m_pNext;
m_pAvailUnit = m_pCurrQueue->m_pUnit;
} while (m_pCurrQueue != entrance);
} while (units_checked < m_iSize);

increase();

Expand Down

0 comments on commit 57d8352

Please sign in to comment.