action: refactor, move VALUE_TRY{SUCCESS,FAILED} out of header
[model-checker.git] / action.cc
index 4b380c2dd404fafc1b4be9846433967daa8cd167..08cacd89227f880c1bb391a83f799283c5de4e03 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -1,7 +1,6 @@
 #include <stdio.h>
 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
-#include <vector>
 
 #include "model.h"
 #include "action.h"
 
 #define ACTION_INITIAL_CLOCK 0
 
+/** A special value to represent a successful trylock */
+#define VALUE_TRYSUCCESS 1
+
+/** A special value to represent a failed trylock */
+#define VALUE_TRYFAILED 0
+
 /**
  * @brief Construct a new ModelAction
  *
@@ -78,6 +83,11 @@ bool ModelAction::is_thread_start() const
        return type == THREAD_START;
 }
 
+bool ModelAction::is_thread_join() const
+{
+       return type == THREAD_JOIN;
+}
+
 bool ModelAction::is_relseq_fixup() const
 {
        return type == MODEL_FIXUP_RELSEQ;
@@ -376,11 +386,9 @@ void ModelAction::create_cv(const ModelAction *parent)
                cv = new ClockVector(NULL, this);
 }
 
-void ModelAction::set_try_lock(bool obtainedlock) {
-       if (obtainedlock)
-               value = VALUE_TRYSUCCESS;
-       else
-               value = VALUE_TRYFAILED;
+void ModelAction::set_try_lock(bool obtainedlock)
+{
+       value = obtainedlock ? VALUE_TRYSUCCESS : VALUE_TRYFAILED;
 }
 
 /**
@@ -604,7 +612,7 @@ void ModelAction::print() const
                        if (idx >= 0)
                                model_print("  Rf: P%-2d", idx);
                        else
-                               model_print("  RF: P? ");
+                               model_print("  Rf: P? ");
                } else
                        model_print("  Rf: ?  ");
        }
@@ -626,8 +634,13 @@ unsigned int ModelAction::hash() const
        hash ^= seq_number << 5;
        hash ^= id_to_int(tid) << 6;
 
-       if (is_read() && reads_from)
-               hash ^= reads_from->get_seq_number();
+       if (is_read()) {
+              if (reads_from)
+                      hash ^= reads_from->get_seq_number();
+              else if (reads_from_promise)
+                      hash ^= model->get_promise_number(reads_from_promise);
+              hash ^= get_reads_from_value();
+       }
        return hash;
 }