From c8cf14d4b9a92b40f9c08df2e329f0f7bfd05b7c Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 11 Jul 2015 20:00:56 -0700 Subject: [PATCH] Moved mutex around smaller block --- gtsam/geometry/Unit3.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gtsam/geometry/Unit3.cpp b/gtsam/geometry/Unit3.cpp index a4153643e..aad128816 100644 --- a/gtsam/geometry/Unit3.cpp +++ b/gtsam/geometry/Unit3.cpp @@ -69,18 +69,13 @@ Unit3 Unit3::Random(boost::mt19937 & rng) { } #ifdef GTSAM_USE_TBB -tbb::mutex unit3BasisMutex; +static tbb::mutex unit3BasisMutex; #endif /* ************************************************************************* */ const Matrix32& Unit3::basis() const { -#ifdef GTSAM_USE_TBB - tbb::mutex::scoped_lock lock(unit3BasisMutex); -#endif - // Return cached version if exists - if (B_) - return *B_; + if (B_) return *B_; // Get the axis of rotation with the minimum projected length of the point Vector3 axis; @@ -99,8 +94,13 @@ const Matrix32& Unit3::basis() const { Vector3 b2 = p_.cross(b1).normalized(); // Create the basis matrix - B_.reset(Matrix32()); - (*B_) << b1, b2; + { +#ifdef GTSAM_USE_TBB + tbb::mutex::scoped_lock lock(unit3BasisMutex); +#endif + B_.reset(Matrix32()); + (*B_) << b1, b2; + } return *B_; }