add TBB guards back for multithread option and potentially breaking changes

release/4.3a0
acxz 2020-01-11 15:11:50 -05:00
parent b2e9331161
commit 1483df7aa0
3 changed files with 14 additions and 0 deletions

View File

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

View File

@ -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<std::mutex> lock(B_mutex_);
#endif
const bool cachedBasis = static_cast<bool>(B_);
const bool cachedJacobian = static_cast<bool>(H_B_);

View File

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