]> git.sesse.net Git - stockfish/commitdiff
Use new Time class in timed_wait()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 3 Mar 2012 17:53:37 +0000 (18:53 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 5 Mar 2012 18:18:46 +0000 (19:18 +0100)
And simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/misc.cpp
src/misc.h
src/types.h

index 99deedcc6a66f5e8d99086fa2baa2c4ccf59a2a9..8cfba7341fa7fe7256fdaafa440dc3140ae9dbcd 100644 (file)
@@ -138,19 +138,11 @@ void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
 #if defined(_WIN32) || defined(_WIN64)
   int tm = msec;
 #else
-  struct timeval t;
-  struct timespec abstime, *tm = &abstime;
+  timespec ts, *tm = &ts;
+  uint64_t ms = Time::current_time().msec() + msec;
 
-  gettimeofday(&t, NULL);
-
-  abstime.tv_sec = t.tv_sec + (msec / 1000);
-  abstime.tv_nsec = (t.tv_usec + (msec % 1000) * 1000) * 1000;
-
-  if (abstime.tv_nsec > 1000000000LL)
-  {
-      abstime.tv_sec += 1;
-      abstime.tv_nsec -= 1000000000LL;
-  }
+  ts.tv_sec = ms / 1000;
+  ts.tv_nsec = (ms % 1000) * 1000000LL;
 #endif
 
   cond_timedwait(sleepCond, sleepLock, tm);
index cda0ef591192c9852e422447a3a3f57ef91bb1c6..7c33211e884616de3b2cee5648a4b637c89f0540 100644 (file)
@@ -57,7 +57,7 @@ public:
   static Time current_time() { Time t; t.restart(); return t; }
 
 private:
-  my_time_t t;
+  sys_time_t t;
 };
 
 #endif // !defined(MISC_H_INCLUDED)
index d907006ca4afb19fe7af338f48b5f24b1152881e..25eef007e74e0176249ae134dadee87d38ab7911 100644 (file)
@@ -62,16 +62,16 @@ typedef unsigned __int64 uint64_t;
 
 #if defined(_WIN32) || defined(_WIN64)
 #  include <sys/timeb.h>
-typedef _timeb my_time_t;
+typedef _timeb sys_time_t;
 
-inline void system_time(my_time_t* t) { _ftime(t); }
-inline uint64_t time_to_msec(const my_time_t& t) { return t.time * 1000 + t.millitm; }
+inline void system_time(sys_time_t* t) { _ftime(t); }
+inline uint64_t time_to_msec(const sys_time_t& t) { return t.time * 1000 + t.millitm; }
 #else
 #  include <sys/time.h>
-typedef timeval my_time_t;
+typedef timeval sys_time_t;
 
-inline void system_time(my_time_t* t) { gettimeofday(t, NULL); }
-inline uint64_t time_to_msec(const my_time_t& t) { return t.tv_sec * 1000 + t.tv_usec / 1000; }
+inline void system_time(sys_time_t* t) { gettimeofday(t, NULL); }
+inline uint64_t time_to_msec(const sys_time_t& t) { return t.tv_sec * 1000 + t.tv_usec / 1000; }
 #endif
 
 #if defined(_WIN64)