[openrtm-commit:01044] r2383 - trunk/OpenRTM-aist/src/lib/coil/posix/coil

openrtm @ openrtm.org openrtm @ openrtm.org
2013年 4月 15日 (月) 20:03:09 JST


Author: n-ando
Date: 2013-04-15 20:03:09 +0900 (Mon, 15 Apr 2013)
New Revision: 2383

Modified:
   trunk/OpenRTM-aist/src/lib/coil/posix/coil/Condition.h
Log:
[compat] Condition::wait() wait time calculation became more precise. refs #2637

Modified: trunk/OpenRTM-aist/src/lib/coil/posix/coil/Condition.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/posix/coil/Condition.h	2013-04-15 10:50:06 UTC (rev 2382)
+++ trunk/OpenRTM-aist/src/lib/coil/posix/coil/Condition.h	2013-04-15 11:03:09 UTC (rev 2383)
@@ -177,9 +177,16 @@
      */
     bool wait(long second, long nano_second = 0)
     {
+      struct timeval tv;
       timespec abstime;
-      abstime.tv_sec = std::time(0) + second;
-      abstime.tv_nsec = nano_second;
+
+      ::gettimeofday(&tv, NULL);
+      abstime.tv_sec  = tv.tv_sec + second;
+      abstime.tv_nsec = tv.tv_usec * 1000 + nano_second;
+      if (abstime.tv_nsec >= 1000000000) {
+        abstime.tv_nsec -= 1000000000;
+        abstime.tv_sec ++;
+      }
       return 0 == ::pthread_cond_timedwait(&m_cond, &m_mutex.mutex_, &abstime);
     }
 



More information about the openrtm-commit mailing list