fixed SF# 2841812: Posix ThreadImpl::sleepImpl throws exceptions on EINTR

This commit is contained in:
Guenter Obiltschnig 2009-08-25 06:49:47 +00:00
parent 4bdeaa7baf
commit 9464ca7b24
2 changed files with 34 additions and 17 deletions

View File

@ -180,23 +180,6 @@ inline int ThreadImpl::getOSPriorityImpl() const
}
inline void ThreadImpl::sleepImpl(long milliseconds)
{
#if defined(__VMS) || defined(__digital__)
// This is specific to DECThreads
struct timespec interval;
interval.tv_sec = milliseconds / 1000;
interval.tv_nsec = (milliseconds % 1000)*1000000;
pthread_delay_np(&interval);
#else
struct timeval tv;
tv.tv_sec = milliseconds / 1000;
tv.tv_usec = (milliseconds % 1000) * 1000;
select(0, NULL, NULL, NULL, &tv);
#endif
}
inline bool ThreadImpl::isRunningImpl() const
{
return _pData->pRunnableTarget != 0 ||

View File

@ -263,6 +263,40 @@ ThreadImpl* ThreadImpl::currentImpl()
}
void ThreadImpl::sleepImpl(long milliseconds)
{
#if defined(__VMS) || defined(__digital__)
// This is specific to DECThreads
struct timespec interval;
interval.tv_sec = milliseconds / 1000;
interval.tv_nsec = (milliseconds % 1000)*1000000;
pthread_delay_np(&interval);
#else
Poco::Timespan remainingTime(1000*Poco::Timespan::TimeDiff(milliseconds));
int rc;
do
{
struct timeval tv;
tv.tv_sec = (long) remainingTime.totalSeconds();
tv.tv_usec = (long) remainingTime.useconds();
Poco::Timestamp start;
rc = ::select(0, NULL, NULL, NULL, &tv);
if (rc < 0 && errno == EINTR)
{
Poco::Timestamp end;
Poco::Timespan waited = start.elapsed();
if (waited < remainingTime)
remainingTime -= waited;
else
remainingTime = 0;
}
}
while (remainingTime > 0 && rc < 0 && errno == EINTR);
if (rc < 0 && remainingTime > 0) throw Poco::SystemException("Thread::sleep(): select() failed");
#endif
}
void* ThreadImpl::runnableEntry(void* pThread)
{
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));