fix some of the bugs related to barrier example...
[model-checker.git] / action.cc
index 09352da0b0f30f030c5fb423ddd5d60dfdb5dd0c..1a819eaf5584f1e97e88fca439104392c07b7f1b 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -7,7 +7,8 @@
 #include "action.h"
 #include "clockvector.h"
 #include "common.h"
-#include "threads.h"
+#include "threads-model.h"
+#include "nodestack.h"
 
 #define ACTION_INITIAL_CLOCK 0
 
@@ -30,8 +31,10 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc,
        location(loc),
        value(value),
        reads_from(NULL),
+       node(NULL),
        seq_number(ACTION_INITIAL_CLOCK),
-       cv(NULL)
+       cv(NULL),
+       sleep_flag(false)
 {
        Thread *t = thread ? thread : thread_current();
        this->tid = t->get_id();
@@ -108,6 +111,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;
@@ -214,11 +222,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
@@ -412,3 +420,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;
+}