change from deprecated tbb::mutex to std::mutex

release/4.3a0
acxz 2020-01-11 13:09:16 -05:00
parent 98a90221cc
commit eb85762483
3 changed files with 7 additions and 21 deletions

View File

@ -19,31 +19,23 @@
#include <gtsam/base/debug.h> #include <gtsam/base/debug.h>
#include <gtsam/config.h> // for GTSAM_USE_TBB #include <gtsam/config.h> // for GTSAM_USE_TBB
#ifdef GTSAM_USE_TBB #include <mutex> // std::mutex, std::unique_lock
#include <tbb/mutex.h>
#endif
namespace gtsam { namespace gtsam {
GTSAM_EXPORT FastMap<std::string, ValueWithDefault<bool, false> > debugFlags; GTSAM_EXPORT FastMap<std::string, ValueWithDefault<bool, false> > debugFlags;
#ifdef GTSAM_USE_TBB std::mutex debugFlagsMutex;
tbb::mutex debugFlagsMutex;
#endif
/* ************************************************************************* */ /* ************************************************************************* */
bool guardedIsDebug(const std::string& s) { bool guardedIsDebug(const std::string& s) {
#ifdef GTSAM_USE_TBB std::unique_lock<std::mutex> lock(debugFlagsMutex);
tbb::mutex::scoped_lock lock(debugFlagsMutex);
#endif
return gtsam::debugFlags[s]; return gtsam::debugFlags[s];
} }
/* ************************************************************************* */ /* ************************************************************************* */
void guardedSetDebug(const std::string& s, const bool v) { void guardedSetDebug(const std::string& s, const bool v) {
#ifdef GTSAM_USE_TBB std::unique_lock<std::mutex> lock(debugFlagsMutex);
tbb::mutex::scoped_lock lock(debugFlagsMutex);
#endif
gtsam::debugFlags[s] = v; gtsam::debugFlags[s] = v;
} }

View File

@ -80,12 +80,10 @@ static Point3 CalculateBestAxis(const Point3& n) {
/* ************************************************************************* */ /* ************************************************************************* */
const Matrix32& Unit3::basis(OptionalJacobian<6, 2> H) const { 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 // 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. // 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. // It either was a red herring or there is still a latent bug left to debug.
tbb::mutex::scoped_lock lock(B_mutex_); std::unique_lock<std::mutex> lock(B_mutex_);
#endif
const bool cachedBasis = static_cast<bool>(B_); const bool cachedBasis = static_cast<bool>(B_);
const bool cachedJacobian = static_cast<bool>(H_B_); const bool cachedJacobian = static_cast<bool>(H_B_);

View File

@ -32,9 +32,7 @@
#include <string> #include <string>
#ifdef GTSAM_USE_TBB #include <mutex> // std::mutex
#include <tbb/mutex.h>
#endif
namespace gtsam { namespace gtsam {
@ -47,9 +45,7 @@ private:
mutable boost::optional<Matrix32> B_; ///< Cached basis mutable boost::optional<Matrix32> B_; ///< Cached basis
mutable boost::optional<Matrix62> H_B_; ///< Cached basis derivative mutable boost::optional<Matrix62> H_B_; ///< Cached basis derivative
#ifdef GTSAM_USE_TBB mutable std::mutex B_mutex_; ///< Mutex to protect the cached basis.
mutable tbb::mutex B_mutex_; ///< Mutex to protect the cached basis.
#endif
public: public: