Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timedwait fix #379

Merged
merged 4 commits into from
May 11, 2018
Merged

Timedwait fix #379

merged 4 commits into from
May 11, 2018

Conversation

Gummilion
Copy link
Contributor

Fixed regression after #291
Created CTimer::condTimedWaitUS - wrapper for pthread_cond_timedwait using relative time to avoid dependency on getTime() value.

This was referenced May 11, 2018
@rndi rndi self-requested a review May 11, 2018 17:37
Copy link
Collaborator

@rndi rndi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested for several hours. Looks good!

@rndi rndi merged commit cce679c into Haivision:master May 11, 2018
@rndi
Copy link
Collaborator

rndi commented May 11, 2018

Thank you @Gummilion !

while (stillConnected() && !m_pRcvBuffer->isRcvDataReady())
{
pthread_cond_timedwait(&m_RecvDataCond, &m_RecvLock, &locktime);
CTimer::condTimedWaitUS(&m_RecvDataCond, &m_RecvLock, m_iRcvTimeOut * 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me, no one has noticed this?

The old code precalculates the latest time up to which it should wait, using CTimer::getTime once. Then in a loop there's waiting up to this time at most.

The new code makes waiting for m_iRcvTimeOut*1000 basing on CTimer::getTime called again every time in a loop, which makes it wait for exactly that amount of time, regardless of how much time was already spent in previous iterations.

It is not the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, with condTimedWaitUS() we need to calculate how much time is left to sleep instead of sleeping fixed amount of time. I'm apologize for this fault. Should I wash away my sin, or you'll kindly fix it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your fault, and also there's more around this. We'll take care of it.


while (stillConnected()
&& sndBuffersLeft() < minlen
&& m_bPeerHealth
&& exptime > CTimer::getTime())
pthread_cond_timedwait(&m_SendBlockCond, &m_SendBlockLock, &locktime);
CTimer::condTimedWaitUS(&m_SendBlockCond, &m_SendBlockLock, m_iSndTimeOut * 1000ULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants