Revision: 7724
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7724&view=rev
Author:   hsujohnhsu
Date:     2009-05-27 02:54:33 +0000 (Wed, 27 May 2009)

Log Message:
-----------
trying different mutex configs.

Modified Paths:
--------------
    code/gazebo/branches/threads/server/Global.hh
    code/gazebo/branches/threads/server/Simulator.cc
    code/gazebo/branches/threads/server/Simulator.hh
    code/gazebo/branches/threads/server/World.cc
    code/gazebo/branches/threads/server/rendering/OgreCreator.cc

Modified: code/gazebo/branches/threads/server/Global.hh
===================================================================
--- code/gazebo/branches/threads/server/Global.hh       2009-05-26 18:13:32 UTC 
(rev 7723)
+++ code/gazebo/branches/threads/server/Global.hh       2009-05-27 02:54:33 UTC 
(rev 7724)
@@ -80,4 +80,6 @@
 
 #define ROUND(x) ( (int)( floor((x)+0.5) ) )
 
+#define TIMING
+
 #endif

Modified: code/gazebo/branches/threads/server/Simulator.cc
===================================================================
--- code/gazebo/branches/threads/server/Simulator.cc    2009-05-26 18:13:32 UTC 
(rev 7723)
+++ code/gazebo/branches/threads/server/Simulator.cc    2009-05-27 02:54:33 UTC 
(rev 7724)
@@ -77,7 +77,9 @@
   selectedEntity(NULL),
   selectedBody(NULL)
 {
-  this->mutex = new boost::recursive_mutex();
+  this->pr_mutex = new boost::recursive_mutex();
+  this->cr_mutex = new boost::recursive_mutex();
+  this->mr_mutex = new boost::recursive_mutex();
   this->p_mutex = new boost::mutex();
   this->c_mutex = new boost::mutex();
   this->m_mutex = new boost::mutex();
@@ -104,12 +106,24 @@
     this->xmlFile = NULL;
   }
 
-  if (this->mutex)
+  if (this->pr_mutex)
   {
-    delete this->mutex;
-    this->mutex = NULL;
+    delete this->pr_mutex;
+    this->pr_mutex = NULL;
   }
 
+  if (this->cr_mutex)
+  {
+    delete this->cr_mutex;
+    this->cr_mutex = NULL;
+  }
+
+  if (this->mr_mutex)
+  {
+    delete this->mr_mutex;
+    this->mr_mutex = NULL;
+  }
+
   if (this->gui)
   {
     delete this->gui;
@@ -686,23 +700,34 @@
   /*********************************************/
   while (!this->userQuit)
   {
+#ifdef TIMING
+    double tmpT1 = this->GetWallTime();
+#endif
+
     // thread control
     {
         boost::lock_guard<boost::mutex> c_lock(*this->c_mutex);
         this->run_collision=true;
+    }
+    this->c_cond->notify_all();
+
+    {
         boost::lock_guard<boost::mutex> m_lock(*this->m_mutex);
         this->run_models=true;
     }
-    this->c_cond->notify_all();
     this->m_cond->notify_all();
 
 
 
     // wait for c and m threads to finish
-    boost::unique_lock<boost::mutex> p_lock(*this->p_mutex);
-    while (this->run_collision||this->run_models)
     {
-      this->p_cond->wait(p_lock);
+      //bool run_physics = false;
+      boost::unique_lock<boost::mutex> p_lock(*this->p_mutex);
+      //while (!run_physics)
+      while (this->run_collision || this->run_models)
+      {
+        this->p_cond->wait(p_lock);
+      }
     }
 
 
@@ -727,8 +752,7 @@
 
       // lock mutex and update physics
       {
-        boost::recursive_mutex::scoped_lock lock(*this->mutex);
-        //world->Update();
+        //boost::recursive_mutex::scoped_lock lock(*this->pr_mutex);
         world->UpdatePhysics();
       }
 
@@ -751,21 +775,34 @@
     }
 
     // // thread control
+#ifdef TIMING
+    double tmpT2 = this->GetWallTime();
+    std::cout << " Simulator::PhysicsLoop() DT(" << tmpT2-tmpT1 << ")" << 
std::endl;
+#endif
 
   }
 
-  // // get ready to quit
-  // this->cp_mutex->unlock();
-  // this->mp_mutex->unlock();
+}
 
+////////////////////////////////////////////////////////////////////////////////
+/// Get the simulator mutex
+boost::recursive_mutex *Simulator::GetCRMutex()
+{
+  return this->cr_mutex;
+}
 
+////////////////////////////////////////////////////////////////////////////////
+/// Get the simulator mutex
+boost::recursive_mutex *Simulator::GetMRMutex()
+{
+  return this->mr_mutex;
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 /// Get the simulator mutex
-boost::recursive_mutex *Simulator::GetMutex()
+boost::recursive_mutex *Simulator::GetPRMutex()
 {
-  return this->mutex;
+  return this->pr_mutex;
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/branches/threads/server/Simulator.hh
===================================================================
--- code/gazebo/branches/threads/server/Simulator.hh    2009-05-26 18:13:32 UTC 
(rev 7723)
+++ code/gazebo/branches/threads/server/Simulator.hh    2009-05-27 02:54:33 UTC 
(rev 7724)
@@ -183,7 +183,9 @@
     public: Body *GetParentBody( Entity *entity ) const;
 
     /// \brief Get the simulator mutex
-    public:boost::recursive_mutex *GetMutex();
+    public:boost::recursive_mutex *GetPRMutex();
+    public:boost::recursive_mutex *GetMRMutex();
+    public:boost::recursive_mutex *GetCRMutex();
 
     /// \brief Function to run gui. Used by guiThread
     private: void PhysicsLoop();
@@ -257,7 +259,9 @@
     private: boost::thread *modelsThread;
 
     // mutex between rendering and (physics,collision,models update)
-    private: boost::recursive_mutex *mutex;
+    private: boost::recursive_mutex *cr_mutex;
+    private: boost::recursive_mutex *pr_mutex;
+    private: boost::recursive_mutex *mr_mutex;
 
     // mutex for physics, collisions, models update sequence control
     private: boost::mutex *c_mutex;

Modified: code/gazebo/branches/threads/server/World.cc
===================================================================
--- code/gazebo/branches/threads/server/World.cc        2009-05-26 18:13:32 UTC 
(rev 7723)
+++ code/gazebo/branches/threads/server/World.cc        2009-05-27 02:54:33 UTC 
(rev 7724)
@@ -302,6 +302,7 @@
   if (!Simulator::Instance()->IsPaused() &&
        Simulator::Instance()->GetPhysicsEnabled())
   {
+    //boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetPRMutex());
     this->physicsEngine->UpdatePhysics();
   }
 
@@ -326,19 +327,15 @@
 
   Simulator* simulator = Simulator::Instance();
 
-  // initialize
-  //std::cout << "C: locking pc" << std::endl;
-  //simulator->GetPC()->lock();  // make sure pc is locked before releasing 
c_init
-  //std::cout << "C: unlocking c_init" << std::endl;
-  //simulator->GetCInit()->unlock(); // unlock c_init so main thread can begin
-
   while (!simulator->GetUserQuit())
   {
 
-    boost::unique_lock<boost::mutex> lock(*simulator->GetC());
-    while (!simulator->RunCollision())
     {
-      simulator->GetCCond()->wait(lock);
+      boost::unique_lock<boost::mutex> lock(*simulator->GetC());
+      while (!simulator->RunCollision())
+      {
+        simulator->GetCCond()->wait(lock);
+      }
     }
 
 #ifdef TIMING
@@ -348,24 +345,16 @@
     if (!Simulator::Instance()->IsPaused() &&
          Simulator::Instance()->GetPhysicsEnabled())
     {
-      boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetMutex());
+      //boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetCRMutex());
       this->physicsEngine->UpdateCollision();
     }
 
 #ifdef TIMING
     double tmpT2 = Simulator::Instance()->GetWallTime();
-    std::cout << " World::Update() Collision DT(" << tmpT2-tmpT1 << ")" << 
std::endl;
+    //std::cout << " World::Update() Collision DT(" << tmpT2-tmpT1 << ")" << 
std::endl;
 #endif
 
     // thread control
-    // std::cout << "C: unlocking pc" << std::endl;
-    // simulator->GetPC()->unlock();
-    // std::cout << "C: locking cp" << std::endl;
-    // simulator->GetCP()->lock();
-    // std::cout << "C: locking pc" << std::endl;
-    // simulator->GetPC()->lock();
-    // std::cout << "C: unlocking cp" << std::endl;
-    // simulator->GetCP()->unlock();
     {
       boost::lock_guard<boost::mutex> p_lock(*simulator->GetP());
       simulator->CollisionDone();
@@ -382,15 +371,15 @@
 
   Simulator* simulator = Simulator::Instance();
 
-  // initialize
-
   while (!simulator->GetUserQuit())
   {
 
-    boost::unique_lock<boost::mutex> lock(*simulator->GetM());
-    while (!simulator->RunModels())
     {
-      simulator->GetMCond()->wait(lock);
+      boost::unique_lock<boost::mutex> lock(*simulator->GetM());
+      while (!simulator->RunModels())
+      {
+        simulator->GetMCond()->wait(lock);
+      }
     }
 
 #ifdef TIMING
@@ -398,7 +387,7 @@
 #endif
 
     {
-      boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetMutex());
+      boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetMRMutex());
       // Update all the models
       std::vector< Model* >::iterator miter;
       for (miter=this->models.begin(); miter!=this->models.end(); miter++)
@@ -516,7 +505,7 @@
 // Add a new entity to the world
 void World::InsertEntity( std::string xmlString)
 {
-  boost::recursive_mutex::scoped_lock lock(*Simulator::Instance()->GetMutex());
+  //boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetMRMutex());
   this->toLoadEntities.push_back( xmlString );
 }
 
@@ -524,7 +513,9 @@
 // Load all the entities that have been queued
 void World::ProcessEntitiesToLoad()
 {
-  boost::recursive_mutex::scoped_lock lock(*Simulator::Instance()->GetMutex());
+  //boost::recursive_mutex::scoped_lock 
pr_lock(*Simulator::Instance()->GetPRMutex());
+  //boost::recursive_mutex::scoped_lock 
cr_lock(*Simulator::Instance()->GetCRMutex());
+  boost::recursive_mutex::scoped_lock 
mr_lock(*Simulator::Instance()->GetMRMutex());
   std::vector< std::string >::iterator iter;
 
   for (iter = this->toLoadEntities.begin(); 

Modified: code/gazebo/branches/threads/server/rendering/OgreCreator.cc
===================================================================
--- code/gazebo/branches/threads/server/rendering/OgreCreator.cc        
2009-05-26 18:13:32 UTC (rev 7723)
+++ code/gazebo/branches/threads/server/rendering/OgreCreator.cc        
2009-05-27 02:54:33 UTC (rev 7724)
@@ -756,7 +756,7 @@
   }
 
   {
-    boost::recursive_mutex::scoped_lock 
lock(*Simulator::Instance()->GetMutex());
+    boost::recursive_mutex::scoped_lock 
mr_lock(*Simulator::Instance()->GetMRMutex());
 
     // Update the visuals
     for (viter = this->visuals.begin(); viter != this->visuals.end(); viter++)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to