schedule: split Scheduler::next_thread() into separate functions
[model-checker.git] / model.cc
index 906416cd90a1aadf8c13eb6cb48c17882d5002d9..70732868bd3114825f3ccc8c2db51bb57e339a92 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -2667,6 +2667,19 @@ bool ModelChecker::is_enabled(thread_id_t tid) const
        return scheduler->is_enabled(tid);
 }
 
+/**
+ * Switch from a model-checker context to a user-thread context. This is the
+ * complement of ModelChecker::switch_to_master and must be called from the
+ * model-checker context
+ *
+ * @param thread The user-thread to switch to
+ */
+void ModelChecker::switch_from_master(Thread *thread)
+{
+       scheduler->set_current_thread(thread);
+       Thread::swap(&system_context, thread);
+}
+
 /**
  * Switch from a user-context to the "master thread" context (a.k.a. system
  * context). This switch is made with the intention of exploring a particular
@@ -2722,7 +2735,7 @@ Thread * ModelChecker::take_step(ModelAction *curr)
        /* Only ask for the next thread from Scheduler if we haven't chosen one
         * already */
        if (!next_thrd)
-               next_thrd = scheduler->next_thread(next_thrd);
+               next_thrd = scheduler->select_next_thread();
 
        DEBUG("(%d, %d)\n", curr_thrd ? id_to_int(curr_thrd->get_id()) : -1,
                        next_thrd ? id_to_int(next_thrd->get_id()) : -1);
@@ -2755,8 +2768,7 @@ void ModelChecker::run()
                                thread_id_t tid = int_to_id(i);
                                Thread *thr = get_thread(tid);
                                if (!thr->is_model_thread() && !thr->is_complete() && !thr->get_pending()) {
-                                       scheduler->next_thread(thr);
-                                       Thread::swap(&system_context, thr);
+                                       switch_from_master(thr);
                                }
                        }