model: factor out a 'switch_from_master()' function
[model-checker.git] / model.cc
index 906416cd90a1aadf8c13eb6cb48c17882d5002d9..b09a81085062533ccc3a5cfa68e808ef82b2e45f 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->next_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
@@ -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);
                                }
                        }