From d1e11baca91adc67244597858f1b63abfb1d5507 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 2 Apr 2013 17:48:59 -0700 Subject: [PATCH] model: kill lock_waiters_map This information can be gleaned without the need for a hash-table of lists. --- model.cc | 24 ++++++++++-------------- model.h | 4 ---- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/model.cc b/model.cc index 4a35fcd5..811d81a6 100644 --- a/model.cc +++ b/model.cc @@ -83,7 +83,6 @@ ModelChecker::ModelChecker(struct model_params params) : action_trace(new action_list_t()), thread_map(new HashTable()), obj_map(new HashTable()), - lock_waiters_map(new HashTable()), condvar_waiters_map(new HashTable()), obj_thrd_map(new HashTable *, uintptr_t, 4 >()), promises(new SnapVector()), @@ -109,7 +108,6 @@ ModelChecker::~ModelChecker() delete obj_thrd_map; delete obj_map; - delete lock_waiters_map; delete condvar_waiters_map; delete action_trace; @@ -970,15 +968,16 @@ bool ModelChecker::process_mutex(ModelAction *curr) } case ATOMIC_WAIT: case ATOMIC_UNLOCK: { - //unlock the lock - state->locked = NULL; - //wake up the other threads - action_list_t *waiters = get_safe_ptr_action(lock_waiters_map, mutex); - //activate all the waiting threads - for (action_list_t::iterator rit = waiters->begin(); rit != waiters->end(); rit++) { - scheduler->wake(get_thread(*rit)); + /* wake up the other threads */ + for (unsigned int i = 0; i < get_num_threads(); i++) { + Thread *t = get_thread(int_to_id(i)); + Thread *curr_thrd = get_thread(curr); + if (t->waiting_on() == curr_thrd && t->get_pending()->is_lock()) + scheduler->wake(t); } - waiters->clear(); + + /* unlock the lock - after checking who was waiting on it */ + state->locked = NULL; if (!curr->is_wait()) break; /* The rest is only for ATOMIC_WAIT */ @@ -1460,11 +1459,8 @@ 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->locked) { - //Stick the action in the appropriate waiting queue - get_safe_ptr_action(lock_waiters_map, curr->get_location())->push_back(curr); + if (state->locked) return false; - } } else if (curr->is_thread_join()) { Thread *blocking = (Thread *)curr->get_location(); if (!blocking->is_complete()) { diff --git a/model.h b/model.h index 6809612a..cbd1027c 100644 --- a/model.h +++ b/model.h @@ -226,10 +226,6 @@ private: * to a trace of all actions performed on the object. */ HashTable * const obj_map; - /** Per-object list of actions. Maps an object (i.e., memory location) - * to a trace of all actions performed on the object. */ - HashTable * const lock_waiters_map; - /** Per-object list of actions. Maps an object (i.e., memory location) * to a trace of all actions performed on the object. */ HashTable * const condvar_waiters_map; -- 2.34.1