X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=nodestack.cc;h=2e170b9f35eb8e424db6949754bb32d8146a0ba2;hb=7f6d1166c41b6b00405eb8cd00d3adda5440f386;hp=5c5447595ebb09ee5b58f0e667f5e038e95ead57;hpb=637cffd1718142edc63a984ab9818a6eadc54e4b;p=model-checker.git diff --git a/nodestack.cc b/nodestack.cc index 5c54475..2e170b9 100644 --- a/nodestack.cc +++ b/nodestack.cc @@ -17,7 +17,7 @@ * @param nthreads The number of threads which exist at this point in the * execution trace. */ -Node::Node(ModelAction *act, Node *par, int nthreads) +Node::Node(ModelAction *act, Node *par, int nthreads, bool *enabled) : action(act), parent(par), num_threads(nthreads), @@ -31,6 +31,12 @@ Node::Node(ModelAction *act, Node *par, int nthreads) { if (act) act->set_node(this); + enabled_array=(bool *)MYMALLOC(sizeof(bool)*num_threads); + if (enabled) + memcpy(enabled_array, enabled, sizeof(bool)*num_threads); + else + for(int i=0;i= promises.size()) - promises.resize(i + 1, 0); - promises[i] = 1; + promises.resize(i + 1, PROMISE_IGNORE); + if (promises[i] == PROMISE_IGNORE) + promises[i] = PROMISE_UNFULFILLED; } /** @@ -72,7 +80,7 @@ void Node::set_promise(unsigned int i) { * @return true if the promise should be satisfied by the given model action. */ bool Node::get_promise(unsigned int i) { - return (i < promises.size()) && (promises[i] == 2); + return (i < promises.size()) && (promises[i] == PROMISE_FULFILLED); } /** @@ -81,12 +89,12 @@ bool Node::get_promise(unsigned int i) { */ bool Node::increment_promise() { for (unsigned int i = 0; i < promises.size(); i++) { - if (promises[i] == 1) { - promises[i] = 2; + if (promises[i] == PROMISE_UNFULFILLED) { + promises[i] = PROMISE_FULFILLED; while (i > 0) { i--; - if (promises[i] == 2) - promises[i] = 1; + if (promises[i] == PROMISE_FULFILLED) + promises[i] = PROMISE_UNFULFILLED; } return true; } @@ -100,7 +108,7 @@ bool Node::increment_promise() { */ bool Node::promise_empty() { for (unsigned int i = 0; i < promises.size();i++) - if (promises[i] == 1) + if (promises[i] == PROMISE_UNFULFILLED) return false; return true; } @@ -109,12 +117,24 @@ bool Node::promise_empty() { * Adds a value from a weakly ordered future write to backtrack to. * @param value is the value to backtrack to. */ -bool Node::add_future_value(uint64_t value) { - for (unsigned int i = 0; i < future_values.size(); i++) - if (future_values[i] == value) - return false; +bool Node::add_future_value(uint64_t value, modelclock_t expiration) { + int suitableindex=-1; + for (unsigned int i = 0; i < future_values.size(); i++) { + if (future_values[i].value == value) { + if (future_values[i].expiration>=expiration) + return false; + if (future_index < i) { + suitableindex=i; + } + } + } - future_values.push_back(value); + if (suitableindex!=-1) { + future_values[suitableindex].expiration=expiration; + return true; + } + struct future_value newfv={value, expiration}; + future_values.push_back(newfv); return true; } @@ -199,7 +219,8 @@ thread_id_t Node::get_next_backtrack() bool Node::is_enabled(Thread *t) { - return id_to_int(t->get_id()) < num_threads; + int thread_id=id_to_int(t->get_id()); + return thread_id < num_threads && enabled_array[thread_id]; } /** @@ -218,7 +239,21 @@ void Node::add_read_from(const ModelAction *act) */ uint64_t Node::get_future_value() { ASSERT(future_index