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 482af590068c2f1ae9b4b24637a83c8a9b098a92..bd65a78a57647200dcc7e49a64dabcf3ffd41a4a 100644 (file)
@@ -10,7 +10,7 @@
 
 namespace std {
        struct mutex_state {
 
 namespace std {
        struct mutex_state {
-               bool islocked;
+               void *locked; /* Thread holding the lock */
                thread_id_t alloc_tid;
                modelclock_t alloc_clock;
        };
                thread_id_t alloc_tid;
                modelclock_t alloc_clock;
        };
index 7741760025162b786b48c903aaf86937bb4cb0f1..276d18e49a53758b79ef0955325f11f62c0da211 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: {
 
        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);
                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");
        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) {
                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
        }
        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
                //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
        }
        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
                //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 (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;
                        //Stick the action in the appropriate waiting queue
                        get_safe_ptr_action(lock_waiters_map, curr->get_location())->push_back(curr);
                        return false;
index 0bb627d293b03a27d29673b3a95b1b3e136093c2..da3184e55a074823b2909bc653e1c2ba30b6b067 100644 (file)
--- a/mutex.cc
+++ b/mutex.cc
@@ -9,7 +9,7 @@ namespace std {
 
 mutex::mutex()
 {
 
 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);
        thread_id_t tid = thread_current()->get_id();
        state.alloc_tid = tid;
        state.alloc_clock = model->get_cv(tid)->getClock(tid);