action: add get_mutex()
authorBrian Norris <banorris@uci.edu>
Sun, 3 Mar 2013 07:24:51 +0000 (23:24 -0800)
committerBrian Norris <banorris@uci.edu>
Sun, 3 Mar 2013 07:26:49 +0000 (23:26 -0800)
action.cc
action.h
model.cc

index 1007e762ee5258305bbd8ef5b403db5a874f17cc..be8c4a6c0cdc69bde75fd08436a33705fa9157af 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -651,3 +651,17 @@ bool ModelAction::may_read_from(const Promise *promise) const
                        return true;
        return false;
 }
+
+/**
+ * Only valid for LOCK, TRY_LOCK, UNLOCK, and WAIT operations.
+ * @return The mutex operated on by this action, if any; otherwise NULL
+ */
+std::mutex * ModelAction::get_mutex() const
+{
+       if (is_trylock() || is_lock() || is_unlock())
+               return (std::mutex *)get_location();
+       else if (is_wait())
+               return (std::mutex *)get_value();
+       else
+               return NULL;
+}
index 1b03bc48943f5b24183c61cd372346a8f8a9b752..a20792033f471ba21744b9de870aa42840490f38 100644 (file)
--- a/action.h
+++ b/action.h
@@ -17,6 +17,10 @@ class ClockVector;
 class Thread;
 class Promise;
 
+namespace std {
+       class mutex;
+}
+
 using std::memory_order;
 using std::memory_order_relaxed;
 using std::memory_order_acquire;
@@ -85,6 +89,7 @@ public:
        uint64_t get_return_value() const;
        const ModelAction * get_reads_from() const { return reads_from; }
        Promise * get_reads_from_promise() const { return reads_from_promise; }
+       std::mutex * get_mutex() const;
 
        Node * get_node() const;
        void set_node(Node *n) { node = n; }
index 86289a0738a7965727fb4620a0021bbb8e2c90d0..7741760025162b786b48c903aaf86937bb4cb0f1 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -927,16 +927,11 @@ bool ModelChecker::process_read(ModelAction *curr)
  */
 bool ModelChecker::process_mutex(ModelAction *curr)
 {
-       std::mutex *mutex = NULL;
+       std::mutex *mutex = curr->get_mutex();
        struct std::mutex_state *state = NULL;
 
-       if (curr->is_trylock() || curr->is_lock() || curr->is_unlock()) {
-               mutex = (std::mutex *)curr->get_location();
+       if (mutex)
                state = mutex->get_state();
-       } else if (curr->is_wait()) {
-               mutex = (std::mutex *)curr->get_value();
-               state = mutex->get_state();
-       }
 
        switch (curr->get_type()) {
        case ATOMIC_TRYLOCK: {