From: Brian Norris Date: Tue, 18 Dec 2012 20:46:48 +0000 (-0800) Subject: model: refactor check_current_action, next thread computation X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8d0922f803ba8e3c093f20e5243135ea53b619f0;p=cdsspec-compiler.git model: refactor check_current_action, next thread computation Pulling the 'get_next_thread()' computation out of check_current_action() so that I can restructure the model-checker execution a little. --- diff --git a/model.cc b/model.cc index 1fe7126..c9bb868 100644 --- a/model.cc +++ b/model.cc @@ -1192,11 +1192,10 @@ void ModelChecker::set_current_action(ModelAction *act) { * execution when running permutations of previously-observed executions. * * @param curr The current action to process - * @return The next Thread that must be executed. May be NULL if ModelChecker - * makes no choice (e.g., according to replay execution, combining RMW actions, - * etc.) + * @return The ModelAction that is actually executed; may be different than + * curr; may be NULL, if the current action is not enabled to run */ -Thread * ModelChecker::check_current_action(ModelAction *curr) +ModelAction * ModelChecker::check_current_action(ModelAction *curr) { ASSERT(curr); bool second_part_of_rmw = curr->is_rmwc() || curr->is_rmw(); @@ -1206,7 +1205,7 @@ Thread * ModelChecker::check_current_action(ModelAction *curr) * much later, when a lock/join can succeed */ get_current_thread()->set_pending(curr); scheduler->sleep(get_current_thread()); - return get_next_thread(NULL); + return NULL; } bool newly_explored = initialize_curr_action(&curr); @@ -1292,7 +1291,7 @@ Thread * ModelChecker::check_current_action(ModelAction *curr) check_curr_backtracking(curr); set_backtracking(curr); - return get_next_thread(curr); + return curr; } void ModelChecker::check_curr_backtracking(ModelAction *curr) @@ -2721,12 +2720,7 @@ bool ModelChecker::take_step(ModelAction *curr) Thread *curr_thrd = get_thread(curr); ASSERT(curr_thrd->get_state() == THREAD_READY); - Thread *next_thrd = check_current_action(curr); - - if (curr_thrd->is_blocked() || curr_thrd->is_complete()) - scheduler->remove_thread(curr_thrd); - - next_thrd = scheduler->next_thread(next_thrd); + curr = check_current_action(curr); /* Infeasible -> don't take any more steps */ if (is_infeasible()) @@ -2736,11 +2730,15 @@ bool ModelChecker::take_step(ModelAction *curr) return false; } - if (params.bound != 0) { - if (priv->used_sequence_numbers > params.bound) { + if (params.bound != 0) + if (priv->used_sequence_numbers > params.bound) return false; - } - } + + if (curr_thrd->is_blocked() || curr_thrd->is_complete()) + scheduler->remove_thread(curr_thrd); + + Thread *next_thrd = get_next_thread(curr); + next_thrd = scheduler->next_thread(next_thrd); DEBUG("(%d, %d)\n", curr_thrd ? id_to_int(curr_thrd->get_id()) : -1, next_thrd ? id_to_int(next_thrd->get_id()) : -1); diff --git a/model.h b/model.h index 5f62ff8..c97cbf1 100644 --- a/model.h +++ b/model.h @@ -148,7 +148,7 @@ private: bool next_execution(); void set_current_action(ModelAction *act); - Thread * check_current_action(ModelAction *curr); + ModelAction * check_current_action(ModelAction *curr); bool initialize_curr_action(ModelAction **curr); bool process_read(ModelAction *curr, bool second_part_of_rmw); bool process_write(ModelAction *curr);