model: factor out a 'switch_from_master()' function
authorBrian Norris <banorris@uci.edu>
Fri, 15 Feb 2013 23:19:45 +0000 (15:19 -0800)
committerBrian Norris <banorris@uci.edu>
Fri, 15 Feb 2013 23:46:47 +0000 (15:46 -0800)
This snippet of code is important and somewhat subtle. Although we only
use it once, let's make it a function to give it a higher-level
abstraction.

model.cc
model.h

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);
                                }
                        }
 
diff --git a/model.h b/model.h
index a5262d2b5c46e18e697cedf646cb0eb539fed3d6..cc4fe284abed1c197682986f9faa4b375f8b6a88 100644 (file)
--- a/model.h
+++ b/model.h
@@ -117,6 +117,7 @@ public:
        unsigned int get_num_threads() const;
        Thread * get_current_thread() const;
 
+       void switch_from_master(Thread *thread);
        uint64_t switch_to_master(ModelAction *act);
        ClockVector * get_cv(thread_id_t tid) const;
        ModelAction * get_parent_action(thread_id_t tid) const;