fix up SemaImpl_Pthreads::Wait
This commit is contained in:
@@ -292,34 +292,22 @@ bool SemaImpl_Pthreads::Wait()
|
|||||||
pthread_mutex_lock( &m_Mutex );
|
pthread_mutex_lock( &m_Mutex );
|
||||||
|
|
||||||
int tries = 2;
|
int tries = 2;
|
||||||
while( tries-- )
|
while( !m_iValue && tries )
|
||||||
{
|
{
|
||||||
int ret = pthread_cond_timedwait( &m_Cond, &m_Mutex, &ts );
|
int ret = pthread_cond_timedwait( &m_Cond, &m_Mutex, &ts );
|
||||||
|
|
||||||
switch( ret )
|
switch( ret )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if( !m_iValue )
|
|
||||||
{
|
|
||||||
++tries;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
--m_iValue;
|
|
||||||
pthread_mutex_unlock( &m_Mutex );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case EINTR:
|
case EINTR:
|
||||||
/* Ignore it. */
|
break;
|
||||||
++tries;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case ETIMEDOUT:
|
case ETIMEDOUT:
|
||||||
/* Timed out. Probably deadlocked. Try again one more time, with a smaller
|
/* Timed out. Probably deadlocked. Try again one more time, with a smaller
|
||||||
* timeout, just in case we're debugging and happened to stop while waiting
|
* timeout, just in case we're debugging and happened to stop while waiting
|
||||||
* on the mutex. */
|
* on the mutex. */
|
||||||
++ts.tv_sec;
|
++ts.tv_sec;
|
||||||
|
tries--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -327,8 +315,18 @@ bool SemaImpl_Pthreads::Wait()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock( &m_Mutex );
|
if( !m_iValue )
|
||||||
return false;
|
{
|
||||||
|
/* Timed out. */
|
||||||
|
pthread_mutex_unlock( &m_Mutex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
--m_iValue;
|
||||||
|
pthread_mutex_unlock( &m_Mutex );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user