Revision: 7736
http://playerstage.svn.sourceforge.net/playerstage/?rev=7736&view=rev
Author: hsujohnhsu
Date: 2009-05-29 00:13:51 +0000 (Fri, 29 May 2009)
Log Message:
-----------
threading cleanup.
Modified Paths:
--------------
code/gazebo/branches/threads/server/Simulator.cc
code/gazebo/branches/threads/server/Simulator.hh
code/gazebo/branches/threads/server/World.cc
Modified: code/gazebo/branches/threads/server/Simulator.cc
===================================================================
--- code/gazebo/branches/threads/server/Simulator.cc 2009-05-28 23:50:41 UTC
(rev 7735)
+++ code/gazebo/branches/threads/server/Simulator.cc 2009-05-29 00:13:51 UTC
(rev 7736)
@@ -77,8 +77,6 @@
selectedEntity(NULL),
selectedBody(NULL)
{
- 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();
@@ -106,18 +104,6 @@
this->xmlFile = NULL;
}
- if (this->pr_mutex)
- {
- 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;
@@ -752,7 +738,6 @@
// lock mutex and update physics
{
- //boost::recursive_mutex::scoped_lock lock(*this->pr_mutex);
world->UpdatePhysics();
}
@@ -786,42 +771,28 @@
////////////////////////////////////////////////////////////////////////////////
/// 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::GetPRMutex()
-{
- return this->pr_mutex;
-}
-
-////////////////////////////////////////////////////////////////////////////////
/// Mutex
-boost::mutex* Simulator::GetC()
+boost::mutex* Simulator::GetCMutex()
{
return this->c_mutex;
}
////////////////////////////////////////////////////////////////////////////////
/// Mutex
-boost::mutex* Simulator::GetP()
+boost::mutex* Simulator::GetPMutex()
{
return this->p_mutex;
}
////////////////////////////////////////////////////////////////////////////////
/// Mutex
-boost::mutex* Simulator::GetM()
+boost::mutex* Simulator::GetMMutex()
{
return this->m_mutex;
}
Modified: code/gazebo/branches/threads/server/Simulator.hh
===================================================================
--- code/gazebo/branches/threads/server/Simulator.hh 2009-05-28 23:50:41 UTC
(rev 7735)
+++ code/gazebo/branches/threads/server/Simulator.hh 2009-05-29 00:13:51 UTC
(rev 7736)
@@ -182,10 +182,8 @@
/// \brief Get the body that contains the entity
public: Body *GetParentBody( Entity *entity ) const;
- /// \brief Get the simulator mutex
- public:boost::recursive_mutex *GetPRMutex();
+ /// \brief Get the simulator mutex (Models update and Rendering)
public:boost::recursive_mutex *GetMRMutex();
- public:boost::recursive_mutex *GetCRMutex();
/// \brief Function to run gui. Used by guiThread
private: void PhysicsLoop();
@@ -253,35 +251,43 @@
private: Entity *selectedEntity;
private: Body *selectedBody;
- /// Thread in which to run the gui
+ /// Thread in which to run physics step (constraint/dynamics solver)
private: boost::thread *physicsThread;
+
+ /// Thread in which to run collision detection
private: boost::thread *collisionsThread;
+
+ /// Thread in which to run models update, this includes rendering updates
and sensor gathering
private: boost::thread *modelsThread;
- // mutex between rendering and (physics,collision,models update)
- private: boost::recursive_mutex *cr_mutex;
- private: boost::recursive_mutex *pr_mutex;
+ // mutex between rendering and models update
private: boost::recursive_mutex *mr_mutex;
+ // ideally, following cycle is repeated
+ // 1. collision and models updates run simultaneously
+ // 2. physics update runs sequentially after step 1. is done
+
// mutex for physics, collisions, models update sequence control
private: boost::mutex *c_mutex;
private: boost::mutex *m_mutex;
private: boost::mutex *p_mutex;
+ // mutex for updating condition_variables
+ public: boost::mutex* GetCMutex();
+ public: boost::mutex* GetPMutex();
+ public: boost::mutex* GetMMutex();
+
+ // conditional variables for sequencing collisions update, models update
and physics update
private: boost::condition_variable *p_cond;
private: boost::condition_variable *c_cond;
private: boost::condition_variable *m_cond;
+ private: bool run_collision;
+ private: bool run_models;
- public: boost::mutex* GetC();
- public: boost::mutex* GetP();
- public: boost::mutex* GetM();
public: boost::condition_variable* GetPCond();
public: boost::condition_variable* GetCCond();
public: boost::condition_variable* GetMCond();
- private: bool run_collision;
- private: bool run_models;
-
public: bool RunCollision();
public: bool RunModels();
public: void CollisionDone();
Modified: code/gazebo/branches/threads/server/World.cc
===================================================================
--- code/gazebo/branches/threads/server/World.cc 2009-05-28 23:50:41 UTC
(rev 7735)
+++ code/gazebo/branches/threads/server/World.cc 2009-05-29 00:13:51 UTC
(rev 7736)
@@ -331,7 +331,7 @@
{
{
- boost::unique_lock<boost::mutex> lock(*simulator->GetC());
+ boost::unique_lock<boost::mutex> lock(*simulator->GetCMutex());
while (!simulator->RunCollision())
{
simulator->GetCCond()->wait(lock);
@@ -345,7 +345,6 @@
if (!Simulator::Instance()->IsPaused() &&
Simulator::Instance()->GetPhysicsEnabled())
{
- //boost::recursive_mutex::scoped_lock
lock(*Simulator::Instance()->GetCRMutex());
this->physicsEngine->UpdateCollision();
}
@@ -356,7 +355,7 @@
// thread control
{
- boost::lock_guard<boost::mutex> p_lock(*simulator->GetP());
+ boost::lock_guard<boost::mutex> p_lock(*simulator->GetPMutex());
simulator->CollisionDone();
}
simulator->GetPCond()->notify_all();
@@ -375,7 +374,7 @@
{
{
- boost::unique_lock<boost::mutex> lock(*simulator->GetM());
+ boost::unique_lock<boost::mutex> lock(*simulator->GetMMutex());
while (!simulator->RunModels())
{
simulator->GetMCond()->wait(lock);
@@ -406,7 +405,7 @@
// thread control
{
- boost::lock_guard<boost::mutex> p_lock(*simulator->GetP());
+ boost::lock_guard<boost::mutex> p_lock(*simulator->GetPMutex());
simulator->ModelsDone();
}
simulator->GetPCond()->notify_all();
@@ -513,8 +512,6 @@
// Load all the entities that have been queued
void World::ProcessEntitiesToLoad()
{
- //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;
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