X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=action.cc;h=ca1285612b00c75fd7294bee5af80d3aa52a3468;hb=9593acf48b245704a75d0e115d6dec1baf51f07c;hp=c12165b0322a2beb4ff9c25fd33be05f1f7630f2;hpb=1af30302f46d984b38a02a3f21ec53a5a9de0f71;p=model-checker.git diff --git a/action.cc b/action.cc index c12165b..ca12856 100644 --- a/action.cc +++ b/action.cc @@ -7,20 +7,39 @@ #include "action.h" #include "clockvector.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" +#include "nodestack.h" #define ACTION_INITIAL_CLOCK 0 -ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, uint64_t value) : +/** + * @brief Construct a new ModelAction + * + * @param type The type of action + * @param order The memory order of this action. A "don't care" for non-ATOMIC + * actions (e.g., THREAD_* or MODEL_* actions). + * @param loc The location that this action acts upon + * @param value (optional) A value associated with the action (e.g., the value + * read or written). Defaults to a given macro constant, for debugging purposes. + * @param thread (optional) The Thread in which this action occurred. If NULL + * (default), then a Thread is assigned according to the scheduler. + */ +ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, + uint64_t value, Thread *thread) : type(type), order(order), location(loc), value(value), reads_from(NULL), + node(NULL), seq_number(ACTION_INITIAL_CLOCK), - cv(NULL) + cv(NULL), + sleep_flag(false) { - Thread *t = thread_current(); + /* References to NULL atomic variables can end up here */ + ASSERT(loc || type == MODEL_FIXUP_RELSEQ); + + Thread *t = thread ? thread : thread_current(); this->tid = t->get_id(); } @@ -95,6 +114,11 @@ bool ModelAction::is_write() const return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT; } +bool ModelAction::could_be_write() const +{ + return is_write() || is_rmwr(); +} + bool ModelAction::is_rmwr() const { return type == ATOMIC_RMWR; @@ -201,11 +225,11 @@ bool ModelAction::could_synchronize_with(const ModelAction *act) const // Explore interleavings of seqcst writes to guarantee total order // of seq_cst operations that don't commute - if ((is_write() || act->is_write()) && is_seqcst() && act->is_seqcst()) + if ((could_be_write() || act->could_be_write()) && is_seqcst() && act->is_seqcst()) return true; // Explore synchronizing read/write pairs - if (is_read() && is_acquire() && act->is_write() && act->is_release()) + if (is_read() && is_acquire() && act->could_be_write() && act->is_release()) return true; // Otherwise handle by reads_from relation @@ -399,3 +423,18 @@ void ModelAction::print() const } else printf("\n"); } + +/** @brief Print nicely-formatted info about this ModelAction */ +unsigned int ModelAction::hash() const +{ + unsigned int hash=(unsigned int) this->type; + hash^=((unsigned int)this->order)<<3; + hash^=seq_number<<5; + hash^=tid<<6; + + if (is_read()) { + if (reads_from) + hash^=reads_from->get_seq_number(); + } + return hash; +}