action: add happens_before() function
authorBrian Norris <banorris@uci.edu>
Thu, 21 Jun 2012 08:56:50 +0000 (01:56 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 21 Jun 2012 08:56:50 +0000 (01:56 -0700)
Now I can easily compare two ModelActions with the happens_before()
relationship. Of course, the clock vectors are not fully complete yet, but
this sets the stage...

action.cc
action.h

index 34650c63927e03e471f9f17354fe39e786e46c77..9f95727c8dcb63b27dfffc9782ab376a644d852b 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -133,6 +133,17 @@ void ModelAction::read_from(ModelAction *act)
        value = act->value;
 }
 
+/**
+ * Check whether 'this' happens before act, according to the memory-model's
+ * happens before relation. This is checked via the ClockVector constructs.
+ * @return true if this action's thread has synchronized with act's thread
+ * since the execution of act, false otherwise.
+ */
+bool ModelAction::happens_before(ModelAction *act)
+{
+       return act->cv->synchronized_since(this);
+}
+
 void ModelAction::print(void)
 {
        const char *type_str;
index f554e36cbb0495ce0658595970086891968b48b9..ae4afb29d27f928cbe63a34d79629a6d6310b28b 100644 (file)
--- a/action.h
+++ b/action.h
@@ -58,6 +58,8 @@ public:
        ClockVector * get_cv() const { return cv; }
        void read_from(ModelAction *act);
 
+       bool happens_before(ModelAction *act);
+
        inline bool operator <(const ModelAction& act) const {
                return get_seq_number() < act.get_seq_number();
        }