[openrtm-commit:00679] r2320 - trunk/OpenRTM-aist/src/lib/coil/common

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 2月 8日 (水) 03:51:14 JST


Author: n-ando
Date: 2012-02-08 03:51:13 +0900 (Wed, 08 Feb 2012)
New Revision: 2320

Modified:
   trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp
   trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h
Log:
[incompat,impl/header,bigfix] Mutex guard has been introduced to logical clock and adjusted clock class.


Modified: trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp	2012-02-07 18:50:03 UTC (rev 2319)
+++ trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp	2012-02-07 18:51:13 UTC (rev 2320)
@@ -17,8 +17,8 @@
  */
 
 #include <coil/Time.h>
-#include <math.h>
 #include <coil/ClockManager.h>
+#include <coil/Guard.h>
 
 namespace coil
 {
@@ -60,11 +60,13 @@
 
   coil::TimeValue LogicalClock::gettime() const
   {
+    coil::Guard<coil::Mutex> guard(m_currentTimeMutex);
     return m_currentTime;
   }
 
   bool LogicalClock::settime(coil::TimeValue clocktime)
   {
+    Guard<Mutex> guard(m_currentTimeMutex);
     m_currentTime = clocktime;
     return true;
   }
@@ -78,21 +80,23 @@
     : m_offset(0.0)
   {
   }
-  
+
   AdjustedClock::~AdjustedClock()
   {
   }
-  
+
   coil::TimeValue AdjustedClock::gettime() const
   {
+    Guard<Mutex> guard(m_offsetMutex);
     return coil::gettimeofday() - m_offset;
   }
-  
+
   bool AdjustedClock::settime(coil::TimeValue clocktime)
-    {
-      m_offset = coil::gettimeofday() - clocktime;
-      return true;
-    }
+  {
+    Guard<Mutex> guard(m_offsetMutex);
+    m_offset = coil::gettimeofday() - clocktime;
+    return true;
+  }
 
   IClock& ClockManager::getClock(std::string clocktype)
   {

Modified: trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h	2012-02-07 18:50:03 UTC (rev 2319)
+++ trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h	2012-02-07 18:51:13 UTC (rev 2320)
@@ -22,6 +22,7 @@
 #include <string>
 #include <coil/Singleton.h>
 #include <coil/TimeValue.h>
+#include <coil/Mutex.h>
 
 namespace coil
 {
@@ -113,12 +114,14 @@
   class LogicalClock
     : public IClock
   {
-    coil::TimeValue m_currentTime;
   public:
     LogicalClock();
     virtual ~LogicalClock();
     virtual coil::TimeValue gettime() const;
     virtual bool settime(coil::TimeValue clocktime);
+  private:
+    coil::TimeValue m_currentTime;
+    mutable coil::Mutex m_currentTimeMutex;
   };
 
   /*!
@@ -139,12 +142,14 @@
   class AdjustedClock
     : public IClock
   {
-    coil::TimeValue m_offset;
   public:
     AdjustedClock();
     virtual ~AdjustedClock();
     virtual coil::TimeValue gettime() const;
     virtual bool settime(coil::TimeValue clocktime);
+  private:
+    coil::TimeValue m_offset;
+    mutable coil::Mutex m_offsetMutex;
   };
 
   /*!



openrtm-commit メーリングリストの案内