diff options
author | msvensson@shellback. <> | 2006-12-14 15:23:44 +0100 |
---|---|---|
committer | msvensson@shellback. <> | 2006-12-14 15:23:44 +0100 |
commit | c41e307d85ba9399eb219fa5718ba8ab5af847c3 (patch) | |
tree | f23da2855e569b61111327134ef1ba91ff7ff353 /mysys/my_wincond.c | |
parent | fdbc84d27c9b21f1ab57393a2b4ba57cbd26373c (diff) | |
download | mariadb-git-c41e307d85ba9399eb219fa5718ba8ab5af847c3.tar.gz |
BUG#24687 func_misc test fails on win64
- Use same precision (milliseconds) for all time functions
used when calculating time for pthread_cond_timedwait
- Use 'GetSystemTimeAsFileTime' for both start and curr time
Diffstat (limited to 'mysys/my_wincond.c')
-rw-r--r-- | mysys/my_wincond.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/mysys/my_wincond.c b/mysys/my_wincond.c index 8c497e8f250..327addff2cc 100644 --- a/mysys/my_wincond.c +++ b/mysys/my_wincond.c @@ -54,14 +54,30 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime) { - struct _timeb curtime; int result; - long timeout; - _ftime(&curtime); - timeout= ((long) (abstime->tv_sec - curtime.time)*1000L + - (long)((abstime->tv_nsec/1000) - curtime.millitm)/1000L); - if (timeout < 0) /* Some safety */ + long timeout; + union ft64 now; + + GetSystemTimeAsFileTime(&now.ft); + + /* + - subtract start time from current time(values are in 100ns units + - convert to millisec by dividing with 10000 + - subtract time since start from max timeout + */ + timeout= abstime->timeout_msec - (long)((now.i64 - abstime->start.i64) / 10000); + + /* Don't allow the timeout to be negative */ + if (timeout < 0) timeout = 0L; + + /* + Make sure the calucated time does not exceed original timeout + value which could cause "wait for ever" if system time changes + */ + if (timeout > abstime->timeout_msec) + timeout= abstime->timeout_msec; + InterlockedIncrement(&cond->waiting); LeaveCriticalSection(mutex); result=WaitForSingleObject(cond->semaphore,timeout); |