本文整理汇总了C++中NodeValue::decrRefCounts方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeValue::decrRefCounts方法的具体用法?C++ NodeValue::decrRefCounts怎么用?C++ NodeValue::decrRefCounts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeValue
的用法示例。
在下文中一共展示了NodeValue::decrRefCounts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reclaimZombies
void NodeManager::reclaimZombies() {
// FIXME multithreading
Assert(!d_attrManager->inGarbageCollection());
Debug("gc") << "reclaiming " << d_zombies.size() << " zombie(s)!\n";
// during reclamation, reclaimZombies() is never supposed to be called
Assert(! d_inReclaimZombies, "NodeManager::reclaimZombies() not re-entrant!");
// whether exit is normal or exceptional, the Reclaim dtor is called
// and ensures that d_inReclaimZombies is set back to false.
ScopedBool r(d_inReclaimZombies);
// We copy the set away and clear the NodeManager's set of zombies.
// This is because reclaimZombie() decrements the RC of the
// NodeValue's children, which may (recursively) reclaim them.
//
// Let's say we're reclaiming zombie NodeValue "A" and its child "B"
// then becomes a zombie (NodeManager::markForDeletion(B) is called).
//
// One way to handle B's zombification would be simply to put it
// into d_zombies. This is what we do. However, if we were to
// concurrently process d_zombies in the loop below, such addition
// may be invisible to us (B is leaked) or even invalidate our
// iterator, causing a crash. So we need to copy the set away.
vector<NodeValue*> zombies;
zombies.reserve(d_zombies.size());
remove_copy_if(d_zombies.begin(),
d_zombies.end(),
back_inserter(zombies),
NodeValueReferenceCountNonZero());
d_zombies.clear();
#ifdef _LIBCPP_VERSION
NodeValue* last = NULL;
#endif
for(vector<NodeValue*>::iterator i = zombies.begin();
i != zombies.end();
++i) {
NodeValue* nv = *i;
#ifdef _LIBCPP_VERSION
// Work around an apparent bug in libc++'s hash_set<> which can
// (very occasionally) have an element repeated.
if(nv == last) {
continue;
}
last = nv;
#endif
// collect ONLY IF still zero
if(nv->d_rc == 0) {
if(Debug.isOn("gc")) {
Debug("gc") << "deleting node value " << nv
<< " [" << nv->d_id << "]: ";
nv->printAst(Debug("gc"));
Debug("gc") << endl;
}
// remove from the pool
kind::MetaKind mk = nv->getMetaKind();
if(mk != kind::metakind::VARIABLE) {
poolRemove(nv);
}
// whether exit is normal or exceptional, the NVReclaim dtor is
// called and ensures that d_nodeUnderDeletion is set back to
// NULL.
NVReclaim rc(d_nodeUnderDeletion);
d_nodeUnderDeletion = nv;
// remove attributes
{ // notify listeners of deleted node
TNode n;
n.d_nv = nv;
nv->d_rc = 1; // so that TNode doesn't assert-fail
for(vector<NodeManagerListener*>::iterator i = d_listeners.begin(); i != d_listeners.end(); ++i) {
(*i)->nmNotifyDeleteNode(n);
}
// this would mean that one of the listeners stowed away
// a reference to this node!
Assert(nv->d_rc == 1);
}
nv->d_rc = 0;
d_attrManager->deleteAllAttributes(nv);
// decr ref counts of children
nv->decrRefCounts();
if(mk == kind::metakind::CONSTANT) {
// Destroy (call the destructor for) the C++ type representing
// the constant in this NodeValue. This is needed for
// e.g. CVC4::Rational, since it has a gmp internal
// representation that mallocs memory and should be cleaned
// up. (This won't delete a pointer value if used as a
// constant, but then, you should probably use a smart-pointer
// type for a constant payload.)
kind::metakind::deleteNodeValueConstant(nv);
}
free(nv);
}
//.........这里部分代码省略.........