[openrtm-commit:03207] r955 - branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2018年 3月 2日 (金) 15:38:43 JST


Author: miyamoto
Date: 2018-03-02 15:38:42 +0900 (Fri, 02 Mar 2018)
New Revision: 955

Modified:
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/RingBuffer.py
Log:
[merge] r950-r953

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/RingBuffer.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/RingBuffer.py	2018-03-02 01:40:49 UTC (rev 954)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/RingBuffer.py	2018-03-02 06:38:42 UTC (rev 955)
@@ -237,7 +237,8 @@
   # ½ñ¤­¹þ¤ß²Äǽ¤ÊÍ×ÁÇ¿ô°Ê¾å¤Î¿ôÃͤò»ØÄꤷ¤¿¾ì¹ç¡¢PRECONDITION_NOT_MET
   # ¤òÊÖ¤¹¡£
   # 
-  # @param  n ½ñ¹þ¤ß¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿ 
+  # @param  n ½ñ¹þ¤ß¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿
+  # @param unlock_enable True¤Î¾ì¹ç¤Ë¥Ð¥Ã¥Õ¥¡¥¨¥ó¥×¥Æ¥£¤Î¥Ö¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë
   # @return BUFFER_OK:            Àµ¾ï½ªÎ»
   #         PRECONDITION_NOT_MET: n > writable()
   # 
@@ -247,12 +248,19 @@
   #
   # Pure virtual function to get the buffer length.
   #
+  # @param  n 
+  # @param unlock_enable 
+  #
   # @return buffer length
   # 
   # @endif
   # 
   # ReturnCode advanceWptr(long int n = 1)
-  def advanceWptr(self, n = 1):
+  def advanceWptr(self, n = 1, unlock_enable=True):
+    empty = False
+    if unlock_enable and n > 0:
+      self._empty_cond.acquire()
+      empty = self.empty()
     # n > 0 :
     #     n satisfies n <= writable elements
     #                 n <= m_length - m_fillcout
@@ -267,6 +275,12 @@
 
     self._wpos = (self._wpos + n + self._length) % self._length
     self._fillcount += n
+
+    if unlock_enable and n > 0:
+      if empty:
+        self._empty_cond.notify()
+      self._empty_cond.release()
+    
     return OpenRTM_aist.BufferStatus.BUFFER_OK
 
 
@@ -349,6 +363,7 @@
   def write(self, value, sec = -1, nsec = 0):
     try:
       self._full_cond.acquire()
+      self.full()
       if self.full():
         timedwrite = self._timedwrite # default is False
         overwrite  = self._overwrite  # default is True
@@ -358,7 +373,7 @@
           overwrite  = False
 
         if overwrite and not timedwrite:       # "overwrite" mode
-          self.advanceRptr()
+          self.advanceRptr(unlock_enable=False)
 
         elif not overwrite and not timedwrite: # "do_nothing" mode
           self._full_cond.release()
@@ -388,19 +403,11 @@
         else: # unknown condition
           self._full_cond.release()
           return OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET
-      
       self._full_cond.release()
 
       self.put(value)
       
-      self._empty_cond.acquire()
-      empty = self.empty()
-      if empty:
-        self.advanceWptr(1)
-        self._empty_cond.notify()
-      else:
-        self.advanceWptr(1)
-      self._empty_cond.release()
+      self.advanceWptr(1)
 
       return OpenRTM_aist.BufferStatus.BUFFER_OK
     except:
@@ -490,7 +497,8 @@
   # 
   # ¸½ºß¤ÎÆɤ߽Ф·°ÌÃ֤Υݥ¤¥ó¥¿¤ò n ¸Ä¿Ê¤á¤ë¡£
   # 
-  # @param  n Æɤ߽Ф·¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿ 
+  # @param  n Æɤ߽Ф·¥Ý¥¤¥ó¥¿ + n ¤Î°ÌÃ֤Υݥ¤¥ó¥¿
+  # @param unlock_enable True¤Î¾ì¹ç¤Ë¥Ð¥Ã¥Õ¥¡¥Õ¥ë¤Î¥Ö¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë
   # @return BUFFER_OK: Àµ¾ï½ªÎ»
   #         BUFFER_ERROR: °Û¾ï½ªÎ»
   # 
@@ -500,12 +508,19 @@
   #
   # Pure virtual function to get the buffer length.
   #
+  # @param  n 
+  # @param unlock_enable 
+  #
   # @return buffer length
   # 
   # @endif
   # 
   # DataType* rptr(long int n = 0)
-  def advanceRptr(self, n = 1):
+  def advanceRptr(self, n = 1, unlock_enable=True):
+    full_ = False
+    if unlock_enable and n > 0:
+      self._full_cond.acquire()
+      full_ = self.full()
     # n > 0 :
     #     n satisfies n <= readable elements
     #                 n <= m_fillcout 
@@ -519,6 +534,14 @@
 
     self._rpos = (self._rpos + n + self._length) % self._length
     self._fillcount -= n
+    
+    
+    
+    if unlock_enable and n > 0:
+      if full_:
+        self._full_cond.notify()
+      self._full_cond.release()
+    
     return OpenRTM_aist.BufferStatus.BUFFER_OK
 
 
@@ -655,18 +678,9 @@
     else:
       value.append(val)
 
-    self._full_cond.acquire()
-    full_ = self.full()
+    self.advanceRptr()
 
-    if full_:
-      self.advanceRptr()
-      self._full_cond.notify()
-    else:
-      self.advanceRptr()
 
-    self._full_cond.release()
-
-
     return OpenRTM_aist.BufferStatus.BUFFER_OK
 
     



More information about the openrtm-commit mailing list