Project

General

Profile

バグ #2609

coil condition timeout の不具合修正

Added by n-ando almost 8 years ago. Updated almost 8 years ago.

Status:
終了
Priority:
通常
Assignee:
Target version:
-
Start date:
03/18/2013
Due date:
% Done:

100%

Estimated time:

Description

KEK千代さんからの指摘。添付スライド参照。

wait()に与えるタイムアウト時間は絶対時間ではなくてはならないが、相対時間を与えている。

daqmw-core.2013-03-18.pptx (523 KB) daqmw-core.2013-03-18.pptx n-ando, 03/18/2013 05:20 PM

History

#1 Updated by n-ando almost 8 years ago

--- OpenRTM-aist-r1971/src/lib/coil/posix/coil/Condition.h.orig 2010-06-24 09:22:51.000000000 +0900
+++ OpenRTM-aist-r1971/src/lib/coil/posix/coil/Condition.h      2013-02-22 09:26:12.108141163 +0900
@@ -20,6 +20,7 @@
 #ifndef COIL_CONDITION_H
 #define COIL_CONDITION_H

+#include <sys/time.h>
 #include <pthread.h>
 #include <algorithm>
 #include <ctime>
@@ -177,9 +178,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);
     }

#2 Updated by n-ando almost 8 years ago

  • Status changed from 新規 to 終了
  • % Done changed from 0 to 100

#2637 にて修正済み。

Also available in: Atom PDF