[openrtm-commit:03335] r1029 - trunk/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2018年 10月 5日 (金) 19:17:29 JST


Author: miyamoto
Date: 2018-10-05 19:17:29 +0900 (Fri, 05 Oct 2018)
New Revision: 1029

Modified:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/MultilayerCompositeEC.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicECSharedComposite.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
Log:
[compat. bugfix] fixed bug.

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/MultilayerCompositeEC.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/MultilayerCompositeEC.py	2018-09-28 07:15:31 UTC (rev 1028)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/MultilayerCompositeEC.py	2018-10-05 10:17:29 UTC (rev 1029)
@@ -66,7 +66,18 @@
 
     return
 
-
+  ##
+  # @if jp
+  # @brief ½ªÎ»´Ø¿ô
+  #
+  # @param self¡¡
+  # @param Task¡¡
+  #
+  # @else
+  # @brief 
+  # @param self¡¡
+  # @param Task¡¡
+  # @endif
   def exit(self, Task=OpenRTM_aist.Task):
     OpenRTM_aist.PeriodicExecutionContext.exit(self)
     for task in self._tasklist:
@@ -73,6 +84,18 @@
       task.finalize()
     return
 
+  ##
+  # @if jp
+  # @brief ½é´ü²½´Ø¿ô
+  #
+  # @param self¡¡
+  # @param props ¥×¥í¥Ñ¥Æ¥£
+  #
+  # @else
+  # @brief 
+  # @param self¡¡
+  # @param props 
+  # @endif
   def init(self, props):
     OpenRTM_aist.PeriodicExecutionContext.init(self, props)
     #prop.getProperty("thread_type", "default")
@@ -79,7 +102,20 @@
     
 
 
-
+  ##
+  # @if jp
+  # @brief ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥Ð¥¤¥ó¥É¤¹¤ë¡£
+  #
+  # @param self
+  # @param rtc RTC
+  #
+  # @else
+  # @brief Bind the component.
+  #
+  # @param self
+  # @param rtc RTC
+  #
+  # @endif
   def bindComponent(self, rtc):
     ret = OpenRTM_aist.ExecutionContextBase.bindComponent(self, rtc)
 
@@ -107,18 +143,62 @@
           continue
         rtcs.append(rtobj)
         
-      self.addTask(rtc, rtcs)
+      self.addTask(rtcs)
 
         
     return ret
 
+  ##
+  # @if jp
+  # @class 
+  # @brief worker ÍѾõÂÖÊÑ¿ô¥¯¥é¥¹
+  # @else
+  # @brief
+  #
+  # @endif
   class WorkerThreadCtrl:
+    ##
+    # @if jp
+    # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿
+    #
+    # ¥³¥ó¥¹¥È¥é¥¯¥¿
+    #
+    # @param self
+    #
+    # @else
+    # @brief Constructor
+    # @endif
     def __init__(self):
       self._mutex = threading.RLock()
       self._cond = threading.Condition(self._mutex)
       self._running = False
-      
+
+  ##
+  # @if jp
+  # @class 
+  # @brief RTC¼þ´ü¼Â¹Ô¥¹¥ì¥Ã¥É
+  # @else
+  # @brief
+  #
+  # @endif
   class ChildTask:
+    ##
+    # @if jp
+    # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿
+    #
+    # @param self
+    # @param task ¼þ´ü¼Â¹Ô¥¹¥ì¥Ã¥É
+    # @param ec ¼Â¹Ô¥³¥ó¥Æ¥­¥¹¥È
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @param task 
+    # @param ec 
+    #
+    # @endif
     def __init__(self, task, ec):
       self._rtcs = []
       self._task = task
@@ -125,9 +205,41 @@
       self._ec = ec
       self._comps = []
       self._worker = MultilayerCompositeEC.WorkerThreadCtrl()
+      self._signal_worker = MultilayerCompositeEC.WorkerThreadCtrl()
+
+    ##
+    # @if jp
+    # @brief ¼Â¹Ô¤¹¤ëRTC¤òÄɲÃ
+    #
+    # @param self
+    # @param rtc RTC
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @param rtc RTC
+    #
+    # @endif
     def addComponent(self, rtc):
       self._rtcs.append(rtc)
 
+    ##
+    # @if jp
+    # @brief ¥¹¥Æ¡¼¥È¥Þ¥·¥ó¤Î¥ê¥¹¥È¤ò¹¹¿·
+    #
+    # @param self
+    # @param return
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @param return
+    #
+    # @endif
     def updateCompList(self):
       for rtc in self._rtcs[:]:
         comp = self._ec.findComponent(rtc)
@@ -134,9 +246,34 @@
         if comp:
           self._rtcs.remove(rtc)
           self._comps.append(comp)
-        
+
+    ##
+    # @if jp
+    # @brief ¥¹¥ì¥Ã¥É¼Â¹Ô´Ø¿ô
+    #
+    # @param self
+    # @param return
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @param return
+    #
+    # @endif
     def svc(self):
       self._worker._running = True
+      
+      
+      self._signal_worker._cond.acquire()
+      while not self._signal_worker._running:
+        self._signal_worker._cond.wait()
+      self._signal_worker._cond.release()
+      self._signal_worker._running = False
+      
+      
+      
       self.updateCompList()
       for comp in self._comps:
         comp.workerPreDo()
@@ -146,22 +283,120 @@
       self._worker._cond.acquire()
       self._worker._cond.notify()
       self._worker._cond.release()
+
       
+      self._signal_worker._cond.acquire()
+      while not self._signal_worker._running:
+        self._signal_worker._cond.wait()
+      self._signal_worker._cond.release()
+      self._signal_worker._running = False
+      
+      
+      return 0
+
+    ##
+    # @if jp
+    # @brief 1²ó¤Î½èÍý¤ò¼Â¹Ô
+    #
+    # @param self
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    #
+    # @endif
     def signal(self):
+      
       while not self._worker._running:
         self._task.signal()
-        
+      
+      
+      self._signal_worker._running = True
+      self._signal_worker._cond.acquire()
+      self._signal_worker._cond.notify()
+      self._signal_worker._cond.release()
+      
+      
+      
+    ##
+    # @if jp
+    # @brief 1²ó¤Î½èÍý½ªÎ»¤Þ¤ÇÂÔµ¡
+    #
+    # @param self
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    #
+    # @endif
     def join(self):
+      
       self._worker._cond.acquire()
       while self._worker._running:
         self._worker._cond.wait()
       self._worker._cond.release()
+      
 
+      self._signal_worker._running = True
+      self._signal_worker._cond.acquire()
+      self._signal_worker._cond.notify()
+      self._signal_worker._cond.release()
+      
+
+    ##
+    # @if jp
+    # @brief ¥¿¥¹¥¯¼þ´ü»þ´Ö·×¬·ë²Ì¤ò¼èÆÀ
+    #
+    # @param self
+    # @return ·×¬·ë²Ì
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @return
+    #
+    # @endif
     def getPeriodStat(self):
       return self._task.getPeriodStat()
+
+
+    ##
+    # @if jp
+    # @brief ¥¿¥¹¥¯´Ø¿ô¼Â¹Ô»þ´Ö·×¬·ë²Ì¤ò¼èÆÀ
+    #
+    # @param self
+    # @return ·×¬·ë²Ì
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    # @return
+    #
+    # @endif
     def getExecStat(self):
       return self._task.getExecStat()
 
+    ##
+    # @if jp
+    # @brief RTC¼Â¹Ô¥¹¥ì¥Ã¥É½ªÎ»´Ø¿ô
+    #
+    # @param self
+    #
+    # @else
+    #
+    # @brief 
+    #
+    # @param self
+    #
+    # @endif
     def finalize(self):
       self._task.resume()
       self._task.finalize()
@@ -168,8 +403,23 @@
 
       OpenRTM_aist.PeriodicTaskFactory.instance().deleteObject(self._task)
       
-    
-  def addTask(self, owner, rtcs):
+  ##
+  # @if jp
+  # @brief RTC¼Â¹Ô¥¹¥ì¥Ã¥ÉºîÀ®
+  #
+  # @param self
+  # @param rtcs ¥¹¥ì¥Ã¥É¤Ë´ØÏ¢ÉÕ¤±¤ëRTC°ìÍ÷
+  # @return ¥¹¥Æ¡¼¥È¥Þ¥·¥ó
+  #
+  # @else
+  #
+  # @brief 
+  #
+  # @param self
+  # @param rtcs 
+  #
+  # @endif
+  def addTask(self, rtcs):
     prop = self._profile.getProperties().getNode("ec"+str(len(self._tasklist)))
     factory = OpenRTM_aist.PeriodicTaskFactory.instance()
 
@@ -176,6 +426,7 @@
     task = factory.createObject(prop.getProperty("thread_type", "default"))
     if not task:
       self._rtcout.RTC_ERROR("Task creation failed: %s", prop.getProperty("thread_type", "default"))
+      return
 
     ct = MultilayerCompositeEC.ChildTask(task, self)
 
@@ -204,15 +455,45 @@
     task.suspend()
 
 
-      
 
-
-        
-
-    return True
+  ##
+  # @if jp
+  # @brief ¥³¥ó¥Ý¡¼¥Í¥ó¥Èõº÷´Ø¿ô
+  #
+  # @param self
+  # @param rtobj RTC
+  # @return ¥¹¥Æ¡¼¥È¥Þ¥·¥ó
+  #
+  # @else
+  #
+  # @brief 
+  #
+  # @param self
+  # @param rtobj 
+  # @return 
+  #
+  # @endif
   def findComponent(self, rtobj):
     return self._worker.findComponent(rtobj)
 
+  ##
+  # @if jp
+  # @brief RTC¼Â¹Ô¥¹¥ì¥Ã¥É¤ËRTC¤òÄɲÃ
+  # Ê£¹ç¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾ì¹ç¤Ï»Ò¥³¥ó¥Ý¡¼¥Í¥ó¥È¤âÄɲÃ
+  #
+  # @param self
+  # @param task RTC¼Â¹Ô¥¹¥ì¥Ã¥É
+  # @param rtobj RTC
+  #
+  # @else
+  #
+  # @brief 
+  #
+  # @param self
+  # @param task
+  # @param rtobj 
+  #
+  # @endif
   def addRTCToTask(self, task, rtobj):
     #comp = self._worker.findComponent(rtobj)
     orglist = rtobj.get_owned_organizations()

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicECSharedComposite.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicECSharedComposite.py	2018-09-28 07:15:31 UTC (rev 1028)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicECSharedComposite.py	2018-10-05 10:17:29 UTC (rev 1029)
@@ -691,7 +691,20 @@
   def __del__(self):
     self._rtcout.RTC_TRACE("destructor of PeriodicECSharedComposite")
     OpenRTM_aist.RTObject_impl.__del__(self)
-    
+
+  ##
+  # @if jp
+  # @brief ½ªÎ»´Ø¿ô
+  # ¥ª¡¼¥¬¥Ê¥¤¥º¥ª¥Ö¥¸¥§¥¯¥È¤òÈó¥¢¥¯¥Æ¥£¥Ö¤Ë¤¹¤ë
+  #
+  # @param self
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  #
+  # @endif
   def shutdown(self):
     OpenRTM_aist.RTObject_impl.shutdown(self)
     poa = OpenRTM_aist.Manager.instance().getPOA()
@@ -807,7 +820,21 @@
     
     return RTC.RTC_OK
 
-
+  ##
+  # @if jp
+  # @brief RTC¤ò¥¢¥¯¥Æ¥£¥Ö²½¤¹¤ë
+  # Ê£¹ç¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾ì¹ç¤Ï»Ò¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¢¥¯¥Æ¥£¥Ö²½¤¹¤ë
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @endif
   def activateChildComp(self, rtobj):
     ecs = self.get_owned_contexts()
 
@@ -865,7 +892,21 @@
     
     return RTC.RTC_OK
 
-
+  ##
+  # @if jp
+  # @brief RTC¤òÈó¥¢¥¯¥Æ¥£¥Ö²½¤¹¤ë
+  # Ê£¹ç¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾ì¹ç¤Ï»Ò¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÈó¥¢¥¯¥Æ¥£¥Ö²½¤¹¤ë
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @endif
   def deactivateChildComp(self, rtobj):
     ecs = self.get_owned_contexts()
 
@@ -926,7 +967,21 @@
     return RTC.RTC_OK
 
 
-
+  ##
+  # @if jp
+  # @brief RTC¤ò¥ê¥»¥Ã¥È¤¹¤ë
+  # Ê£¹ç¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¾ì¹ç¤Ï»Ò¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥ê¥»¥Ã¥È¤¹¤ë
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @else
+  # @brief 
+  #
+  # @param self
+  # @param rtobj RTC
+  #
+  # @endif
   def resetChildComp(self, rtobj):
     ecs = self.get_owned_contexts()
 

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2018-09-28 07:15:31 UTC (rev 1028)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2018-10-05 10:17:29 UTC (rev 1029)
@@ -78,7 +78,18 @@
 
     return
 
-
+  ##
+  # @if jp
+  # @brief ½ªÎ»´Ø¿ô
+  #
+  # @param self¡¡
+  # @param Task¡¡
+  #
+  # @else
+  # @brief 
+  # @param self¡¡
+  # @param Task¡¡
+  # @endif
   def exit(self, Task=OpenRTM_aist.Task):
     import OpenRTM_aist.Guard
     self._rtcout.RTC_TRACE("PeriodicExecutionContext.__del__()")
@@ -97,6 +108,19 @@
     OpenRTM_aist.ExecutionContextBase.exit(self)
     return
 
+
+  ##
+  # @if jp
+  # @brief ½é´ü²½´Ø¿ô
+  #
+  # @param self¡¡
+  # @param props ¥×¥í¥Ñ¥Æ¥£
+  #
+  # @else
+  # @brief 
+  # @param self¡¡
+  # @param props 
+  # @endif
   def init(self, props):
     OpenRTM_aist.ExecutionContextBase.init(self, props)
     self.setCpuAffinity(props)
@@ -606,19 +630,7 @@
     return RTC.RTC_OK
 
 
-  def onStopped(self):
-    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
-    self._svc = False
-    del guard
 
-    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
-    self._workerthread._cond.acquire()
-    self._workerthread._running = True
-    self._workerthread._cond.notify()
-    self._workerthread._cond.release()
-    del guard
-    self.wait()
-    return RTC.RTC_OK
 
   def onAddedComponent(self, rtobj):
     guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
@@ -641,13 +653,14 @@
                                self.getStateString(comp.getStates().next)))
     # Now comp's next state must be ACTIVE state
     # If worker thread is stopped, restart worker thread.
-    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
-    if self._workerthread._running == False:
-      self._workerthread._running = True
-      self._workerthread._cond.acquire()
-      self._workerthread._cond.notify()
-      self._workerthread._cond.release()
-    del guard
+    if self.isRunning():
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == False:
+        self._workerthread._running = True
+        self._workerthread._cond.acquire()
+        self._workerthread._cond.notify()
+        self._workerthread._cond.release()
+      del guard
     return RTC.RTC_OK
 
 
@@ -665,13 +678,14 @@
 
     # Now comp's next state must be ACTIVE state
     # If worker thread is stopped, restart worker thread.
-    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
-    if self._workerthread._running == False:
-      self._workerthread._running = True
-      self._workerthread._cond.acquire()
-      self._workerthread._cond.notify()
-      self._workerthread._cond.release()
-    del guard
+    if self.isRunning():
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == False:
+        self._workerthread._running = True
+        self._workerthread._cond.acquire()
+        self._workerthread._cond.notify()
+        self._workerthread._cond.release()
+      del guard
     return RTC.RTC_OK
 
 



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