[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26211] trunk/blender/source/blender/ blenlib/intern/threads.c: Thread queue: use _ftime to get current time on windows, same as

Brecht Van Lommel brecht at blender.org
Sat Jan 23 15:29:56 CET 2010


Revision: 26211
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26211
Author:   blendix
Date:     2010-01-23 15:29:56 +0100 (Sat, 23 Jan 2010)

Log Message:
-----------
Thread queue: use _ftime to get current time on windows, same as
pthreads-win32 test suite.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/threads.c

Modified: trunk/blender/source/blender/blenlib/intern/threads.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/threads.c	2010-01-23 13:57:54 UTC (rev 26210)
+++ trunk/blender/source/blender/blenlib/intern/threads.c	2010-01-23 14:29:56 UTC (rev 26211)
@@ -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,40 +525,37 @@
 
 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++;
 		x -= 1000000;
 	}
 
 	timeout->tv_nsec = x*1000;
-#endif
 }
 
 void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms)





More information about the Bf-blender-cvs mailing list