Browse Source

make thread-safe

David Rose 18 years ago
parent
commit
89f4ff426b

+ 1 - 4
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();
   }
 }

+ 15 - 0
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

+ 3 - 0
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();