An attempt to fix exception passing in TBB on Mac
parent
95f8b3bf2e
commit
609ed8f09e
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifdef GTSAM_USE_TBB
|
||||
#include <tbb/tbb_exception.h>
|
||||
#include <tbb/scalable_allocator.h>
|
||||
#endif
|
||||
|
||||
namespace gtsam {
|
||||
|
|
@ -148,16 +149,21 @@ namespace gtsam {
|
|||
public std::exception
|
||||
#endif
|
||||
{
|
||||
private:
|
||||
#ifdef GTSAM_USE_TBB
|
||||
private:
|
||||
typedef tbb::tbb_exception Base;
|
||||
protected:
|
||||
typedef std::basic_string<char, std::char_traits<char>, tbb::tbb_allocator<char> > String;
|
||||
#else
|
||||
private:
|
||||
typedef std::exception Base;
|
||||
protected:
|
||||
typedef std::string String;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
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
|
||||
ThreadsafeException() : dynamic_(false) {}
|
||||
|
|
@ -166,7 +172,7 @@ namespace gtsam {
|
|||
ThreadsafeException(const ThreadsafeException& other) : Base(other), dynamic_(false) {}
|
||||
|
||||
/// 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()
|
||||
virtual ~ThreadsafeException() throw () {}
|
||||
|
|
@ -175,14 +181,22 @@ namespace gtsam {
|
|||
// Implement functions for tbb_exception
|
||||
#ifdef GTSAM_USE_TBB
|
||||
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;
|
||||
return clone;
|
||||
}
|
||||
|
||||
virtual void destroy() throw() {
|
||||
if (dynamic_)
|
||||
::delete this;
|
||||
if (dynamic_) {
|
||||
DERIVED* derivedPtr = static_cast<DERIVED*>(this);
|
||||
derivedPtr->~DERIVED();
|
||||
scalable_free(derivedPtr);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void throw_self() {
|
||||
|
|
|
|||
|
|
@ -94,23 +94,22 @@ namespace gtsam {
|
|||
*/
|
||||
class IndeterminantLinearSystemException : public ThreadsafeException<IndeterminantLinearSystemException> {
|
||||
Index j_;
|
||||
mutable std::string what_;
|
||||
public:
|
||||
IndeterminantLinearSystemException(Index j) throw() : j_(j) {}
|
||||
virtual ~IndeterminantLinearSystemException() throw() {}
|
||||
Index nearbyVariable() const { return j_; }
|
||||
virtual const char* what() const throw() {
|
||||
if(what_.empty())
|
||||
what_ =
|
||||
if(!description_)
|
||||
description_ = String(
|
||||
"\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\
|
||||
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\
|
||||
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\
|
||||
on gtsam::IndeterminantLinearSystemException for more information.\n";
|
||||
return what_.c_str();
|
||||
on gtsam::IndeterminantLinearSystemException for more information.\n");
|
||||
return description_->c_str();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue