From 89f4ff426baaa2ba39eab07ca327bb7c250a72bb Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 27 Nov 2007 01:12:50 +0000 Subject: [PATCH] make thread-safe --- panda/src/char/jointVertexTransform.I | 5 +---- panda/src/char/jointVertexTransform.cxx | 15 +++++++++++++++ panda/src/char/jointVertexTransform.h | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/panda/src/char/jointVertexTransform.I b/panda/src/char/jointVertexTransform.I index 2560ae6056..93d6e486ba 100644 --- a/panda/src/char/jointVertexTransform.I +++ b/panda/src/char/jointVertexTransform.I @@ -36,9 +36,6 @@ get_joint() const { INLINE void JointVertexTransform:: check_matrix() const { if (_matrix_stale) { - ((JointVertexTransform *)this)->_matrix = - _joint->_initial_net_transform_inverse * - _joint->_net_transform; - ((JointVertexTransform *)this)->_matrix_stale = false; + ((JointVertexTransform *)this)->compute_matrix(); } } diff --git a/panda/src/char/jointVertexTransform.cxx b/panda/src/char/jointVertexTransform.cxx index 5016dbd197..97f95d6527 100644 --- a/panda/src/char/jointVertexTransform.cxx +++ b/panda/src/char/jointVertexTransform.cxx @@ -21,6 +21,7 @@ #include "datagramIterator.h" #include "bamReader.h" #include "bamWriter.h" +#include "mutexHolder.h" TypeHandle JointVertexTransform::_type_handle; @@ -133,6 +134,20 @@ output(ostream &out) const { out << _joint->get_name(); } +//////////////////////////////////////////////////////////////////// +// Function: JointVertexTransform::compute_matrix +// Access: Private +// Description: Recomputes _matrix if it needs it. Uses locking. +//////////////////////////////////////////////////////////////////// +void JointVertexTransform:: +compute_matrix() { + MutexHolder holder(_lock); + if (_matrix_stale) { + _matrix = _joint->_initial_net_transform_inverse * _joint->_net_transform; + _matrix_stale = false; + } +} + //////////////////////////////////////////////////////////////////// // Function: JointVertexTransform::register_with_read_factory diff --git a/panda/src/char/jointVertexTransform.h b/panda/src/char/jointVertexTransform.h index f6c26df664..e33b5026eb 100644 --- a/panda/src/char/jointVertexTransform.h +++ b/panda/src/char/jointVertexTransform.h @@ -23,6 +23,7 @@ #include "characterJoint.h" #include "vertexTransform.h" #include "pointerTo.h" +#include "pmutex.h" //////////////////////////////////////////////////////////////////// // Class : JointVertexTransform @@ -56,11 +57,13 @@ PUBLISHED: private: INLINE void check_matrix() const; + void compute_matrix(); PT(CharacterJoint) _joint; LMatrix4f _matrix; bool _matrix_stale; + Mutex _lock; public: static void register_with_read_factory();