+void ModelChecker::process_mutex(ModelAction *curr) {
+ std::mutex * mutex=(std::mutex *) curr->get_location();
+ struct std::mutex_state * state=mutex->get_state();
+ switch(curr->get_type()) {
+ case ATOMIC_TRYLOCK: {
+ bool success=!state->islocked;
+ curr->set_try_lock(success);
+ if (!success)
+ break;
+ }
+ //otherwise fall into the lock case
+ case ATOMIC_LOCK: {
+ state->islocked=true;
+ ModelAction *unlock=get_last_unlock(curr);
+ //synchronize with the previous unlock statement
+ curr->synchronize_with(unlock);
+ break;
+ }
+ case ATOMIC_UNLOCK: {
+ //unlock the lock
+ state->islocked=false;
+ //wake up the other threads
+ action_list_t * waiters = lock_waiters_map->get_safe_ptr(curr->get_location());
+ //activate all the waiting threads
+ for(action_list_t::iterator rit = waiters->begin(); rit!=waiters->end(); rit++) {
+ add_thread(get_thread((*rit)->get_tid()));
+ }
+ waiters->clear();
+ break;
+ }
+ default:
+ ASSERT(0);
+ }
+}
+
+