-
Notifications
You must be signed in to change notification settings - Fork 861
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
Timedwait fix #379
Conversation
There was a problem hiding this 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!
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar problem here.
Fixed regression after #291
Created
CTimer::condTimedWaitUS
- wrapper for pthread_cond_timedwait using relative time to avoid dependency on getTime() value.