From 6a82594a4f50463fe9254dc6060fbb9aa4cf8562 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 8 Feb 2016 20:09:32 -0800 Subject: [PATCH] SpatiallyNestable: more locks, less contention --- libraries/shared/src/SpatiallyNestable.cpp | 16 ++++++++-------- libraries/shared/src/SpatiallyNestable.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 3db714964f..48238977d1 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -395,7 +395,7 @@ glm::vec3 SpatiallyNestable::getVelocity(bool& success) const { glm::vec3 parentVelocity = getParentVelocity(success); Transform parentTransform = getParentTransform(success); glm::vec3 result; - _transformLock.withReadLock([&] { + _velocityLock.withReadLock([&] { // TODO: take parent angularVelocity into account. result = parentVelocity + parentTransform.getRotation() * _velocity; }); @@ -410,7 +410,7 @@ glm::vec3 SpatiallyNestable::getVelocity() const { void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { glm::vec3 parentVelocity = getParentVelocity(success); Transform parentTransform = getParentTransform(success); - _transformLock.withWriteLock([&] { + _velocityLock.withWriteLock([&] { // TODO: take parent angularVelocity into account. _velocity = glm::inverse(parentTransform.getRotation()) * velocity - parentVelocity; }); @@ -434,7 +434,7 @@ glm::vec3 SpatiallyNestable::getAngularVelocity(bool& success) const { glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); Transform parentTransform = getParentTransform(success); glm::vec3 result; - _transformLock.withReadLock([&] { + _angularVelocityLock.withReadLock([&] { result = parentAngularVelocity + parentTransform.getRotation() * _angularVelocity; }); return result; @@ -448,7 +448,7 @@ glm::vec3 SpatiallyNestable::getAngularVelocity() const { void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity, bool& success) { glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); Transform parentTransform = getParentTransform(success); - _transformLock.withWriteLock([&] { + _angularVelocityLock.withWriteLock([&] { _angularVelocity = glm::inverse(parentTransform.getRotation()) * angularVelocity - parentAngularVelocity; }); } @@ -592,28 +592,28 @@ void SpatiallyNestable::setLocalOrientation(const glm::quat& orientation) { glm::vec3 SpatiallyNestable::getLocalVelocity() const { glm::vec3 result(glm::vec3::_null); - _transformLock.withReadLock([&] { + _velocityLock.withReadLock([&] { result = _velocity; }); return result; } void SpatiallyNestable::setLocalVelocity(const glm::vec3& velocity) { - _transformLock.withWriteLock([&] { + _velocityLock.withWriteLock([&] { _velocity = velocity; }); } glm::vec3 SpatiallyNestable::getLocalAngularVelocity() const { glm::vec3 result(glm::vec3::_null); - _transformLock.withReadLock([&] { + _angularVelocityLock.withReadLock([&] { result = _angularVelocity; }); return result; } void SpatiallyNestable::setLocalAngularVelocity(const glm::vec3& angularVelocity) { - _transformLock.withWriteLock([&] { + _angularVelocityLock.withWriteLock([&] { _angularVelocity = angularVelocity; }); } diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index a4f4691c40..0c43aff20d 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -165,6 +165,8 @@ protected: private: mutable ReadWriteLockable _transformLock; mutable ReadWriteLockable _idLock; + mutable ReadWriteLockable _velocityLock; + mutable ReadWriteLockable _angularVelocityLock; Transform _transform; // this is to be combined with parent's world-transform to produce this' world-transform. glm::vec3 _velocity; glm::vec3 _angularVelocity;