An attempt to fix exception passing in TBB on Mac
parent
95f8b3bf2e
commit
609ed8f09e
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#ifdef GTSAM_USE_TBB
|
#ifdef GTSAM_USE_TBB
|
||||||
#include <tbb/tbb_exception.h>
|
#include <tbb/tbb_exception.h>
|
||||||
|
#include <tbb/scalable_allocator.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
@ -148,16 +149,21 @@ namespace gtsam {
|
||||||
public std::exception
|
public std::exception
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
#ifdef GTSAM_USE_TBB
|
#ifdef GTSAM_USE_TBB
|
||||||
|
private:
|
||||||
typedef tbb::tbb_exception Base;
|
typedef tbb::tbb_exception Base;
|
||||||
|
protected:
|
||||||
|
typedef std::basic_string<char, std::char_traits<char>, tbb::tbb_allocator<char> > String;
|
||||||
#else
|
#else
|
||||||
|
private:
|
||||||
typedef std::exception Base;
|
typedef std::exception Base;
|
||||||
|
protected:
|
||||||
|
typedef std::string String;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool dynamic_; ///< Whether this object was moved
|
bool dynamic_; ///< Whether this object was moved
|
||||||
boost::optional<std::string> description_; ///< Optional description
|
mutable boost::optional<String> description_; ///< Optional description
|
||||||
|
|
||||||
/// Default constructor is protected - may only be created from derived classes
|
/// Default constructor is protected - may only be created from derived classes
|
||||||
ThreadsafeException() : dynamic_(false) {}
|
ThreadsafeException() : dynamic_(false) {}
|
||||||
|
|
@ -166,7 +172,7 @@ namespace gtsam {
|
||||||
ThreadsafeException(const ThreadsafeException& other) : Base(other), dynamic_(false) {}
|
ThreadsafeException(const ThreadsafeException& other) : Base(other), dynamic_(false) {}
|
||||||
|
|
||||||
/// Construct with description string
|
/// Construct with description string
|
||||||
ThreadsafeException(const std::string& description) : dynamic_(false), description_(description) {}
|
ThreadsafeException(const std::string& description) : dynamic_(false), description_(String(description.begin(), description.end())) {}
|
||||||
|
|
||||||
/// Default destructor doesn't have the throw()
|
/// Default destructor doesn't have the throw()
|
||||||
virtual ~ThreadsafeException() throw () {}
|
virtual ~ThreadsafeException() throw () {}
|
||||||
|
|
@ -175,14 +181,22 @@ namespace gtsam {
|
||||||
// Implement functions for tbb_exception
|
// Implement functions for tbb_exception
|
||||||
#ifdef GTSAM_USE_TBB
|
#ifdef GTSAM_USE_TBB
|
||||||
virtual tbb::tbb_exception* move() throw () {
|
virtual tbb::tbb_exception* move() throw () {
|
||||||
DERIVED* clone = ::new DERIVED(static_cast<DERIVED&>(*this));
|
void* cloneMemory = scalable_malloc(sizeof(DERIVED));
|
||||||
|
if (!cloneMemory) {
|
||||||
|
std::cerr << "Failed allocating memory to copy thrown exception, exiting now." << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
DERIVED* clone = ::new(cloneMemory) DERIVED(static_cast<DERIVED&>(*this));
|
||||||
clone->dynamic_ = true;
|
clone->dynamic_ = true;
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void destroy() throw() {
|
virtual void destroy() throw() {
|
||||||
if (dynamic_)
|
if (dynamic_) {
|
||||||
::delete this;
|
DERIVED* derivedPtr = static_cast<DERIVED*>(this);
|
||||||
|
derivedPtr->~DERIVED();
|
||||||
|
scalable_free(derivedPtr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void throw_self() {
|
virtual void throw_self() {
|
||||||
|
|
|
||||||
|
|
@ -94,23 +94,22 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
class IndeterminantLinearSystemException : public ThreadsafeException<IndeterminantLinearSystemException> {
|
class IndeterminantLinearSystemException : public ThreadsafeException<IndeterminantLinearSystemException> {
|
||||||
Index j_;
|
Index j_;
|
||||||
mutable std::string what_;
|
|
||||||
public:
|
public:
|
||||||
IndeterminantLinearSystemException(Index j) throw() : j_(j) {}
|
IndeterminantLinearSystemException(Index j) throw() : j_(j) {}
|
||||||
virtual ~IndeterminantLinearSystemException() throw() {}
|
virtual ~IndeterminantLinearSystemException() throw() {}
|
||||||
Index nearbyVariable() const { return j_; }
|
Index nearbyVariable() const { return j_; }
|
||||||
virtual const char* what() const throw() {
|
virtual const char* what() const throw() {
|
||||||
if(what_.empty())
|
if(!description_)
|
||||||
what_ =
|
description_ = String(
|
||||||
"\nIndeterminant linear system detected while working near variable with\n"
|
"\nIndeterminant linear system detected while working near variable with\n"
|
||||||
"index " + boost::lexical_cast<std::string>(j_) + " in ordering.\n"
|
"index " + boost::lexical_cast<String>(j_) + " in ordering.\n"
|
||||||
"\n\
|
"\n\
|
||||||
Thrown when a linear system is ill-posed. The most common cause for this\n\
|
Thrown when a linear system is ill-posed. The most common cause for this\n\
|
||||||
error is having underconstrained variables. Mathematically, the system is\n\
|
error is having underconstrained variables. Mathematically, the system is\n\
|
||||||
either underdetermined, or its quadratic error function is concave in some\n\
|
either underdetermined, or its quadratic error function is concave in some\n\
|
||||||
directions. See the GTSAM Doxygen documentation at http://borg.cc.gatech.edu/ \n\
|
directions. See the GTSAM Doxygen documentation at http://borg.cc.gatech.edu/ \n\
|
||||||
on gtsam::IndeterminantLinearSystemException for more information.\n";
|
on gtsam::IndeterminantLinearSystemException for more information.\n");
|
||||||
return what_.c_str();
|
return description_->c_str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue