fixes return values of wxSemaphore::TryWait() and WaitTimeout() to behave as documented

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20155 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-04-12 00:43:28 +00:00
parent a5e3c24d7b
commit 918dc51991
2 changed files with 22 additions and 4 deletions

View File

@@ -267,7 +267,16 @@ public:
bool IsOk() const { return m_semaphore != NULL; } bool IsOk() const { return m_semaphore != NULL; }
wxSemaError Wait() { return WaitTimeout(INFINITE); } wxSemaError Wait() { return WaitTimeout(INFINITE); }
wxSemaError TryWait() { return WaitTimeout(0); }
wxSemaError TryWait()
{
wxSemaError rc = WaitTimeout(0);
if ( rc == wxSEMA_TIMEOUT )
rc = wxSEMA_BUSY;
return rc;
}
wxSemaError WaitTimeout(unsigned long milliseconds); wxSemaError WaitTimeout(unsigned long milliseconds);
wxSemaError Post(); wxSemaError Post();
@@ -321,7 +330,7 @@ wxSemaError wxSemaphoreInternal::WaitTimeout(unsigned long milliseconds)
return wxSEMA_NO_ERROR; return wxSEMA_NO_ERROR;
case WAIT_TIMEOUT: case WAIT_TIMEOUT:
return wxSEMA_BUSY; return wxSEMA_TIMEOUT;
default: default:
wxLogLastError(_T("WaitForSingleObject(semaphore)")); wxLogLastError(_T("WaitForSingleObject(semaphore)"));

View File

@@ -532,8 +532,17 @@ wxSemaError wxSemaphoreInternal::WaitTimeout(unsigned long milliseconds)
return wxSEMA_TIMEOUT; return wxSEMA_TIMEOUT;
} }
if ( m_cond.WaitTimeout(remainingTime) != wxCOND_NO_ERROR ) switch ( m_cond.WaitTimeout(remainingTime) )
return wxSEMA_MISC_ERROR; {
case wxCOND_TIMEOUT:
return wxSEMA_TIMEOUT;
default:
return wxSEMA_MISC_ERROR;
case wxCOND_NO_ERROR:
;
}
} }
m_count--; m_count--;