#include "schedule.h"
#include "snapshot-interface.h"
#include "common.h"
+#include "clockvector.h"
#define INITIAL_THREAD_ID 0
Node *currnode;
ModelAction *curr = this->current_action;
+ ModelAction *tmp;
current_action = NULL;
if (!curr) {
DEBUG("trying to push NULL action...\n");
return;
}
- curr = node_stack->explore_action(curr);
- curr->create_cv(get_parent_action(curr->get_tid()));
+ tmp = node_stack->explore_action(curr);
+ if (tmp) {
+ /* Discard duplicate ModelAction; use action from NodeStack */
+ 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);
+ }
/* Assign 'creation' parent */
if (curr->get_type() == THREAD_CREATE) {
return parent;
}
+/**
+ * Build up an initial set of all past writes that this 'read' action may read
+ * from. This set is determined by the clock vector's "happens before"
+ * relationship.
+ * @param curr is the current ModelAction that we are exploring; it must be a
+ * 'read' operation.
+ */
+void ModelChecker::build_reads_from_past(ModelAction *curr)
+{
+ std::vector<action_list_t> *thrd_lists = &(*obj_thrd_map)[curr->get_location()];
+ unsigned int i;
+
+ ASSERT(curr->is_read());
+
+ for (i = 0; i < thrd_lists->size(); i++) {
+ action_list_t *list = &(*thrd_lists)[i];
+ action_list_t::reverse_iterator rit;
+ for (rit = list->rbegin(); rit != list->rend(); rit++) {
+ ModelAction *act = *rit;
+
+ /* Only consider 'write' actions */
+ if (!act->is_write())
+ continue;
+
+ DEBUG("Adding action to may_read_from:\n");
+ if (DBG_ENABLED()) {
+ act->print();
+ curr->print();
+ }
+ curr->get_node()->add_read_from(act);
+
+ /* Include at most one act that "happens before" curr */
+ if (act->happens_before(curr))
+ break;
+ }
+ }
+}
+
void ModelChecker::print_summary(void)
{
printf("\n");