diff --git a/gtsam/base/debug.cpp b/gtsam/base/debug.cpp index dbea53c7c..592b42d15 100644 --- a/gtsam/base/debug.cpp +++ b/gtsam/base/debug.cpp @@ -19,23 +19,31 @@ #include #include // for GTSAM_USE_TBB +#ifdef GTSAM_USE_TBB #include // std::mutex, std::unique_lock +#endif namespace gtsam { GTSAM_EXPORT FastMap > debugFlags; +#ifdef GTSAM_USE_TBB std::mutex debugFlagsMutex; +#endif /* ************************************************************************* */ bool guardedIsDebug(const std::string& s) { +#ifdef GTSAM_USE_TBB std::unique_lock lock(debugFlagsMutex); +#endif return gtsam::debugFlags[s]; } /* ************************************************************************* */ void guardedSetDebug(const std::string& s, const bool v) { +#ifdef GTSAM_USE_TBB std::unique_lock lock(debugFlagsMutex); +#endif gtsam::debugFlags[s] = v; } diff --git a/gtsam/geometry/Unit3.cpp b/gtsam/geometry/Unit3.cpp index 655b94fc3..f33e08a83 100644 --- a/gtsam/geometry/Unit3.cpp +++ b/gtsam/geometry/Unit3.cpp @@ -80,10 +80,12 @@ static Point3 CalculateBestAxis(const Point3& n) { /* ************************************************************************* */ const Matrix32& Unit3::basis(OptionalJacobian<6, 2> H) const { +#ifdef GTSAM_USE_TBB // NOTE(hayk): At some point it seemed like this reproducably resulted in // deadlock. However, I don't know why and I can no longer reproduce it. // It either was a red herring or there is still a latent bug left to debug. std::unique_lock lock(B_mutex_); +#endif const bool cachedBasis = static_cast(B_); const bool cachedJacobian = static_cast(H_B_); diff --git a/gtsam/geometry/Unit3.h b/gtsam/geometry/Unit3.h index 0a43ce59b..a4043be85 100644 --- a/gtsam/geometry/Unit3.h +++ b/gtsam/geometry/Unit3.h @@ -32,7 +32,9 @@ #include +#ifdef GTSAM_USE_TBB #include // std::mutex +#endif namespace gtsam { @@ -45,7 +47,9 @@ private: mutable boost::optional B_; ///< Cached basis mutable boost::optional H_B_; ///< Cached basis derivative +#ifdef GTSAM_USE_TBB mutable std::mutex B_mutex_; ///< Mutex to protect the cached basis. +#endif public: