Fix the race!
parent
99c01c4dba
commit
027a4a5a8e
|
@ -15,6 +15,10 @@
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
#include <gtsam/base/treeTraversal-inst.h>
|
#include <gtsam/base/treeTraversal-inst.h>
|
||||||
|
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
#include <mutex>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -120,20 +124,39 @@ struct EliminationData {
|
||||||
size_t myIndexInParent;
|
size_t myIndexInParent;
|
||||||
FastVector<sharedFactor> childFactors;
|
FastVector<sharedFactor> childFactors;
|
||||||
boost::shared_ptr<BTNode> bayesTreeNode;
|
boost::shared_ptr<BTNode> bayesTreeNode;
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
boost::shared_ptr<std::mutex> writeLock;
|
||||||
|
#endif
|
||||||
|
|
||||||
EliminationData(EliminationData* _parentData, size_t nChildren) :
|
EliminationData(EliminationData* _parentData, size_t nChildren) :
|
||||||
parentData(_parentData), bayesTreeNode(boost::make_shared<BTNode>()) {
|
parentData(_parentData), bayesTreeNode(boost::make_shared<BTNode>())
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
, writeLock(boost::make_shared<std::mutex>())
|
||||||
|
#endif
|
||||||
|
{
|
||||||
if (parentData) {
|
if (parentData) {
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
parentData->writeLock->lock();
|
||||||
|
#endif
|
||||||
myIndexInParent = parentData->childFactors.size();
|
myIndexInParent = parentData->childFactors.size();
|
||||||
parentData->childFactors.push_back(sharedFactor());
|
parentData->childFactors.push_back(sharedFactor());
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
parentData->writeLock->unlock();
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
myIndexInParent = 0;
|
myIndexInParent = 0;
|
||||||
}
|
}
|
||||||
// Set up BayesTree parent and child pointers
|
// Set up BayesTree parent and child pointers
|
||||||
if (parentData) {
|
if (parentData) {
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
parentData->writeLock->lock();
|
||||||
|
#endif
|
||||||
if (parentData->parentData) // If our parent is not the dummy node
|
if (parentData->parentData) // If our parent is not the dummy node
|
||||||
bayesTreeNode->parent_ = parentData->bayesTreeNode;
|
bayesTreeNode->parent_ = parentData->bayesTreeNode;
|
||||||
parentData->bayesTreeNode->children.push_back(bayesTreeNode);
|
parentData->bayesTreeNode->children.push_back(bayesTreeNode);
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
parentData->writeLock->unlock();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,8 +219,15 @@ struct EliminationData {
|
||||||
nodesIndex_.insert(std::make_pair(j, myData.bayesTreeNode));
|
nodesIndex_.insert(std::make_pair(j, myData.bayesTreeNode));
|
||||||
|
|
||||||
// Store remaining factor in parent's gathered factors
|
// Store remaining factor in parent's gathered factors
|
||||||
if (!eliminationResult.second->empty())
|
if (!eliminationResult.second->empty()) {
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
myData.parentData->writeLock->lock();
|
||||||
|
#endif
|
||||||
myData.parentData->childFactors[myData.myIndexInParent] = eliminationResult.second;
|
myData.parentData->childFactors[myData.myIndexInParent] = eliminationResult.second;
|
||||||
|
#ifdef GTSAM_USE_TBB
|
||||||
|
myData.parentData->writeLock->unlock();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue