model: refactor check_current_action, next thread computation
authorBrian Norris <banorris@uci.edu>
Tue, 18 Dec 2012 20:46:48 +0000 (12:46 -0800)
committerBrian Norris <banorris@uci.edu>
Tue, 18 Dec 2012 23:05:19 +0000 (15:05 -0800)
Pulling the 'get_next_thread()' computation out of
check_current_action() so that I can restructure the model-checker
execution a little.

model.cc
model.h

index 1fe7126c66b2f974c6c6d38602aeb521a7d67743..c9bb86824233723fc706ba2ae8b407f14a5c8895 100644 (file)
--- 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 5f62ff835df1d1e9df13dde2e8cd204d2bafd9d2..c97cbf1a05f905fb79087c21b91401548b5ecf2e 100644 (file)
--- 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);