mutex: change 'islocked' to hold Thread pointer
authorBrian Norris <banorris@uci.edu>
Sun, 3 Mar 2013 07:37:05 +0000 (23:37 -0800)
committerBrian Norris <banorris@uci.edu>
Sun, 3 Mar 2013 07:37:05 +0000 (23:37 -0800)
We will need to know which Thread is holding the lock, so just stick it
in the mutex state.

include/mutex
model.cc
mutex.cc

index 482af59..bd65a78 100644 (file)
@@ -10,7 +10,7 @@
 
 namespace std {
        struct mutex_state {
-               bool islocked;
+               void *locked; /* Thread holding the lock */
                thread_id_t alloc_tid;
                modelclock_t alloc_clock;
        };
index 7741760..276d18e 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -935,7 +935,7 @@ bool ModelChecker::process_mutex(ModelAction *curr)
 
        switch (curr->get_type()) {
        case ATOMIC_TRYLOCK: {
-               bool success = !state->islocked;
+               bool success = !state->locked;
                curr->set_try_lock(success);
                if (!success) {
                        get_thread(curr)->set_return_value(0);
@@ -947,7 +947,7 @@ bool ModelChecker::process_mutex(ModelAction *curr)
        case ATOMIC_LOCK: {
                if (curr->get_cv()->getClock(state->alloc_tid) <= state->alloc_clock)
                        assert_bug("Lock access before initialization");
-               state->islocked = true;
+               state->locked = get_thread(curr);
                ModelAction *unlock = get_last_unlock(curr);
                //synchronize with the previous unlock statement
                if (unlock != NULL) {
@@ -958,7 +958,7 @@ bool ModelChecker::process_mutex(ModelAction *curr)
        }
        case ATOMIC_UNLOCK: {
                //unlock the lock
-               state->islocked = false;
+               state->locked = NULL;
                //wake up the other threads
                action_list_t *waiters = get_safe_ptr_action(lock_waiters_map, curr->get_location());
                //activate all the waiting threads
@@ -970,7 +970,7 @@ bool ModelChecker::process_mutex(ModelAction *curr)
        }
        case ATOMIC_WAIT: {
                //unlock the lock
-               state->islocked = false;
+               state->locked = NULL;
                //wake up the other threads
                action_list_t *waiters = get_safe_ptr_action(lock_waiters_map, (void *) curr->get_value());
                //activate all the waiting threads
@@ -1402,7 +1402,7 @@ bool ModelChecker::check_action_enabled(ModelAction *curr) {
        if (curr->is_lock()) {
                std::mutex *lock = (std::mutex *)curr->get_location();
                struct std::mutex_state *state = lock->get_state();
-               if (state->islocked) {
+               if (state->locked) {
                        //Stick the action in the appropriate waiting queue
                        get_safe_ptr_action(lock_waiters_map, curr->get_location())->push_back(curr);
                        return false;
index 0bb627d..da3184e 100644 (file)
--- a/mutex.cc
+++ b/mutex.cc
@@ -9,7 +9,7 @@ namespace std {
 
 mutex::mutex()
 {
-       state.islocked = false;
+       state.locked = NULL;
        thread_id_t tid = thread_current()->get_id();
        state.alloc_tid = tid;
        state.alloc_clock = model->get_cv(tid)->getClock(tid);