+
+ if (curr->is_rmwc() || curr->is_rmw()) {
+ ModelAction *tmp = process_rmw(curr);
+ already_added = true;
+ delete curr;
+ curr = tmp;
+ } else {
+ ModelAction * tmp = node_stack->explore_action(curr);
+ if (tmp) {
+ /* Discard duplicate ModelAction; use action from NodeStack */
+ /* First restore type and order in case of RMW operation */
+ if (curr->is_rmwr())
+ tmp->copy_typeandorder(curr);
+
+ /* If we have diverged, we need to reset the clock vector. */
+ if (diverge == NULL)
+ tmp->create_cv(get_parent_action(tmp->get_tid()));
+
+ delete curr;
+ curr = tmp;
+ } else {
+ /*
+ * Perform one-time actions when pushing new ModelAction onto
+ * NodeStack
+ */
+ curr->create_cv(get_parent_action(curr->get_tid()));
+ /* Build may_read_from set */
+ if (curr->is_read())
+ build_reads_from_past(curr);
+ if (curr->is_write())
+ compute_promises(curr);
+ }
+ }
+
+ /* Assign 'creation' parent */
+ if (curr->get_type() == THREAD_CREATE) {
+ Thread *th = (Thread *)curr->get_location();
+ th->set_creation(curr);
+ }
+
+ /* Deal with new thread */
+ if (curr->get_type() == THREAD_START)
+ check_promises(NULL, curr->get_cv());
+
+ /* Assign reads_from values */
+ Thread *th = get_thread(curr->get_tid());
+ uint64_t value = VALUE_NONE;
+ if (curr->is_read()) {
+ const ModelAction *reads_from = curr->get_node()->get_read_from();
+ if (reads_from != NULL) {
+ value = reads_from->get_value();
+ /* Assign reads_from, perform release/acquire synchronization */
+ curr->read_from(reads_from);
+ r_modification_order(curr,reads_from);
+ } else {
+ /* Read from future value */
+ value = curr->get_node()->get_future_value();
+ curr->read_from(NULL);
+ Promise * valuepromise = new Promise(curr, value);
+ promises->push_back(valuepromise);
+ }
+ } else if (curr->is_write()) {
+ w_modification_order(curr);
+ resolve_promises(curr);
+ }
+
+ th->set_return_value(value);
+
+ /* Add action to list. */
+ if (!already_added)
+ add_action_to_lists(curr);
+
+ /** @todo Is there a better interface for setting the next thread rather
+ than this field/convoluted approach? Perhaps like just returning
+ it or something? */
+
+ /* Do not split atomic actions. */
+ if (curr->is_rmwr())
+ nextThread = thread_current()->get_id();
+ else
+ nextThread = get_next_replay_thread();
+
+ Node *currnode = curr->get_node();
+ Node *parnode = currnode->get_parent();
+
+ if (!parnode->backtrack_empty() || !currnode->read_from_empty() ||
+ !currnode->future_value_empty() || !currnode->promise_empty())
+ if (!next_backtrack || *curr > *next_backtrack)
+ next_backtrack = curr;
+
+ set_backtracking(curr);
+}
+
+/** @returns whether the current partial trace is feasible. */
+bool ModelChecker::isfeasible() {
+ return !cyclegraph->checkForCycles() && !failed_promise;
+}
+
+/** Returns whether the current completed trace is feasible. */
+bool ModelChecker::isfinalfeasible() {
+ return isfeasible() && promises->size() == 0;
+}
+
+/** Close out a RMWR by converting previous RMWR into a RMW or READ. */
+ModelAction * ModelChecker::process_rmw(ModelAction * act) {
+ int tid = id_to_int(act->get_tid());
+ ModelAction *lastread = get_last_action(tid);
+ lastread->process_rmw(act);
+ if (act->is_rmw())
+ cyclegraph->addRMWEdge(lastread, lastread->get_reads_from());
+ return lastread;
+}
+
+/**
+ * Updates the cyclegraph with the constraints imposed from the current read.
+ * @param curr The current action. Must be a read.
+ * @param rf The action that curr reads from. Must be a write.
+ */
+void ModelChecker::r_modification_order(ModelAction * curr, const ModelAction *rf) {
+ std::vector<action_list_t> *thrd_lists = obj_thrd_map->ensureptr(curr->get_location());
+ unsigned int i;
+ ASSERT(curr->is_read());
+
+ /* Iterate over all threads */
+ for (i = 0; i < thrd_lists->size(); i++) {
+ /* Iterate over actions in thread, starting from most recent */
+ action_list_t *list = &(*thrd_lists)[i];
+ action_list_t::reverse_iterator rit;
+ for (rit = list->rbegin(); rit != list->rend(); rit++) {
+ ModelAction *act = *rit;
+
+ /* Include at most one act per-thread that "happens before" curr */
+ if (act->happens_before(curr)) {
+ if (act->is_read()) {
+ const ModelAction * prevreadfrom = act->get_reads_from();
+ if (prevreadfrom != NULL && rf != prevreadfrom)
+ cyclegraph->addEdge(rf, prevreadfrom);
+ } else if (rf != act) {
+ cyclegraph->addEdge(rf, act);
+ }
+ break;
+ }
+ }
+ }
+}
+
+/** Updates the cyclegraph with the constraints imposed from the
+ * current read. */
+void ModelChecker::post_r_modification_order(ModelAction * curr, const ModelAction *rf) {
+ std::vector<action_list_t> *thrd_lists = obj_thrd_map->ensureptr(curr->get_location());
+ unsigned int i;
+ ASSERT(curr->is_read());
+
+ /* Iterate over all threads */
+ for (i = 0; i < thrd_lists->size(); i++) {
+ /* Iterate over actions in thread, starting from most recent */
+ action_list_t *list = &(*thrd_lists)[i];
+ action_list_t::reverse_iterator rit;
+ ModelAction *lastact = NULL;
+
+ /* Find last action that happens after curr */
+ for (rit = list->rbegin(); rit != list->rend(); rit++) {
+ ModelAction *act = *rit;
+ if (curr->happens_before(act)) {
+ lastact = act;
+ } else
+ break;
+ }
+
+ /* Include at most one act per-thread that "happens before" curr */
+ if (lastact != NULL) {
+ if (lastact->is_read()) {
+ const ModelAction * postreadfrom = lastact->get_reads_from();
+ if (postreadfrom != NULL&&rf != postreadfrom)
+ cyclegraph->addEdge(postreadfrom, rf);
+ } else if (rf != lastact) {
+ cyclegraph->addEdge(lastact, rf);
+ }
+ break;
+ }
+ }