[openrtm-commit:03216] r3234 - branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2018年 3月 5日 (月) 15:07:30 JST


Author: miyamoto
Date: 2018-03-05 15:07:30 +0900 (Mon, 05 Mar 2018)
New Revision: 3234

Modified:
   branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/BufferBase.h
   branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/RingBuffer.h
Log:
[bugfix, ->trunk] bug fixed. refs #4473

Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/BufferBase.h
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/BufferBase.h	2018-03-05 01:50:16 UTC (rev 3233)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/BufferBase.h	2018-03-05 06:07:30 UTC (rev 3234)
@@ -254,7 +254,7 @@
      * 
      * @endif
      */ 
-    virtual ReturnCode advanceWptr(long int n = 1) = 0;
+    virtual ReturnCode advanceWptr(long int n = 1, bool unlock_enable = true) = 0;
 
     /*!
      * @if jp
@@ -400,7 +400,7 @@
      * 
      * @endif
      */ 
-    virtual ReturnCode advanceRptr(long int n = 1) = 0;
+    virtual ReturnCode advanceRptr(long int n = 1, bool unlock_enable = true) = 0;
 
     /*!
      * @if jp

Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/RingBuffer.h
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/RingBuffer.h	2018-03-05 01:50:16 UTC (rev 3233)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/RingBuffer.h	2018-03-05 06:07:30 UTC (rev 3234)
@@ -318,6 +318,7 @@
      * ¤òÊÖ¤¹¡£
      * 
      * @param  n ½ñ¹þ¤ß¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿ 
+     * @param  unlock_enable true¤Î¾ì¹ç¤Ë¥Ð¥Ã¥Õ¥¡¥¨¥ó¥×¥Æ¥£¤Î¥Ö¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë
      * @return BUFFER_OK:            Àµ¾ï½ªÎ»
      *         PRECONDITION_NOT_MET: n > writable()
      * 
@@ -331,8 +332,14 @@
      * 
      * @endif
      */ 
-    virtual ReturnCode advanceWptr(long int n = 1)
+    virtual ReturnCode advanceWptr(long int n = 1, bool unlock_enable = true)
     {
+      bool empty_ = false;
+      if(unlock_enable && n > 0)
+        {
+          Guard fguard(m_empty.mutex);
+          empty_ = empty();
+        }
       // n > 0 :
       //     n satisfies n <= writable elements
       //                 n <= m_length - m_fillcout
@@ -350,6 +357,16 @@
       m_wpos = (m_wpos + n + m_length) % m_length;
       m_fillcount += n;
       m_wcount += n;
+
+      if(unlock_enable)
+        {
+          if(empty_)
+            {
+              Guard fguard(m_empty.mutex);
+              m_empty.cond.signal();
+            }
+        }
+
       return ::RTC::BufferStatus::BUFFER_OK;
     }
     /*!
@@ -447,7 +464,7 @@
 
           if (overwrite && !timedwrite)       // "overwrite" mode
             {
-              advanceRptr();
+              advanceRptr(1,false);
             }
           else if (!overwrite && !timedwrite) // "do_nothing" mode
             {
@@ -475,19 +492,9 @@
     
       put(value);
 
-	  {
-		Guard eguard(m_empty.mutex);
-		if (empty())
-		  {
-			// Guard eguard(m_empty.mutex);
-			advanceWptr(1);
-			m_empty.cond.signal();
-		  }
-		else
-		  {
-			advanceWptr(1);
-		  }
-	  }
+      advanceWptr(1);
+
+
       return ::RTC::BufferStatus::BUFFER_OK;
     }
     
@@ -578,6 +585,7 @@
      * ¸½ºß¤ÎÆɤ߽Ф·°ÌÃ֤Υݥ¤¥ó¥¿¤ò n ¸Ä¿Ê¤á¤ë¡£
      * 
      * @param  n Æɤ߽Ф·¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿ 
+     * @param  unlock_enable true¤Î¾ì¹ç¤Ë¥Ð¥Ã¥Õ¥¡¥Õ¥ë¤Î¥Ö¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë
      * @return BUFFER_OK: Àµ¾ï½ªÎ»
      *         BUFFER_ERROR: °Û¾ï½ªÎ»
      * 
@@ -591,8 +599,14 @@
      * 
      * @endif
      */ 
-    virtual ReturnCode advanceRptr(long int n = 1)
+    virtual ReturnCode advanceRptr(long int n = 1, bool unlock_enable = true)
     {
+      bool full_ = false;
+      if(unlock_enable && n > 0)
+        {
+          Guard fguard(m_full.mutex);
+          full_ = full();
+        }
       // n > 0 :
       //     n satisfies n <= readable elements
       //                 n <= m_fillcout 
@@ -608,6 +622,16 @@
 
       m_rpos = (m_rpos + n + m_length) % m_length;
       m_fillcount -= n;
+
+      if(unlock_enable)
+        {
+          if(full_)
+            {
+              Guard fguard(m_full.mutex);
+              m_full.cond.signal();
+            }
+        }
+
       return ::RTC::BufferStatus::BUFFER_OK;
     }
     
@@ -761,19 +785,8 @@
       
       get(value);
 
-	  {
-		Guard fguard(m_full.mutex);
-		if (full())
-		  {
-			// Guard fguard(m_full.mutex);
-			advanceRptr(1);
-			m_full.cond.signal();
-		  }
-		else
-		  {
-			advanceRptr(1);
-		  }
-	  }
+      advanceRptr(1);
+
       return ::RTC::BufferStatus::BUFFER_OK;
     }
     



More information about the openrtm-commit mailing list