From: Brian Norris Date: Fri, 4 May 2012 06:30:28 +0000 (-0700) Subject: tree: add is_enabled(Thread *) X-Git-Tag: pldi2013~457 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=efd0e6cfa2827dfec2cf5932c02f9c6559389f4d;p=model-checker.git tree: add is_enabled(Thread *) Determine "enabled" by: was the thread created at this point. Checking against num_threads is a naive way to do this... --- diff --git a/tree.cc b/tree.cc index 57e0c13..c161ca8 100644 --- a/tree.cc +++ b/tree.cc @@ -7,6 +7,13 @@ TreeNode::TreeNode(TreeNode *par, ModelAction *act) { TreeNode::totalNodes++; this->parent = par; + if (!parent) { + num_threads = 1; + } else { + num_threads = parent->num_threads; + if (act && act->get_type() == THREAD_CREATE) + num_threads++; + } } TreeNode::~TreeNode() { @@ -57,3 +64,8 @@ TreeNode * TreeNode::getRoot() return parent->getRoot(); return this; } + +bool TreeNode::is_enabled(Thread *t) +{ + return id_to_int(t->get_id()) < num_threads; +} diff --git a/tree.h b/tree.h index 1752d3f..d45fd83 100644 --- a/tree.h +++ b/tree.h @@ -25,11 +25,14 @@ public: int setBacktrack(thread_id_t id); TreeNode * getRoot(); static int getTotalNodes() { return TreeNode::totalNodes; } + + bool is_enabled(Thread *t); private: TreeNode *parent; std::map children; std::set backtrack; static int totalNodes; + int num_threads; }; #endif /* __TREE_H__ */