action: add create_cv() and read_from()
authorBrian Norris <banorris@uci.edu>
Sat, 26 May 2012 02:13:36 +0000 (19:13 -0700)
committerBrian Norris <banorris@uci.edu>
Sat, 26 May 2012 03:39:00 +0000 (20:39 -0700)
These functions provide basic wrapper functionality for creating and updating
the clock vector for a particular ModelAction.

action.cc
action.h

index 1fe4c7fb79d11d627a8adeccc0ae3293eb2ea11c..b0d8fc9b7bed4aaacc843cc8620c0abfffc1dd00 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -3,6 +3,7 @@
 #include "model.h"
 #include "action.h"
 #include "clockvector.h"
+#include "common.h"
 
 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
 {
@@ -81,6 +82,23 @@ bool ModelAction::is_dependent(ModelAction *act)
        return false;
 }
 
+void ModelAction::create_cv(ModelAction *parent)
+{
+       ASSERT(cv == NULL);
+       if (parent)
+               cv = new ClockVector(parent->cv, this);
+       else
+               cv = new ClockVector();
+}
+
+void ModelAction::read_from(ModelAction *act)
+{
+       ASSERT(cv);
+       if (act->is_release() && this->is_acquire())
+               cv->merge(act->cv);
+       value = act->value;
+}
+
 void ModelAction::print(void)
 {
        const char *type_str;
index 98ec8736eb6025341c86c8102e12a0ad037f4e39..62141749d5efafc34dc1bbe3fef6656b344571ec 100644 (file)
--- a/action.h
+++ b/action.h
@@ -2,6 +2,8 @@
 #define __ACTION_H__
 
 #include <list>
+#include <cstddef>
+
 #include "threads.h"
 #include "libatomic.h"
 #include "mymemory.h"
@@ -42,6 +44,9 @@ public:
        bool same_thread(ModelAction *act);
        bool is_dependent(ModelAction *act);
 
+       void create_cv(ModelAction *parent = NULL);
+       void read_from(ModelAction *act);
+
        inline bool operator <(const ModelAction& act) const {
                return get_seq_number() < act.get_seq_number();
        }