Fixed broken timed wait for thread and mutex objects in WaitForSingleObject.
This commit is contained in:
parent
72770c8c43
commit
719c1a27d6
@ -89,7 +89,7 @@ int clock_gettime(int clk_id, struct timespec *t)
|
||||
static int pthread_timedjoin_np(pthread_t td, void **res,
|
||||
struct timespec *timeout)
|
||||
{
|
||||
struct timeval timenow;
|
||||
struct timespec timenow;
|
||||
struct timespec sleepytime;
|
||||
/* This is just to avoid a completely busy wait */
|
||||
sleepytime.tv_sec = 0;
|
||||
@ -102,10 +102,10 @@ static int pthread_timedjoin_np(pthread_t td, void **res,
|
||||
|
||||
nanosleep(&sleepytime, NULL);
|
||||
|
||||
gettimeofday(&timenow, NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &timenow);
|
||||
|
||||
if (timenow.tv_sec >= timeout->tv_sec &&
|
||||
(timenow.tv_usec * 1000) >= timeout->tv_nsec)
|
||||
(timenow.tv_nsec) >= timeout->tv_nsec)
|
||||
{
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
@ -117,7 +117,7 @@ static int pthread_timedjoin_np(pthread_t td, void **res,
|
||||
|
||||
static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout)
|
||||
{
|
||||
struct timeval timenow;
|
||||
struct timespec timenow;
|
||||
struct timespec sleepytime;
|
||||
int retcode;
|
||||
|
||||
@ -127,10 +127,10 @@ static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec
|
||||
|
||||
while ((retcode = pthread_mutex_trylock (mutex)) == EBUSY)
|
||||
{
|
||||
gettimeofday (&timenow, NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &timenow);
|
||||
|
||||
if (timenow.tv_sec >= timeout->tv_sec &&
|
||||
(timenow.tv_usec * 1000) >= timeout->tv_nsec)
|
||||
(timenow.tv_nsec) >= timeout->tv_nsec)
|
||||
{
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
@ -172,7 +172,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
|
||||
if (thread->started)
|
||||
{
|
||||
#ifdef __linux__
|
||||
if (dwMilliseconds != INFINITE)
|
||||
{
|
||||
struct timespec timeout;
|
||||
@ -191,7 +190,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
status = pthread_join(thread->thread, &thread_status);
|
||||
|
||||
if (status != 0)
|
||||
@ -223,7 +221,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
|
||||
mutex = (WINPR_MUTEX*) Object;
|
||||
|
||||
#ifdef __linux__
|
||||
if (dwMilliseconds != INFINITE)
|
||||
{
|
||||
int status;
|
||||
@ -238,7 +235,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
pthread_mutex_lock(&mutex->mutex);
|
||||
}
|
||||
else if (Type == HANDLE_TYPE_EVENT)
|
||||
|
Loading…
Reference in New Issue
Block a user