From 0c429b461653b8e02e515819d89b7acd241996ca Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 15 Feb 2013 15:19:45 -0800 Subject: [PATCH] model: factor out a 'switch_from_master()' function 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 | 16 ++++++++++++++-- model.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/model.cc b/model.cc index 906416cd..b09a8108 100644 --- 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 a5262d2b..cc4fe284 100644 --- 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; -- 2.34.1