make thread-safe

This commit is contained in:
David Rose 2007-11-27 01:12:50 +00:00
parent b990681b1a
commit 89f4ff426b
3 changed files with 19 additions and 4 deletions

View File

@ -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();
}
}

View File

@ -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

View File

@ -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();