diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-01-23 17:29:56 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-01-23 17:29:56 +0300 |
commit | 1bb6ba0605d56f5fcb3a190a350659dd2e4ae600 (patch) | |
tree | ae3501ddf90ed89e8e0b5eae7aff856b8e71888f /source/blender/blenlib/intern/threads.c | |
parent | 10b1b6130628b6c7a854f8ae8d872ba4a7bc5e4b (diff) |
Thread queue: use _ftime to get current time on windows, same as
pthreads-win32 test suite.
Diffstat (limited to 'source/blender/blenlib/intern/threads.c')
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 610984f2d9c..a81d5ed64e4 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -47,6 +47,7 @@ /* for checking system threads - BLI_system_thread_count */ #ifdef WIN32 #include "windows.h" +#include <sys/timeb.h> #elif defined(__APPLE__) #include <sys/types.h> #include <sys/sysctl.h> @@ -524,32 +525,30 @@ void *BLI_thread_queue_pop(ThreadQueue *queue) static void wait_timeout(struct timespec *timeout, int ms) { -#ifndef WIN32 - struct timeval now; ldiv_t div_result; - long x; + long sec, usec, x; - gettimeofday(&now, NULL); - div_result = ldiv(ms, 1000); - timeout->tv_sec = now.tv_sec + div_result.quot; - x = now.tv_usec + (div_result.rem*1000); - - if (x >= 1000000) { - timeout->tv_sec++; - x -= 1000000; +#ifdef WIN32 + { + struct _timeb now; + _ftime(&now); + sec = now.time; + usec = now.millitm*1000; /* microsecond precision would be better */ } - - timeout->tv_nsec = x*1000; #else - /*XXX test me*/ - time_t now; - ldiv_t div_result; - long x; + { + struct timeval now; + gettimeofday(&now, NULL); + sec = now.tv_sec; + usec = now.tv_usec; + } +#endif - time(&now); + /* add current time + millisecond offset */ div_result = ldiv(ms, 1000); - timeout->tv_sec = now + div_result.quot; - x = (now*1000) + (div_result.rem*1000); + timeout->tv_sec = sec + div_result.quot; + + x = usec + (div_result.rem*1000); if (x >= 1000000) { timeout->tv_sec++; @@ -557,7 +556,6 @@ static void wait_timeout(struct timespec *timeout, int ms) } timeout->tv_nsec = x*1000; -#endif } void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) |